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