This article demonstrates how to use rsync.
The rsync program enables you to synchronize directories locally or between two computers. Rsync automatically determines which files are different or new between the two locations, and then synchronizes the directories.
You can use this functionality to accomplish a number of tasks. For example, you can use rsync to back up your web site to another computer. Alternatively, suppose that you have a web site development environment already installed on another server. You could use rsync to deploy this environment to your A2 Hosting account.
The rsync program has many features, but the following command-line options are enough to get started:
Using these rsync options, we can go through some examples. Suppose you want to back up your web site files to another server. To do this, follow these steps:
To back up (or “push”) your public_html directory to the user account on a remote server at example.com, type the following command:
rsync -avz -e ssh public_html [email protected]:~/backup
This command assumes that the remote server is running SSH on port 22. If you were backing up to another A2 Hosting server, for example, you would use the following command because SSH runs on port 7822:
rsync -avz -e "ssh -p7822" public_html [email protected]:~/backup
Another common scenario is “pulling” files from a remote location. For example, you may have a development environment set up on a remote server. You could use rsync to pull files from the remote repository into your A2 Hosting account. With each subsequent “pull”, rsync will only update the files that have changed since the last update, thereby saving time and bandwidth. To do this, run the following command from your home directory:
rsync -avz -e ssh [email protected]:~/public_html .
After rsync finishes, your public_html directory contains a copy of the files in the remote server's public_html directory.
This article is only a brief introduction to rsync's extensive capabilities. To view the official online documentation for the rsync program, please visit http://rsync.samba.org/documentation.html.
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.