HOWTO: RSync Backups
Seeing as I now have so much more space on my main server, I’ve set up backups of my home dir using RSync, a great, powerful command line too. I’m not going to into too much detail on the options of RSync, and not going to even mention the ones I don’t use, there’s plenty of guides out there, Google it.
My RSync script looks like this;
#! /bin/bash if ping -c 1 -W 2 192.168.1.200 > /dev/null; then rsync -ra --delete /home/dave/ /mnt/An-Lar/Backups/Home/ fi
To explain, what the script does is ping my server to make sure its up, the -c 1 after ping meaning for it to send one packet only, while -W 2 gives it a waitout time of 2 seconds. The output of this is suppressed with > /dev/null.
If this is successful, it then excutes
rsync -ra --delete /home/dave/ /mnt/An-Lar/Backups/Home/
This copies everything in my home directory, to the folder in the NFS mounted share. Those trailing slashes are important, and donate to copy the contents rather than the directory, check out the manpage for more info. -r means as always recursive, -a means archive, which retains permissions and attributes, and –delete tells Rsync to delete files on the server if they no longer exist on the client.
The power of RSync is that it only copies the changes in a file, so if I change a file on the client, RSync copies only the changed file. Makes things very fast🙂
I set up a crontab to excute this script at 6Pm every day, crontab -e looks like this;
# m h dom mon dow command 00 18 * * * /home/dave/.rsyncbackup.sh
Filed under: HowTo, Posts, Server, Ubuntu | 2 Comments
Tags: Backups, HowTo, RSync, Server