Mirror a folder with rsync (local backup)
Keep a second folder, USB disk, or mount exactly in step with the original — without re-copying everything.
Run rsync -avh source/ /destination/ to copy only new and changed files; add --delete to also remove files you deleted from the source.
01Command
Command
$ rsync -avh --delete ~/projects/site/ /mnt/backup/site/02What it does
rsync compares source and destination and transfers only the differences, making repeat syncs very fast. The trailing slashes matter: source/ copies the contents of source into the destination, while source (no slash) would create a source folder inside it. -a preserves permissions, timestamps, and symlinks.
03Risk
!Warning: --delete makes the destination an exact mirror: files removed from the source are deleted from the backup too. If you delete the wrong things in the source, the backup deletes them on the next run — do a dry run with -n (--dry-run) first to preview.
04Undo
Undo
$ Manually restore deleted extras from the destination backup (no automatic undo)05Sources
- rsync(1) — a fast, versatile, remote (and local) file-copying toolEvidence: rsync -a archives recursively preserving attributes, -v is verbose, -h gives human-readable sizes; --delete removes destination files missing from the source.
Last verified: 2026-09-18 · Category: Files & Folders