When 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 hosting.com account.If you are synchronizing directories between two separate computers, they both must have rsync installed.
How to use rsync
The rsync program has many features, but the following command-line options are enough to get started:- The -a option enables archive mode. In archive mode, rsync preserves all file permissions, ownership, and modification times.
- The -e option specifies the remote shell to use. This is often set to ssh.
-
The -l option preserves any symbolic links.
📘 Note If you use the -a option, this option is enabled automatically.
-
The -r option makes rsync recurse through any subdirectories.
📘 Note If you use the -a option, this option is enabled automatically.
- The -v option enables verbose mode, which means rsync displays information while it is running. (By default, rsync does not display any information.) You can omit this option, or to see even more detailed information, use the -vv option.
- The -z option enables compression for file transfers.
- Log in to your account using SSH.
-
To make sure you are in your home directory, type the following command:
-
To back up (or “push”) your public_html directory to the user account on a remote server at example.com, type the following command:
📘 Note This command assumes that the remote server is running SSH on port 22. To use a different SSH port, use the -p option. For example:
- After rsync finishes, the user on the remote server at example.com has a backup/public_html directory in their account that is an exact copy of the public_html directory in your account.