Skip to content
rsync Guide

rsync Guide

rsync Guide

rsync is one of the best Linux alternatives to Windows Robocopy. It is ideal for copying large directory trees, synchronising folders, migrating media libraries, transferring files between servers, and resuming interrupted copies.

Basic Copy

Copy the contents of one directory to another:

1
rsync -avh --progress /source/ /destination/

Example:

1
rsync -avh --progress "/mnt/media/TV Shows/" "/mnt/newdisk/TVShows/"

The trailing / on the source is important.
/source/ copies the contents of the directory, while /source copies the directory itself into the destination.

Common Options

OptionDescription
-aArchive mode. Recursive and preserves permissions, timestamps, symlinks, etc.
-vVerbose output
-hHuman-readable file sizes
--progressShow progress for each file
--info=progress2Show overall transfer progress
--partialKeep partially transferred files if the copy is interrupted
--deleteDelete destination files that no longer exist at the source
--dry-runShow what would happen without making changes
--excludeExclude specified files or directories
-HPreserve hard links
-APreserve ACLs
-XPreserve extended attributes

Recommended General-Purpose Copy

For most large local file migrations:

1
rsync -aHAX --info=progress2 --partial /source/ /destination/

This preserves:

  • File permissions and ownership
  • Timestamps
  • Symlinks
  • Hard links
  • ACLs
  • Extended attributes
  • Partially copied files

Mirror a Directory

To make the destination match the source:

1
rsync -avh --delete --info=progress2 /source/ /destination/

:::caution --delete removes files from the destination if they do not exist at the source. Use --dry-run first if you are unsure. :::

Test the mirror operation first:

1
rsync -avh --delete --dry-run /source/ /destination/

Then remove --dry-run once the output looks correct.

Resume an Interrupted Copy

For large transfers that may be interrupted:

1
rsync -avh --partial --append-verify --info=progress2 /source/ /destination/

--append-verify attempts to continue partially transferred files and verifies the completed file afterwards.

For most normal copies, simply rerunning:

1
rsync -aHAX --info=progress2 --partial /source/ /destination/

is sufficient because rsync will skip files that are already up to date.

Copy Only New or Changed Files

This is the normal behaviour of rsync:

1
rsync -avh --info=progress2 /source/ /destination/

On subsequent runs, unchanged files are skipped.

Exclude Files or Directories

Exclude a directory:

1
rsync -avh --exclude='cache/' /source/ /destination/

Exclude multiple items:

1
rsync -avh   --exclude='cache/'   --exclude='*.tmp'   --exclude='downloads/'   /source/ /destination/

Copy to Another Linux Server

rsync can transfer files over SSH.

1
rsync -avh --info=progress2 /source/ user@server:/destination/

Example:

1
rsync -avh --info=progress2 /mnt/media/ aleks@10.10.10.20:/mnt/storage/

The destination only needs:

  • SSH access
  • rsync installed

No separate rsync server service is required.

Copy From Another Linux Server

Reverse the source and destination:

1
rsync -avh --info=progress2 user@server:/remote/source/ /local/destination/

Example:

1
rsync -avh --info=progress2 aleks@10.10.10.20:/mnt/storage/ /mnt/backup/

Use a Non-Standard SSH Port

If SSH is listening on a different port:

1
rsync -avh -e "ssh -p 49222" /source/ user@server:/destination/

Preserve Numeric User and Group IDs

Useful when migrating data between Linux systems where you want to retain the original UID and GID values:

1
rsync -aHAX --numeric-ids --info=progress2 /source/ /destination/

Copy Files Without Preserving Ownership

When copying to storage where ownership should be determined by the destination:

1
rsync -avh --no-owner --no-group --info=progress2 /source/ /destination/

Show What Will Be Copied

Use a dry run:

1
rsync -avh --dry-run /source/ /destination/

For additional detail:

1
rsync -avh --dry-run --itemize-changes /source/ /destination/

Useful Media Migration Command

For moving large Plex, Sonarr, or Radarr libraries between disks or servers:

1
rsync -aHAX --partial --info=progress2 /mnt/old-media/ /mnt/new-media/

Verify the transfer, then optionally rerun the same command. The second run should complete quickly if everything has copied successfully.

If you want the destination to exactly match the source:

1
rsync -aHAX --partial --delete --info=progress2 /mnt/old-media/ /mnt/new-media/

:::warning Only use --delete when you deliberately want the destination to be an exact mirror of the source. :::

rsync vs Robocopy

Windows RobocopyLinux rsync
/E-a
/MIR-a --delete
/L--dry-run
/Z--partial
/LOGRedirect output to a file
/XD--exclude
/XF--exclude
Copy only changed filesDefault rsync behaviour

Save Output to a Log File

Write normal output to a log:

1
rsync -aHAX --info=progress2 /source/ /destination/ | tee rsync.log

Include errors as well:

1
rsync -aHAX --info=progress2 /source/ /destination/ 2>&1 | tee rsync.log

Recommended Commands

Standard local migration

1
rsync -aHAX --partial --info=progress2 /source/ /destination/

Exact mirror

1
rsync -aHAX --partial --delete --info=progress2 /source/ /destination/

Test a mirror first

1
rsync -aHAX --partial --delete --dry-run /source/ /destination/

Transfer to another server

1
rsync -aHAX --partial --info=progress2 /source/ user@server:/destination/

Resume a large partially transferred file

1
rsync -avh --partial --append-verify --info=progress2 /source/ /destination/