rsync: A Backup Strategy for Modern Times
Dry-Run
$ rsync -avn -e ssh sourcedir username@remotemachine.com:/destinationdir/
The -n switch, or --dry-run, shows what will happen when rsyn is run but without actually copying or changing anything. Use with -v, verbose, to see the messages. Verbose has three levels: -v, -vv, and -vvv for maximum verbosity. Always perform dry runs until you're satisfied rsync will work as desired.
Some other useful command options to be aware of include:
- --delete = Use with caution! Always do a dry-run first when using --delete. Don't say I didn't warn you! --delete removes all files at the destination that do not exist on the source.
- --delete-excluded = Delete any files that are named by --exclude. As you can see, this is powerful stuff to keep archives tidy and uncluttered. Use it wisely.
- -z (or --compress) = Use rsync's compression.
- -S (or --sparse) = Handle sparse files efficiently.
- -H (or --hard-links) = Preserve hard links. -a does not preserve hard links.
- -b (or --backup) = Appends a ~ to existing destination files. You're not stuck with "~", as the --suffix command lets you specify anything you like
- --backup-dir=DIR = Combine with --backup to tell rsync where to store backups.
Excluding Files
rsync can be exclusive as well as inclusive:
--exclude pattern = Exclude files matching pattern.
--exclude-from file = Exclude patterns listed in file.
For example, --exclude *.tmp will exclude all .tmp files. --exclude *.bak excludes .bak files. Name individual files and directories. Each --exclude can take only one argument. For multiple excludes, either string them together on the command line:
--exclude *.bak --exclude *.tmp
Or better, put them in a file:
--exclude-from exclude.file
rsync now supports regular expressions, as all good Linux programs should, for fine-grained file selection. It requires applying a patch; follow this link for details.
Page 4: Running an rsync Server




ATI Enterprises, Inc. prepares students for careers in health care, computer repair, information technology, automotive repair, graphic design, business administration, HVAC, and welding. The company uses the HP BladeSystem and management tools from HP and Microsoft to consolidate its IT infrastructure and simplify day-to-day operations with remote management. More >>