# rsync

> How rsync copies and synchronises files, what the trailing slash changes, and how to test with --dry-run before --delete.

rsync copies files between directories or computers and transfers only what changed, which makes repeated copies and backups fast. It works locally or over SSH and keeps permissions, times and links with the archive option -a.

## Common options

'-a' (archive) keeps permissions, times, owners and symbolic links and copies recursively. '-v' shows each file, '-h' prints sizes readably, '-z' compresses over the network and '--progress' shows progress.

## The trailing slash

'rsync -a src/ dest/' copies the contents of src into dest. 'rsync -a src dest/' copies the directory itself, creating dest/src. Getting this wrong is the most common rsync mistake.

## --delete and --dry-run

'--delete' removes files in the destination that no longer exist in the source, making an exact mirror. '--dry-run' (-n) shows what would happen without changing anything, and should always be used first with --delete.

## How to back up a folder to a server

1. Test first: rsync -avhn --delete ~/Documents/ user@server:/backup/Documents/
2. Read the list of files that would be copied or deleted.
3. Run it for real: rsync -avh --delete ~/Documents/ user@server:/backup/Documents/
4. Repeat the same command later; only changes are transferred.

## Cautions

- With --delete, a wrong source path can empty the destination; always run with -n first.
- A mirror is not a backup history: deleted or damaged files are mirrored too.

## Sources

1. [rsync(1) manual page](https://download.samba.org/pub/rsync/rsync.1)
2. [rsync project page](https://rsync.samba.org/)

Last reviewed: 2026-10-08
URL: https://wiki.raincleaner.eu/linux/rsync
