4pus

The rsync flags I keep forgetting

I have read the rsync man page perhaps thirty times. It has not stuck. This is the subset I actually use, written down so that the thirty-first time is the last.

The trailing slash

The one that has cost me the most time. src/ means "the contents of src"; src means "the directory src itself". So:

rsync -a src/ dst/     # dst/file
rsync -a src  dst/     # dst/src/file

Nothing warns you. You just end up with a nested directory and a confused expression.

The everyday set

rsync -aHAX --info=progress2 --partial src/ dst/

-a is the archive bundle — recursive, preserves times, permissions, symlinks, owner and group. It does not cover hard links (-H), ACLs (-A) or extended attributes (-X), which is exactly the sort of thing you discover after the migration. --info=progress2 gives one overall progress line instead of one per file, and --partial keeps half-transferred files so a resume is not a restart.

Deleting, carefully

--delete removes things on the destination that are gone from the source. Always with -n first:

rsync -aHAX --delete -n src/ dst/ | head -50

And note --delete-after if the destination is tight on space in a way that makes the default ordering awkward.

Bandwidth and interruptions

--bwlimit=5m keeps a large copy from making the connection unusable. For anything long, run it under tmux; rsync resumes fine, but only if the process survives to be resumed.

The one I always look up

-e 'ssh -p 2222' for a non-standard port. Every time. Without fail.