Advanced
Searching inHow-to guides
How to search
  • Type the task in your own words (find port, open firewall, disk full) or paste an error message in quotes.
  • Choose "Quick answer" to see only the commands, or an area to stay in one field.
  • "two words" finds the exact phrase.
  • Plain words find names, texts and examples.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search
Try:

How-to 89System · Linux

How to sync folders with rsync

Keep a mirror of a folder on another disk, deploy a site folder, move data to a new server with only seconds of downtime, or keep daily snapshot copies that cost almost no space — rsync does all of it, and it copies only what changed. This how-to covers local and remote mirrors, the dry run you must always do before --delete, how to read rsync's change list, and space-saving snapshots with hard links.

  • 5 Lessons
  • 6 Commands

$ run as a normal user# run as root (or with sudo)

89.1

The quick answer

rsync -a --delete -n -i /srv/data/ /mnt/backup/data/
rsync -a --delete /srv/data/ /mnt/backup/data/
rsync -aHAX --numeric-ids --info=progress2 /srv/data/ backup1:/backup/data/

The first line is the dry run (-n) with the change list (-i): read it, then run the real command.

Commands in this lesson

89.2

Step by step

  1. The trailing slash decides what is copied:
CommandResult
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.
  1. The important options:
OptionMeans
-aArchive: folders, links, times, modes, owners (as root).
-H -A -XHard links, ACLs, extended attributes (SELinux labels) — for system data.
--deleteRemove files in the target that are gone in the source (a true mirror).
-n / -iDry run / itemize the changes.
--exclude-from=FILESkip patterns listed in a file.
--bwlimit=20MLimit the speed (do not fill the line in work hours).
-cCompare by checksum, not by time and size (slower, exact).
  1. 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 *deleting lines you did not expect — stop, check the paths.
  2. 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/
  1. 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/*
  1. Exclude what you do not need:
/etc/rsync-excludes.txt
*.tmp
cache/
node_modules/
.git/
rsync -a --delete --exclude-from=/etc/rsync-excludes.txt ./site/ web1:/var/www/site/

89.3

Check that it worked

A second dry run lists nothing to change:

rsync -a --delete -n -i /srv/data/ /mnt/backup/data/ | wc -l
0

89.4

Common problems

ProblemCauseFix
--delete removed the wrong filesWrong 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 userNot run as root, or --numeric-ids missing between servers.Run as root on both sides; --numeric-ids.
SELinux labels lostNo -X.-aHAX, or restorecon -R after.
Every run copies everythingTimes differ (FAT/NTFS targets, clock).--modify-window=2, or -c.
rsync: connection unexpectedly closedrsync missing on the remote, or SSH problems.Install rsync there; test ssh host.

89.5

Go further

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.

All commands in this chapter