Overview
This article provides information about how to use the rsync copying tool.
Background
rsync is a fast and versatile file copying/syncing tool used in Linux and macOS operating systems. It is useful for backing up your content to your local computer, pushing your local content to a web server, and quickly syncing files between two computers.
Using rsync to publish your files
When you use rsync to upload your site files (or changes), it determines which files have changed and uploads only the changed files. This ensures that a file is not duplicated when syncing.
In the following examples, the username is your shell user, and server is your DreamHost web server.
Here is the basic syntax:
[server]$ rsync -e "/usr/bin/ssh" -av local_directory username@server.dreamhost.com:remote_directory
To avoid any errors, it is recommended to use the full path for both local and remote directories. Here is a full example:
[server]$ rsync -e "/usr/bin/ssh" -av /home/username/documents/mybackups username@server.dreamhost.com:/home/username/example.com
Fields and filters
You can use various field settings and filters when with rsync.
Fields
Field | Description |
---|---|
rsync | The rsync command. Always start the full command with rsync. |
-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. See the FTP article for instructions on how to locate this name. |
remote_directory | This is the directory on the server to which you wish to upload content. For example, if you want to download all the contents of your /example.com directory, add the full file path on the server: /home/username/example.com/.
If you add a trailing forward slash to the end of the path, it will download only 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. |
Filters
It is also possible to set filters to include and ignore certain files. This makes it possible to have a completely automated one-step configuration once your filters are in place.
Example
This command filters out .pyc files and /.git directories:
[server]$ rsync --filter '- *.pyc' --filter '- /.git' -e "/usr/bin/ssh" -av local_directory username@server.dreamhost.com:remote_directory
See also
DreamHost links