Rsync

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.

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 username@server.dreamhost.com:remote_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 - 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.
  • 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.

To avoid any errors, it is recommended to use the full path for both local and remote directories.

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. RoR example, 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 username@server.dreamhost.com:remote_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