Introduction to rsync

Updated by Linode

Contribute on GitHub

View Project | View File | Edit File

Rsync is a command line utility which synchronizes files and folders from one location to another. Some workflows that can be implemented using rsync are updating a production host from a development machine, or using a cron job to call rsync to regularly back up data to a storage location. You can even use rsync to migrate your server to Linode from other providers.

rsync title graphic

Rsync is incremental, so once the initial operation has completed, successive backup operations complete very quickly. Only the differences between the source and the destination files are copied. This property of rsync makes it an ideal solution for automated operations.

How Do You Get rsync?

Linux/Unix: Not all *nix systems include rsync by default, but it can be installed from your distribution’s software repository or compiled from source.

Apple OS X: rsync is included in recent versions of OS X.

Windows: As a standalone tool, rsync is not as popular on Windows. There are multiple GUI programs available which use rsync as a backend, and some are open source. Cygwin and DeltaCopy are two which you’ll find recommended on StackExchange.

Reasons to Consider rsync Over cp or SCP

  • Creates incremental data backups.
  • Copies from source to destination only the data which is different between the two locations.
  • Each file is checksummed on transfer using MD5.
  • rsync’s --del option deletes files located at the destination which are no longer at the source.
  • rsync can resume failed transfers (as long as they were started with rsync).
  • rsync can be run as a daemon.
  • rsync can compress data with the -z option, so no need to pipe to an archiving utility.

Working With rsync

There exists a large number of options to use with rsync, and many people have their favorite set of options to use when calling the tool. Single rsync options can also be aliases of multiple others, so for example, running rsync -a would give the same result as rsync -rlptgoD.

Thus, rsync is a tool you want to be especially careful with when copying commands from forum posts and other sites on the internet without knowing exactly what they do. You will get the most out of rsync if you take the time to research and experiment a little before using it on your data.

To start becoming more familiar with rsync, the two commands you’ll need are:

1
2
man rsync
rsync -help

The basic structure of an rsync command is similar to cp and SCP.

1
rsync -[options] source destination

If you have multiple destinations, they’re appended to the end of the string like is done with the cp command:

1
rsync -[options] source destination1 destination2 destination3

Either the source or the destination, or both, can be local or remote. If you’re synchronizing files over a network, then both the local and remote machines will need rsync installed. Rsync uses SSH when transferring over networks so your data is encrypted, and it works with SSH keys for quick authentication with remote servers.

Remote locations are formatted like SSH or SCP commands. For example, to synchronize a local folder with one on a remote server, you’d use:

1
rsync -[options] /path/to/source_folder username@<remote_host>:/path/to/destination_folder

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

This guide is published under a CC BY-ND 4.0 license.