Mautobu

MySQL + Web dir backup over reverse ssh

Feb 21st, 2015
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.33 KB | None | 0 0
  1. #!/bin/bash
  2. # To be used in conjunction with http://pastebin.com/3J7imyKP
  3. # This will be the destination server, pulling backups from the reverse ssh connection established in the above paste.
  4. # For more secure backups, create a user with read only access to the web directory and a mysql user with global select
  5. # Create a key. If you intent to have multiple servers backup to this box, name the key.
  6. #   $ ssh-keygen
  7. #   $ cat /path/to/key.pub | ssh -p 2222 user@localhost "cat >> ~/.ssh/authorizedkeys"
  8. # I haven't tested this thoroughly vith variables :/
  9.  
  10. key=/path/to/key                        # /home/user/.ssh/mysitebackup_rsa
  11. log=/path/to/log/file                       # /home/user/backups/mysite.log
  12. back=/path/to/backup/location                   # /home/user/backups
  13. sitepath=/path/to/site                      # /var/www/html/mysite
  14. sitename=arbitrary name for site being backed up        # MySite
  15. dbname=mysql database name                  # mysite-db
  16. sshuser=ssh user name                       # user
  17. mysqluser=mysql username                    # root
  18. mysqlpass=mysql password                    # therootpassword
  19.  
  20.  
  21. now=$(date +"%m_%d_%Y")
  22. echo "Backup Started for $now" >> $log
  23. ssh -C $sshuser@localhost -p 2222 -i $key mysqldump -u $mysqluser -p$mysqlpass $dbname | gzip > $back/$dbname.$now.sql.gz
  24. ssh -C $sshuser@localhost -p 2222 -i $key -czpf - $sitepath/$site | cat > $back/$site.tar.gz
  25. echo "Backup Completed for $now" >> $log
  26. echo .  >> $log
Advertisement
Add Comment
Please, Sign In to add comment