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:
| |
Example:
| |
The trailing
/on the source is important./source/copies the contents of the directory, while/sourcecopies the directory itself into the destination.
Common Options
| Option | Description |
|---|---|
-a | Archive mode. Recursive and preserves permissions, timestamps, symlinks, etc. |
-v | Verbose output |
-h | Human-readable file sizes |
--progress | Show progress for each file |
--info=progress2 | Show overall transfer progress |
--partial | Keep partially transferred files if the copy is interrupted |
--delete | Delete destination files that no longer exist at the source |
--dry-run | Show what would happen without making changes |
--exclude | Exclude specified files or directories |
-H | Preserve hard links |
-A | Preserve ACLs |
-X | Preserve extended attributes |
Recommended General-Purpose Copy
For most large local file migrations:
| |
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:
| |
:::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:
| |
Then remove --dry-run once the output looks correct.
Resume an Interrupted Copy
For large transfers that may be interrupted:
| |
--append-verify attempts to continue partially transferred files and verifies the completed file afterwards.
For most normal copies, simply rerunning:
| |
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:
| |
On subsequent runs, unchanged files are skipped.
Exclude Files or Directories
Exclude a directory:
| |
Exclude multiple items:
| |
Copy to Another Linux Server
rsync can transfer files over SSH.
| |
Example:
| |
The destination only needs:
- SSH access
rsyncinstalled
No separate rsync server service is required.
Copy From Another Linux Server
Reverse the source and destination:
| |
Example:
| |
Use a Non-Standard SSH Port
If SSH is listening on a different port:
| |
Preserve Numeric User and Group IDs
Useful when migrating data between Linux systems where you want to retain the original UID and GID values:
| |
Copy Files Without Preserving Ownership
When copying to storage where ownership should be determined by the destination:
| |
Show What Will Be Copied
Use a dry run:
| |
For additional detail:
| |
Useful Media Migration Command
For moving large Plex, Sonarr, or Radarr libraries between disks or servers:
| |
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:
| |
:::warning
Only use --delete when you deliberately want the destination to be an exact mirror of the source.
:::
rsync vs Robocopy
| Windows Robocopy | Linux rsync |
|---|---|
/E | -a |
/MIR | -a --delete |
/L | --dry-run |
/Z | --partial |
/LOG | Redirect output to a file |
/XD | --exclude |
/XF | --exclude |
| Copy only changed files | Default rsync behaviour |
Save Output to a Log File
Write normal output to a log:
| |
Include errors as well:
| |
Recommended Commands
Standard local migration
| |
Exact mirror
| |
Test a mirror first
| |
Transfer to another server
| |
Resume a large partially transferred file
| |