rsync is a fast and flexible file copying/syncing application for Linux and OSX. It can be used to back up your content to your local computer as well as push local content to the web server. It also enables you to rapidly synchronize data between two computers so that they remain identical.
In the examples below, username is your Shell user, and example.com is your website.
Using rsync to publish your files
When you use rsync to upload your site’s files (or changes), it can detect which files have changed and only upload those. When syncing, this ensures that a file is not duplicated.
Here’s how an rsync “push out to webhost” command looks in the simplest scenario, without any filters:
rsync -e “/usr/bin/ssh” [server]$ -av local directory [email protected]:remote directory —bwlimit=2000
Always begin the complete command with rsync.
-e – The remote shell program to use is specified. This can always be /usr/bin/ssh. bwlimit – (Optional) Sets the maximum transfer rate in kilobits per second.
-av stands for Archive and Verbose.
local directory – This is the location on your computer where the data to be uploaded is stored. Consider the following scenario: /home/username/documents/mybackups
This is the GreggHost shell login that has been issued to your site.
server – The name of the server to which you’re uploading files. Instructions on how to find your hostname may be found in the Finding Your Hostname article.
remote directory – This is the server directory to which you want to upload material. If you wanted to download the entire contents of your /example.com directory, for example, add the full file path to the server: /home/username/example.com/.
When you add a trailing forward slash at the end of a path, it just downloads the contents of that directory, not the directory name.
If you don’t include the trailing slash, the directory and everything within it will be downloaded.
It is advised that you use the entire path for both local and remote directories to avoid any issues. Here’s a complete example (without the —bwlimit flag):
[email protected]:/home/username/example.com rsync -e “/usr/bin/ssh” -av /home/username/documents/mybackups
Here’s where you may learn more about the flags mentioned above:
It’s also possible to specify which files it should include and which it should exclude using filters. Once your filters are in place, this allows for a completely automatic one-step setting.
The simplest way to add a filter is to use rsync from the command line. To filter out.pyc files and /.git directories, you might perform the following:
—filter ‘- *.pyc’ —filter ‘- /.git’ -e “/usr/bin/ssh” $ rsync —filter ‘- *.pyc’ —filter ‘- /.git’ -e “/usr/bin/ssh” -av local directory [email protected]:remote directory —bwlimit=2000
For more information, go to the following page:
rsync for Windows
rsync is also available for Windows, however the setup requires a few extra steps. The usage of Delta Copy is one option. The ‘raw’ version, which does not have an installer, works perfectly.