Cheat sheets

Cheat sheet: rsync

Copy and synchronize files, locally or via SSH. Only what has changed is transferred.

The basics

Copy a folder (with progress) rsync -avh --progress source/ destination/
Try first: what would happen? rsync -avhn source/ destination/
To another computer via SSH rsync -avh source/ user@host:/path/destination/
Retrieve from another computer rsync -avh user@host:/path/source/ destination/
With a different SSH port rsync -avh -e "ssh -p 2222" source/ user@host:/path/destination/

Options

Compress modified files during transfer rsync -avhz source/ user@host:/path/destination/
Delete what no longer exists in the source (be careful!) rsync -avh --delete source/ destination/
Skip files or folders rsync -avh --exclude='*.tmp' --exclude='node_modules/' source/ destination/
Resume interrupted transfer rsync -avhP source/ destination/
Limit the speed (kB/s) rsync -avh --bwlimit=5000 source/ user@host:/path/
Overall progress overview rsync -avh --info=progress2 source/ destination/
Compare by content instead of time and size rsync -avhc source/ destination/
On the other side with sudo rsync -avh --rsync-path="sudo rsync" source/ user@host:/path/

Permissions and special files

Preserve hard links, ACLs and extended attributes rsync -aHAXvh source/ destination/
A summary at the end rsync -avh --stats source/ destination/

Backups with history

Daily backups that save space (hardlinks) rsync -avh --delete --link-dest=/backups/yesterday /data/ /backups/today/

Good to know

  • The trailing slash after the source folder matters. source/ copies the contents of the folder, source (without slash) copies the folder itself.
  • -a stands for archive: subfolders, permissions, times, owners and links are preserved. -v shows what’s happening, -h makes numbers readable.
  • Only use --delete after a dry run with -n. More about backups: the 3-2-1 rule.

Sources and attribution

This overview has been compiled in our own words. Commands and options change per version: when in doubt, check the official documentation.