Home > Support > HOWTO List > Linux > RSync

Working with Linux howtos

Backups with RSync

RSync is a useful tool.  It facilitates directory replication across servers.   It will compare a source directory and a target directory and 'sync' them up.   It is implemented to run quickly and to use minimal bandwidth. 

The syntax goes something like this:


EXCLUDE=" --exclude *.tmp \
--exclude *.temp"

rsync --archive -vv --rsh=ssh $EXCLUDE $USER@$HOST:/etc/ $BACKUPPATH/$HOST/etc

This code will 'pull' a backup from a remote host (source) to the local machine (destination).   It will use SSH (-e ssh) so the remote machine does not have to be running an rsync daemon.  It will be very verbose (-vv).  It will ignore any files ending in tmp or temp.  Swap the last two args to 'push' a backup from the local machine to the remote machine. 

An example: rsync --archive -vv --rsh=ssh datadir yourbackupserver:/home/backups/

'Man' tells us that the '-archive' option is the same as '-rlptgoD' or:

There are many other options available.  e.g. --delete will delete any files on the receiving side that aren't on the sending side.  You'll probably want to tack on a --compress option for compression; and a --sparse option to efficiently handle sparse files and --stats --progress to show you something interesting while a big job runs.  --ignore-existing will leave existing files as is.

Idea: Put the rsync command in your crontab to perform regular backups. 

Idea: Keep multiple 'generations' of your site by using different destination directories (e.g. backups1, backups2).  If space is an issue, cycle through the directories every so many days or months.

Idea: Use 'ssh authorized keys' so backups can be performed via SSH without password prompting.  E.g. see: automated rsync backup howto.

Idea: Back up your PC to your Linux server.  Get an offsite backup of your Windows PC.  Grab the rsync application by doing a http://www.cygwin.com install.  Then 'push' a backup to your Linux VPS.