rsync: A Backup Strategy for Modern Times - Page 2

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

rsync Commands

The following command makes copies on the same machine. The file or directory being copied is named first and the destination directory second:

$ rsync -a sourcedir destinationdir

To copy a directory from the local machine to a remote machine (note that rsync must be present on both machines):

$ rsync -a sourcedir remotehost:destinationdir

To copy a directory from the remote machine to a local machine:

$ rsync -a remotehost:/sourcedir destinationdir

It is best to be explicit and use full filepaths, even when copying from the current directory.


-a, or --archive, is shorthand for -rlptgoD:

  • r = Copy directories recursively. Without this switch, directories will not get copied at all.
  • l = Recreate symlinks.
  • p = Preserve permissions.
  • t = Transfer modification times and update them on the remote system. Must have this for accurate synchronization.
  • g = Set the group of the destination file to be the same as the source file.
  • o = Set the owner of the destination file to be the same as the source file.
  • D = Re-create character and block devices on the remote system (only root can do this).

To transfer over a ssh tunnel, use this command:

$ rsync -a -e ssh sourcedir username@remotemachine.com:/destinationdir/

-e ssh means "replace the native rsh protocol with ssh." If there is some other secure tunnel you want to use, this is where to name it.

Also, mind your trailing slashes, as they make a difference to rsync in the source arguments. A trailing "/" on a source argument means "copy the contents of this directory." Leaving off a trailing slash means "copy the directory and its contents."

Page 3: Dry-Run

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