# Using rsync

> Use rsync to copy and synchronise folders locally or between two computers, for example to back up your website.

Source: https://helpcenter.ruachost.com/developers/linux/using-rsync/

**Using rsync**\
Learn the basics of the rsync program and how to use it effectively.

This article demonstrates how to work with rsync.

**When to use rsync**\
Rsync allows you to synchronize directories locally or between two computers. It automatically detects which files are new or have changed and updates the destination accordingly.

This can be useful in many scenarios. For example, you can back up your website to another computer. Or, if you have a development environment on another server, you can deploy it to your ruachost.com account.

> **Note:**
When synchronizing directories between two separate computers, both systems must have rsync installed.

**How to use rsync**\
Rsync has many features, but the following command-line options are enough to get started:

- The `-a` option enables archive mode, preserving file permissions, ownership, and modification times.
- The `-e` option specifies the remote shell, often set to `ssh`.
- The `-l` option preserves symbolic links.

**Note**\
Using the `-a` option automatically enables symbolic link preservation.

- The `-r` option allows rsync to recurse through subdirectories.

**Note**\
Using the `-a` option automatically enables recursion.

- The `-v` option enables verbose mode, showing information while rsync runs. You can omit it or use `-vv` for more detailed output.
- The `-z` option enables compression during file transfers.

**Examples**\
Here’s how to use these options:

1. Log in to your account via SSH.
2. Ensure you are in your home directory:

```
cd ~
```

3. To back up (or "push") your `public_html` directory to a remote server at `example.com`, run:

```
rsync -avz -e ssh public_html user@example.com:~/backup
```

**Note**\
This assumes SSH on port 22. To use a different port, include the `-p` option, for example:

```
rsync -avz -e "ssh -p7822" public_html user@example.com:~/backup
```

After completion, the remote server at `example.com` will have a `backup/public_html` directory identical to your local `public_html` directory.

Another common scenario is "pulling" files from a remote server. If you have a development environment on a remote server, you can pull files into your ruachost.com account. Each subsequent pull updates only changed files, saving time and bandwidth:

```
rsync -avz -e ssh user@example.com:~/public_html .
```

After rsync finishes, your local `public_html` directory contains a copy of the remote server's `public_html` files.

**More information**\
This is a brief introduction to rsync. For full documentation, visit [rsync documentation](http://rsync.samba.org/documentation.html).
