rsync is a fast and versatile file copying/syncing tool used in Linux and OSX operating systems. It is useful for backing up your content to your local computer, as well as for pushing your local content up to the web server. It also allows you to quickly sync files from two computers so they remain the same.

In the following examples, username would be your Shell user and your website.

Using rsync to publish your files

When you use rsync to upload your site files (or changes), it is able to determine which files have changed and upload only the changed files. This ensures that a file is not duplicated when syncing.

Basic example

In the simplest case, without any filters, here's what an rsync "push out to webhost" command looks like:

[server]$ rsync -e "/usr/bin/ssh"  --bwlimit=2000 -av local_directory

Explanation of fields

  • rsync - always start the full command with this.
  • -e - Specifies the remote shell program to use. This can always remain as /usr/bin/ssh.
  • bwlimit - (Optional) Allows you to specify a maximum transfer rate in kb/sec.
  • -av - Archive and Verbose mode.
  • local_directory - This is the local directory on your computer where you store the data to be uploaded. For example: /home/username/documents/mybackups
  • username - This is your DreamHost shell username assigned to your site.
  • server - This is the name of the server you're uploading content to. View the Finding your hostname article for instructions on how to locate this name.
  • remote_directory - This is the directory on the server that you wish to upload content to. For example, if you wanted to download all the contents of your / directory, add the full file path on the server: /home/username/

    If you add a trailing forward slash to the end of the path, it will only download the contents of that directory, but not the directory name itself.

    If you do not add the trailing slash, the directory will be downloaded with everything inside of it.

To avoid any errors, it is recommended to use the full path for both local and remote directories. Here is a full example (excluding the --bwlimit flag.:

[server]$ rsync -e "/usr/bin/ssh" -av /home/username/documents/mybackups 

More information on the flags used above can be found here:

Setting filters

It is also possible to set filters for which files it will include and which it will ignore. This makes it possible to have a completely automated one-step configuration once your filters are in place.

Filter example

The easiest way to add a filter is to add them into the command line rsync. You could do the following to filter out .pyc files and /.git directories:

[server]$ rsync --filter '- *.pyc' --filter '- /.git'  -e "/usr/bin/ssh" --bwlimit=2000 -av local_directory

View the following page for further details:

rsync for Windows

rsync is available for Windows as well, but the configuration includes a few more steps. One solution is to use Delta Copy. The 'raw' version with no installer works fine.

One note about rsync for Windows is that you use *nix style paths even if they're on your Windows machine.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?