Rsync for Linux: sync, copy, and back up files
9 min read - May 24, 2025

How to use rsync on Linux for incremental transfers, remote syncs over SSH, scheduled backups with cron, and avoiding the trailing-slash trap.
Rsync for Linux: how to sync, copy, and back up files like a pro
Rsync is the standard tool for copying files between Linux systems. It's faster than cp or scp for anything you run more than once, recovers from network drops, and only transfers what has actually changed. This post covers what rsync does, the flags worth knowing, the examples you'll reach for most often, and how to schedule it with cron.
What is rsync?
Rsync is a command-line utility for copying and synchronising files between locations. It works locally, over SSH to a remote host, or against an rsync daemon. The key difference from cp or scp: rsync compares source and destination first, then transfers only the differences. On a 100 GB directory where 200 MB has changed, rsync moves 200 MB. cp and scp move the lot.
It ships with every modern Linux distribution. If it's missing: apt install rsync or dnf install rsync.
Why use rsync over cp or scp
Three reasons rsync wins for any non-trivial copy:
- It's incremental. Subsequent runs transfer only the changed bytes, not whole files. For backups and mirrors, that turns an overnight job into a few minutes.
- It survives interruptions. With
--partial, a half-transferred 50 GB file resumes from where it stopped rather than starting over. - It preserves metadata. Archive mode (
-a) keeps permissions, ownership, symlinks, and timestamps. Critical for system files, source trees, and anything where attributes matter.
For one-off copies of small files, scp is fine. For anything that gets repeated, anything bandwidth-heavy, or anything you might need to resume, use rsync.
Common rsync flags
The flags you'll actually reach for:
| Flag | What it does |
|---|---|
-a | Archive mode. Preserves permissions, ownership, symlinks, timestamps. Equivalent to -rlptgoD. |
-v | Verbose. Lists files being transferred. |
-z | Compress in transit. Useful on slow or expensive links, less useful on LAN or for already-compressed content. |
-P | Combines --partial and --progress. Resume interrupted transfers, show live progress. |
--delete | Delete files on the destination that don't exist on the source. Required for a true mirror. |
--exclude | Skip files matching a pattern. |
--exclude-from=FILE | Read exclude patterns from a file. Cleaner than chaining many --exclude flags. |
--dry-run | Show what would happen without transferring anything. |
--bwlimit=KBPS | Cap bandwidth usage in kilobytes per second. Useful for backups that run during business hours. |
--checksum | Compare files by checksum instead of size and modification time. Slower but catches edge cases. |
-e ssh | Use SSH for the transfer. Implicit on most modern installs. |
Default behaviour compares file size and modification time, which is fast and almost always correct. Switch to --checksum if a deployment process rewrites timestamps without changing content, or if you suspect bit-level corruption.
Rsync examples
Copy a directory locally:
rsync -av /source/path/ /destination/path/Sync to a remote server over SSH:
rsync -avz /local/dir/ user@remote:/remote/dir/Dry run before doing anything destructive:
rsync -avz --dry-run /local/dir/ user@remote:/dir/Mirror two directories, including deletions on the destination:
rsync -av --delete /source/ /destination/Exclude logs and a temp directory:
rsync -av --exclude='*.log' --exclude='tmp/' /src/ /dest/Resume a large transfer that might get interrupted:
rsync -avP user@remote:/backups/big.img /local/If the SSH session drops, run the same command again. With -P, rsync picks up where it stopped instead of starting from zero.
Cap bandwidth at 50 MB/s for an off-peak backup so it doesn't saturate the uplink:
rsync -avz --bwlimit=50000 /local/dir/ user@remote:/dir/The trailing slash gotcha
The single most common rsync mistake:
rsync -av /source /destination/ # copies the 'source' directory INTO /destination
rsync -av /source/ /destination/ # copies the CONTENTS of /source into /destinationA trailing slash on the source means "everything inside this directory". No trailing slash means "this directory itself". Run with --dry-run first if you're unsure, especially when combined with --delete.
Automating rsync with cron
For scheduled backups, you need three things:
Passwordless SSH access to the destination. Cron jobs can't type passwords. Generate a key and copy it to the backup host:
ssh-keygen -t ed25519 ssh-copy-id user@backup-hostA script, not a one-liner in crontab. Easier to test, easier to log:
#!/bin/bash LOG=/var/log/rsync-backup.log rsync -az --delete /etc/ user@backup:/backups/$(hostname)/etc/ >> "$LOG" 2>&1Make it executable with
chmod +x.A cron entry to run it. Edit with
crontab -e:0 2 * * * /usr/local/bin/rsync-backup.shThat runs the script every night at 02:00.
Two refinements worth making in production: wrap the script in flock so a long-running job doesn't overlap with the next night's run, and pipe output through logger so failures land in the system journal where monitoring can pick them up.
Final thoughts
Rsync is one of the few Linux tools where the time spent learning the flags pays back almost immediately. The main points:
- Incremental transfers and resume support make rsync the right choice for anything you run more than once
-afor archive mode,-zfor compression,-Pfor resume and progress,--deletefor true mirrors- Watch the trailing slash on the source path, especially with
--delete - Pair it with cron and SSH keys for hands-off scheduled backups
For large backup jobs that move data between facilities, running rsync on a VPS with unmetered bandwidth means backup windows aren't constrained by transfer caps.
Why it's important to have a powerful and unmetered VPS
An unmetered VPS gives flat-rate bandwidth at a fixed port speed. How it differs from metered plans, when it pays off, and what to check before buying.
7 min read - May 9, 2025

Have questions or need a custom solution?
Flexible options
Global reach
Instant deployment
Flexible options
Global reach
Instant deployment