> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Using rsync

> Master rsync with this guide: discover when to use it, how to implement it, and follow step-by-step instructions with code snippets.

This article demonstrates how to use *rsync*.

## 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.

<Note>
  If you are synchronizing directories between two separate computers, they both must have *rsync* installed.
</Note>

## 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.

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:

1. Log in to your account [using SSH](/docs/using-ssh-secure-shell).

2. To make sure you are in your home directory, type the following command:

   ```bash theme={null}
   cd ~
   ```

3. To back up (or "push") your *public\_html* directory to the *user* account on a remote server at *example.com*, type the following command:

   ```bash theme={null}
   rsync -avz -e ssh public_html user@example.com:~/backup
   ```

   > 📘 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:
   >
   > ```bash theme={null}
   > rsync -avz -e "ssh -p7822" public_html user@example.com:~/backup
   > ```

4. 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.

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 hosting.com 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:

```bash theme={null}
rsync -avz -e ssh user@example.com:~/public_html .
```

After *rsync* finishes, your *public\_html* directory contains a copy of the files in the remote server's *public\_html* directory.

## More information

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](https://rsync.samba.org/documentation.html).

## Related articles

* [Using SSH (Secure Shell)](/docs/using-ssh-secure-shell)

* [Using screen](/docs/using-screen)
