Sync one directory to another

Destructive
What do risk levels mean?
Read-only
Inspects state without changing anything.
Low risk
Reversible with a routine follow-up command.
Medium risk
Changes state; undo path documented.
Destructive
Deletes or overwrites; confirmation required.

Mirrors a source directory to a destination with rsync (or robocopy on Windows), copying only what changed — the standard local backup move.

filessyncrsyncbackup

Confirmation required

This recipe is destructive and requires confirmation — confirm you understand the impact before running any command below.

Parameters

Source directory (contents are synced; trailing slash is added by the recipe).

Destination directory to mirror into.

Commands

Dry-run showing exactly what would be copied and deleted

rsync -avn --delete "<source>/" "<destination>/"

Copy changed files and remove destination files absent from the source

rsync -av --delete "<source>/" "<destination>/"

Verification

diff -rq "<source>" "<destination>"

No output — the two directories are identical.

Undo

Not undoable

Files deleted from the destination by --delete/MIR cannot be recovered by this recipe. Run the dry-run step first, every time.

Pitfalls

  • The trailing slash on the rsync source means "sync contents"; omitting it creates a nested copy of the directory inside the destination.
  • The --delete and /MIR flags remove destination files not present in the source — pointing the sync the wrong way destroys the backup.
  • robocopy exit codes 0–7 mean success; only 8+ are errors, which surprises scripts checking for 0.

Related