$ run as a normal user# run as root (or with sudo)
The quick answer
Step by step
- The trailing slash decides what is copied:
| Command | Result |
|---|---|
rsync -a /srv/data/ /mnt/b/data/ | The contents of data → /mnt/b/data/. |
rsync -a /srv/data /mnt/b/ | The folder itself → /mnt/b/data/. |
rsync -a /srv/data /mnt/b/data/ | You get /mnt/b/data/data/ — a common mistake. |
- The important options:
| Option | Means |
|---|---|
-a | Archive: folders, links, times, modes, owners (as root). |
-H -A -X | Hard links, ACLs, extended attributes (SELinux labels) — for system data. |
--delete | Remove files in the target that are gone in the source (a true mirror). |
-n / -i | Dry run / itemize the changes. |
--exclude-from=FILE | Skip patterns listed in a file. |
--bwlimit=20M | Limit the speed (do not fill the line in work hours). |
-c | Compare by checksum, not by time and size (slower, exact). |
- Read the change list (
-i):>f+++++++++ new.txt= new file,>f.st...... app.log= changed size/time,*deleting old.txt= will be deleted. If you see many*deletinglines you did not expect — stop, check the paths. - Migrate to a new server with short downtime: sync many times while the app runs (each run is faster), then stop the app, run one last sync, start on the new server:
rsync -aHAX --numeric-ids --delete /srv/data/ new1:/srv/data/
systemctl stop shop
rsync -aHAX --numeric-ids --delete /srv/data/ new1:/srv/data/- Daily snapshots that share unchanged files (
--link-dest) — every day looks like a full copy, but unchanged files are hard links and use no extra space:
rsync -a --delete --link-dest=/backup/data/2026-11-18 /srv/data/ /backup/data/2026-11-19/
du -sh /backup/data/*- Exclude what you do not need:
*.tmp
cache/
node_modules/
.git/rsync -a --delete --exclude-from=/etc/rsync-excludes.txt ./site/ web1:/var/www/site/Check that it worked
Common problems
| Problem | Cause | Fix |
|---|---|---|
--delete removed the wrong files | Wrong target path or slash. | Always -n -i first; keep backups/snapshots of the target. |
You got data/data/ | No trailing slash on the source. | SRC/ with a slash for the contents. |
| Owners became your user | Not run as root, or --numeric-ids missing between servers. | Run as root on both sides; --numeric-ids. |
| SELinux labels lost | No -X. | -aHAX, or restorecon -R after. |
| Every run copies everything | Times differ (FAT/NTFS targets, clock). | --modify-window=2, or -c. |
rsync: connection unexpectedly closed | rsync missing on the remote, or SSH problems. | Install rsync there; test ssh host. |
Go further
- Command pages: rsync, ssh, du.
- Next how-tos: Copy files between servers, Back up a server with restic, Compare two files or folders.
- Learn it: RH134 — rsync, RH134 — The trailing slash, TLCL — rsync, rsync in daily DevOps.
- Practise: Lab: copy, sync and reboot safely, Lab: a day on call.
1What must you always run before rsync --delete?
A dry run with the change list: rsync -a --delete -n -i SRC/ DST/.
2What does --link-dest give you?
Daily snapshot folders where unchanged files are hard links, so each day costs only the changed data.