File Server: Setting Up Rsync Backups

As mentioned previously, I’ve been interested and have started using rsync as my backup utility for backing up important files. I thought I would right an extremely brief post on some of my thoughts for setting this up. For the sake of security, I recommend backing up over SSH with the -e ssh option when backing up to remote servers, but to get this working automatically through cron you’ll also need to set up SSH access without a password for your root user. Once you’ve done that, jump into cron as root with sudo crontab -e and add a new line that’s something like this:

0 2 * * * rsync -az /mnt/sdbmisc/pictures /mnt/sdfbackups/

This simple crontab entry runs at 2AM every morning and backs up the /mnt/sdbmisc/pictures directory to /mnt/backups/ on the same machine, but on a different disk so we’re protected against disk failure. The -a option is for archive mode, which backs up recursively and also backs up the edited/created dates, etc. -z compresses the data to reduce the amount of transfer needed.

For backing up to a remote server, you might want to use a cron entry like this:

0 3 * * * rsync -aze ssh /mnt/sdfbackups/pictures

This uses the aforementioned -e ssh option to send over SSH and backs up our local /mnt/sdfbackups/pictures folder to the /home/adam/homebackups/ directory of the remote machine at at 3AM every morning.

Lastly, in some cases you may want to back up a remote server to your local server, so entries like the following are useful too:

0 4 * * * rsync -aze ssh /mnt/sdfbackups/remoteserver/

At 4AM every morning our server with this crontab entry will SSH into our remote server at and then back up the /home/adam/mongodbdump directory to the local point of /mnt/sdfbackups/remoteserver.

Hopefully this gives you some ideas on how to use rsync and cron to set up your backup schedule. This setting should also send mail to your root linux user whenever it an rsync fails (there’s no output on success).

Good luck and happy rsyncing!