rsync syncs files by comparing what’s already there, then transferring only what’s missing or changed, locally or over a network.
You’ve got two folders that should match: a laptop and a server, a photos drive and a backup disk, a build output and a deployment target. Copying everything every time wastes bandwidth and writes extra data to disk. rsync avoids that waste.
Instead of being a blind copier, rsync behaves like an updater. It builds a plan, checks what differs, transfers the smallest practical amount of data, then sets metadata so the destination ends up behaving like the source.
What rsync Is Trying To Do
rsync takes a “source” tree and makes the “destination” tree match. By default it won’t delete extra destination files, and it won’t overwrite a destination file that already matches what rsync believes is the same content.
The match decision comes from a comparison strategy. The default “quick check” uses file size and modified time. You can switch to checksum comparison when you need stricter content checks.
How rsync Works For Backups And Mirroring
Every rsync run is a two-side conversation: a sender that reads source files and a receiver that writes destination files. On a remote copy, rsync starts a partner process on the other machine (often via SSH) and the two sides coordinate the work.
The run breaks into phases: build a file list, compare items, transfer data, then finish by setting times, permissions, owners, and links. Deletions happen only when you ask for them.
Phase 1: Building The File List
rsync walks the source path and records directories, files, and symlinks it might copy. Filter rules like --exclude and --include trim that list. If you use --delete, rsync also scans the destination so it can spot extra files.
A tiny detail matters here: the trailing slash on the source. Compare:
rsync -a src_dir dest_dir
rsync -a src_dir/ dest_dir
The first form creates dest_dir/src_dir. The second form copies the contents of src_dir into dest_dir. Pick the form that matches the tree you want.
Phase 2: Deciding What Needs Copying
With a file list in hand, rsync compares each item against what exists at the destination. The default quick check is lightweight and works well when timestamps are reliable. If size and modified time match, rsync treats the file as already aligned and skips it.
When timestamps can’t be trusted, --checksum makes rsync compute and compare checksums. That reads the full content of each candidate file, so it can be much heavier than the quick check.
Phase 3: Transferring Data With A Delta Strategy
For many files, rsync can do better than “send the whole file.” The classic rsync algorithm uses block signatures so the receiver can describe what blocks it already has, and the sender can transmit only the non-matching blocks plus instructions to rebuild the new file. That rolling checksum plus strong checksum idea is detailed in the rsync technical report.
You won’t always get block-level deltas. Small files often transfer whole because it’s cheaper than calculating signatures. The real win shows up with big files that changed a little, like database dumps, virtual disk images, or log files.
Phase 4: Writing Safely And Preserving Metadata
By default, rsync writes to a temporary file on the destination, then renames it into place when the transfer finishes. If the link drops, you’re less likely to end up with a half-written file pretending to be complete.
Archive mode (-a) is the common starting point. It recurses into directories and preserves a baseline set of metadata such as permissions and timestamps. Extra flags handle ACLs, extended attributes, and hard links when you need them and when the platform permits it.
| rsync Step | What It Checks Or Does | Why It Matters |
|---|---|---|
| Scan Source | Walks paths, applies filters | Keeps the run focused on intended content |
| Build File List | Records names, types, sizes, times | Creates the plan both sides follow |
| Quick Compare | Compares size and mtime by default | Skips work when files already match |
| Checksum Compare | Computes file checksums when requested | Finds same-size files with different bytes |
| Delta Match | Matches blocks using rolling checksums | Moves fewer bytes on partial changes |
| Transfer | Sends new data and rebuild instructions | Makes destination content correct |
| Finalize | Renames temp files, sets metadata | Leaves the destination consistent |
| Optional Delete | Removes extra destination files | Creates a true mirror when desired |
How Does rsync Work? Step-By-Step On The Wire
On a remote sync over SSH, rsync starts an SSH session and launches rsync on the far side. From there, the two rsync processes speak their own protocol over the encrypted channel.
This split is useful: SSH handles encryption and authentication, while rsync handles selection, comparison, and transfer.
What Happens When The Destination Has An Older Version
If the destination already has a similar file, rsync can reuse it as raw material. The receiver computes checksums for blocks in its local file and sends those signatures to the sender. The sender scans the new file, finds matching blocks, and sends only the blocks that don’t match plus a map of where they fit. The receiver rebuilds the new file locally.
If you want the source-of-truth for the algorithm details, read the rsync technical report. It’s short and it answers the “how can it send less than the whole file?” question directly.
Commands That Cover Most Real Uses
These patterns show the moving parts without turning into a wall of flags.
Mirror A Folder To A Backup Drive
rsync -a --delete /home/you/ /mnt/backup/home-you/
The trailing slashes mean “copy contents.” --delete removes destination files that no longer exist at the source, so the backup stays in sync.
Sync To A Remote Host Over SSH
rsync -a -e ssh --delete ./site/ user@host:/var/www/site/
-e ssh selects SSH as the remote shell. You can pass SSH options via the same flag, like a non-default port.
Dry Run Before A Risky Change
rsync -a --delete --dry-run ./data/ /srv/data/
--dry-run prints the planned changes without writing them. Use it when you changed a path, added a new filter, or turned on delete.
| Option | What It Changes | When It’s Handy |
|---|---|---|
-a |
Recursive copy plus common metadata preservation | Backups and mirrors where permissions and times matter |
--delete |
Removes destination files not in the source | Keeping a mirror clean, avoiding stale files |
--dry-run |
Shows actions without changing files | Spotting surprises before they happen |
--checksum |
Compares by checksums instead of size+mtime | When timestamps lie or drift |
--partial |
Keeps partly transferred files on interruption | Unstable links where restarts hurt |
--compress |
Compresses data in transit | Low bandwidth links with spare CPU |
--exclude |
Skips matching paths | Ignoring caches, build outputs, or logs |
--bwlimit=RATE |
Caps transfer rate | Keeping rsync polite on shared connections |
Filters: The Part That Makes Or Breaks A Sync
Filters are how you define what “counts” in the source tree. Done well, they keep backups lean and deployments tidy. Done poorly, they skip a file you needed.
A common pattern is to exclude transient directories and noisy files:
rsync -a --delete \
--exclude ".git/" \
--exclude "node_modules/" \
--exclude "*.log" \
./project/ /mnt/backup/project/
Filter rules apply in order. If you need a file inside an excluded directory, add an include rule for that path earlier in the chain, or restructure the rules so the include is seen first.
Deletion Rules: Safe Habits
--delete is blunt. It makes the destination reflect the source. If the source doesn’t contain it, the destination won’t keep it.
Three habits cut risk. First, do a dry run. Second, confirm you’re targeting the right destination directory and that your trailing slashes match your intent. Third, keep at least one backup that isn’t a mirror, so a mistake doesn’t erase your only copy.
Metadata And Permissions: What Can Surprise You
rsync can preserve metadata only when the receiving side has permission to set it. If you push files to a server as a non-root user, rsync can’t set ownership to another user.
If you care about permissions and times, use archive mode. If you care about ACLs or extended attributes, you may need extra flags and a destination filesystem that can store them.
Daemon Mode And rsync:// URLs
SSH is the common default for remote syncing because it’s encrypted and usually already set up. rsync also has a daemon mode, which is a dedicated rsync service that can expose named modules and accept connections over the rsync protocol.
You’ll see daemon targets written like rsync://host/module/path. This style is common for public mirrors and internal file distribution. If you enable a daemon yourself, treat its config like any other network service: limit what it can read or write, and don’t expose write access unless you really need it.
Transfer Safety Flags That Change The Feel Of rsync
rsync’s default temp-file-then-rename behavior is a good safety net. Two switches are worth knowing when you’re syncing large files on shaky links. --partial keeps a partially transferred file so a later run can continue without starting from zero. --partial-dir can keep those partials in a separate directory so half files don’t clutter the target.
--inplace changes the write strategy by updating files in place. That can be useful when you can’t afford a second full copy on disk, but it also means an interrupted transfer can leave the destination file in a mixed state. Use it only when you accept that trade.
Where To Read The Definitive Behavior
rsync has many flags, and the corner cases live in the docs. The best single reference for how your rsync behaves is the rsync(1) manual page. It documents option semantics, filter rules, temp file behavior, and lots of gotchas.
When something looks off, add -v and re-run as a dry run. The output often tells you why a file was selected or skipped.
If you take one habit from this article, make it the dry run. rsync is predictable when you read its plan, and painful when you don’t.
References & Sources
- rsync Project (Samba).“rsync(1) Manual Page.”Option meanings, transfer behavior, and filter semantics.
- rsync Project (Samba).“The rsync algorithm (technical report).”Explains rolling checksum block matching used for delta transfers.
