Configure automated Rsync backups

Configure automated Rsync backups


rsync is an open source utility that provides fast incremental file transfer. rsync is freely available under theGNU General Public License and is currently being maintained by Wayne Davison.
Its very easy to setup an automated incremental backup using rsync :) First we need to make sure we have Public key based authentication working to the host we want to backup. I.e you shouldnt be prompted for a password during the login. Theres lots of posts on the net already on how to do this but it basically should be along the lines of the two commands below.


ssh-copy-id '-p 12345'
Then ssh username@host should login without prompting for a password. In the example above I had to add quotes around the argument because sshd isn't running on the default port. Depending on the backup your going to do the user will need to have read permissions for the files your trying to backup.


First off make sure rync is installed so
Ubuntu: apt-get install rsync
Fedora/Centos: yum install rsync
Now I want a pretty much full backup of my system so from the host doing the backup I run
rsync -avzH -e 'ssh -p 12345' username@host:/ /home/m00nie/NAS/BACKUP --delete --exclude=/proc --exclude=/sys --exclude=/net
with -e 'ssh -p 12345'you can specify a non standard port for ssh. /home/m00nie/NAS/BACKUP is the local location to backup the host to.

Now after the above command runs without error you can create a cron job to run the backup as often as you like. For this example I'll run the command every sunday night at 4:30 am. crontab -e  will open crontab for editing then add something similar to the following depending on how often you want the backup done.

30 4 * * 0 "rsync -avzH -e 'ssh -p 12345' username@host:/ /home/m00nie/NAS/BACKUP --delete --exclude=/proc --exclude=/sys --exclude=/net" > /dev/null 2>&1

Save then crontab -l to check its listed. Now once a week an incremental backup of your host will be done.

m00nie :)