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 > /dev/null; then
rsync -ra --delete /home/dave/ /mnt/An-Lar/Backups/Home/

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/

2 Responses to “HOWTO: RSync Backups”

  1. You might want to look at running rsync in daemon mode on the server, and using the rsync protocol to backup over the network. Granted you’re describing an environment where you’re backing up over a LAN, and b/w may not be a big concern to you, if you start scaling this solution, or deploying it to more workstations, you may find you’re really blasting the LAN with needless traffic. Rsync really shines in it’s ability to transfer deltas rather than copy a file in it’s entirely as the NFS-copy solution does.

    Jim C.

    • 2 evidex

      Thanks for the info, but I don’t see it being two much of a problem 🙂 Even my 100MB/s LAN can cope with two or three computers backing themselves up. I schedule them to be at different times, and so it works out ok. I’ll take a look into what you mentioned alright though 🙂

%d bloggers like this: