Rsync over SSH

Posted January 30, 2004 by Al Banks in UNIX software

The combination of rsync and ssh is a very efficient and secure method of moving and backing up data.

In many of our projects, we use rsync over ssh to move data from one machine to another. The most common use is of the backup of data. However, we have used it for synchronizing data across servers and keeping track of log files.

Rsync is the utility that will copy files from one machine to another. In addition, rsync will determine if it needs to copy the entire file or just the changes. This makes rsync very fast on subsequent transfers.

This tutorial was assembled using Cygwin’s rsync package on a Microsoft Windows XP machine. Your syntax may be slightly different on other platforms.

The following command will copy the dirname directory and its contents to the remote machine, in the specified path:

rsync -avz -e ssh dirname [email protected]:/desired/path

Slightly modified, the command will establish an ssh connection to “firsthost”, then launch rsync over SSH to “secondhost”, and finally copydirname to the desired path:

ssh [email protected] rsync -avz -e ssh dirname [email protected]:/desired/path

When combined with SSH public key authentication, it is possible to automate (cron) backups over the SSH secure connection without a password.

NOTE: The rsync parameters are defined as follows:

  • a = archive
  • v = verbose
  • z = compress file data
  • e = specifies remote shell to use

The Conversation

Follow the reactions below and share your own thoughts.