rsync: A Backup Strategy for Modern Times - Page 3

By Carla Schroder | Posted Jan 23, 2004
Page 3 of 4   |  Back to Page 1
Print ArticleEmail Article
  • Share on Facebook
  • Share on Twitter
  • Share on LinkedIn

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

Comment and Contribute
(Maximum characters: 1200). You have
characters left.
Get the Latest Scoop with Enterprise Networking Planet Newsletter