Rain WikiWindows · Linux · Android

rsync

Command-line toolAll Linux distributions

rsync copies files between directories or computers and transfers only what changed, which makes repeated copies and backups fast. It works locally or over SSH and keeps permissions, times and links with the archive option -a.

1Common options

-a (archive) keeps permissions, times, owners and symbolic links and copies recursively. -v shows each file, -h prints sizes readably, -z compresses over the network and --progress shows progress.

2The trailing slash

rsync -a src/ dest/ copies the contents of src into dest. rsync -a src dest/ copies the directory itself, creating dest/src. Getting this wrong is the most common rsync mistake.

3--delete and --dry-run

--delete removes files in the destination that no longer exist in the source, making an exact mirror. --dry-run (-n) shows what would happen without changing anything, and should always be used first with --delete.

How to back up a folder to a server

  1. Test first: rsync -avhn --delete ~/Documents/ user@server:/backup/Documents/
  2. Read the list of files that would be copied or deleted.
  3. Run it for real: rsync -avh --delete ~/Documents/ user@server:/backup/Documents/
  4. Repeat the same command later; only changes are transferred.

Cautions

  • With --delete, a wrong source path can empty the destination; always run with -n first.
  • A mirror is not a backup history: deleted or damaged files are mirrored too.

Sources

  1. rsync(1) manual page download.samba.org
  2. rsync project page rsync.samba.org

Last reviewed: