Server Sync Script

Server Sync Script

This script is a work in progress to sync my VPS. Right now the only things I utilize are the cPanel based apache server and the MySQL server. If you run other things,
you will have to add to this. You will need to answer password prompts if you have not set up keys.

server="example.com"
syncDir="/home/bigDrive/example.sync"
saveDir="/home/bigDrive/example.backups"

rsync -a root@$server:/home/ $syncDir/home/
ssh root@thegreatdivide.info -t "mysqldump --all-databases" > $syncDir/mysql.sql
cd $syncDir/
tar -cvzf $saveDir/$(date +%y-%m-%d).tar .

Alternatively, you can prompt for your server and save paths. You will still need to answer password prompts too if you have not set up keys.

read -p "Url (example.com):" server
read -p "Absolute Sync Path ($(pwd)):" syncDir
read -p "Absolute Sync Path ($(pwd)):" saveDir

rsync -a root@$server:/home/ $syncDir/home/
ssh root@thegreatdivide.info -t "mysqldump --all-databases" > $syncDir/mysql.sql
cd $syncDir/
tar -cvzf $saveDir/$(date +%y-%m-%d).tar .

Note that neither of these scripts delete the old backups.