How-to

Rsync in Practice: Twelve Patterns Worth Knowing

Rsync is the copy tool that thinks before it writes. These patterns cover what admins really do with it, on one machine or between two.

What makes rsync different from cp?

It compares before it copies. For every file, rsync checks size and modification time on both sides and skips anything that already matches. When a large file changed only partly and the copy goes over a network, it sends just the changed blocks. A second run of the same command is therefore cheap, which turns rsync into a sync tool, a backup tool and a migration tool at once. cp copies everything, every time.

Every image we install has rsync available from the default repositories. Debian 13 ships rsync 3.4.1, which includes the January 2025 security fixes; Ubuntu 24.04 and the Enterprise Linux images carry patched 3.2 builds. Keep it updated like any network-facing tool.

Which flags should I memorize?

FlagMeaning
-aArchive: recursive, keeps modes, times, links, owner, group, devices
-v / -iVerbose, or itemized list of what changed and why
-nDry run: show what would happen, change nothing
-zCompress over the network
-PSame as --partial --progress
-cCompare by checksum instead of size and time
--deleteRemove target files that no longer exist on the source

Examples 1 to 4: everyday copies

1. Copy a folder on the same machine, for example onto the second NVMe drive that arrives empty with every two-drive model:

rsync -a /var/www/ /mnt/nvme1/www-copy/

2. Watch progress on a big copy with one summary line instead of thousands of file names:

rsync -a --info=progress2 --no-inc-recursive /srv/photos/ /mnt/nvme1/photos/

--no-inc-recursive makes rsync scan the whole tree first, so the percentage is accurate from the start.

3. Copy only some file types while keeping the folder layout:

rsync -a --include='*/' --include='*.pdf' --exclude='*' /srv/docs/ /srv/pdf-only/

4. Copy to another machine by adding a host. SSH is the transport automatically; the details are in Rsync over SSH.

Examples 5 to 8: big or awkward files

5. Resume an interrupted transfer of large files instead of starting over:

rsync -a --partial --append-verify /data/vm-images/ files@198.51.100.12:/tank/vm-images/

6. Skip huge files when you only want configuration and code, not dumps or ISO images:

rsync -a --max-size=200M /home/ /mnt/nvme1/home-light/

7. Verify a copy by content after a disk scare. Checksums read every byte on both sides, so this is slow but thorough:

rsync -ac --dry-run --itemize-changes /srv/archive/ /mnt/nvme1/archive/ | grep -v '^\.'

Empty output means the copy matches the source byte for byte.

8. Keep hard links, ACLs and extended attributes, needed for mail stores, some backup trees and SELinux labels:

rsync -aHAX /var/vmail/ /mnt/nvme1/vmail/

Examples 9 to 12: changes you can undo

9. Preview deletions before mirroring. Never skip this step with --delete:

rsync -an --delete -i /srv/site/ /srv/site-mirror/ | grep deleting

10. Keep the old version of every replaced file in a dated folder, a cheap safety net for deploys:

rsync -a --delete --backup --backup-dir=/srv/site-prev/$(date +%F-%H%M) build/ /srv/site/

11. Move instead of copy, deleting each source file once it is safely transferred:

rsync -a --remove-source-files /srv/incoming/ /srv/processed/
find /srv/incoming -type d -empty -delete

Rsync removes files but leaves empty folders behind, which the find line cleans up.

12. Limit disk impact during business hours by lowering priority on both CPU and I/O:

nice -n 15 ionice -c2 -n7 rsync -a /srv/media/ /mnt/nvme1/media/

When should I not use rsync?

For live databases. Copying the files of a running MySQL or PostgreSQL instance gives you an inconsistent snapshot. Dump the database or use its own backup tool first, then rsync the dump. Rsync is also the wrong tool for millions of tiny files that change constantly; a file system snapshot with ZFS or LVM, followed by a copy of the snapshot, is faster and consistent. The backup side of this is covered in Back up data with rsync, and filtering in Exclude files in rsync.

Keep Reading

Back up data with rsync

Build dated, space-saving snapshot backups with rsync and hard links, pull them from a second machine and test restores.

Open

Exclude files in rsync

Skip caches, logs and build folders with --exclude, --exclude-from and filter rules, and learn how anchored patterns really match.

Open

Rsync over SSH

Copy and mirror folders between machines with rsync over SSH: trailing slashes, dry runs, custom ports, sudo on the far side and bandwidth caps.

Open

Two-drive mirror (RAID 1)

How RAID 1 keeps a full copy of your data on two drives, which machines have two drives and how to check it with mdadm.

Open

FAQ

Quick Answers

Archive mode copies folders recursively and keeps permissions, timestamps, symlinks, owner, group and device files.

Run the same command again with --partial, or with --partial --append-verify for very large files.

Run rsync with -c, --dry-run and --itemize-changes; if nothing is listed, the contents match.

Yes, with --remove-source-files. It leaves empty folders behind, which find can delete afterwards.

It is in the default repositories of every image we offer; install it with apt, dnf or pkg if a minimal system lacks it.