rsync reconciles files and directory trees while avoiding unnecessary transfer of unchanged data. Its efficiency does not make every invocation safe: source syntax, trailing slashes, metadata, exclusions, and deletion policy determine the result.
Network Sharing · Lesson 2
rsync
Learn how to preview, run, and verify safe local or SSH-based directory synchronization with rsync.
Reading Source and Destination
Synchronize the contents of source/ into destination/ locally:
$ rsync -a -- source/ destination/
The trailing slash on source/ means “copy this directory's contents.” Without it, rsync -a source destination/ creates or updates destination/source. Always preview the resulting paths when changing slash placement.
What does the trailing slash in rsync -a source/ destination/ signify?
Understanding Archive Mode
Archive mode, -a, is equivalent to a collection of recursive and metadata-preserving options commonly summarized as -rlptgoD. It preserves symlinks, permissions, modification times, groups, owners, and device or special files where permissions and platform support allow.
Archive mode does not include preservation of hard links, ACLs, or extended attributes; those commonly require -H, -A, and -X. It also does not create historical versions by itself.
Which metadata is not included in -a by itself?
Previewing a Transfer
Use a dry run with itemized changes before a consequential sync:
$ rsync -a --dry-run --itemize-changes -- source/ destination/
A dry run predicts actions using the current scan; it cannot guarantee that files will not change before the real command. Save and review the exact command, then run it without --dry-run only after confirming both endpoints.
What does --dry-run --itemize-changes provide?
Synchronizing over SSH
Push to or pull from a remote host using the familiar remote operand:
$ rsync -a -- source/ alice@example.net:/srv/data/
$ rsync -a -- alice@example.net:/srv/data/ destination/
Modern rsync commonly uses SSH for this form, but confirm the configured remote shell, host key, account privileges, and remote rsync availability. Compression with -z can help compressible data on a constrained link but can waste CPU for data already compressed.
Which operand order pulls remote data into a local directory?
Treating Deletion as Destructive
--delete removes destination entries that are absent from the source within the synchronized scope. A reversed endpoint, wrong slash, or bad exclusion can therefore erase valid data. Preview against a test destination, ensure recoverable backups, review mount state, and consider maximum-delete limits before authorization.
After the real run, inspect exit status and logs, compare expected file counts and metadata, and test representative content or restoration. Rsync synchronization alone mirrors unwanted deletion or corruption and is not a complete backup strategy.
What can --delete do during synchronization?
Lesson complete
You finished rsync
You can now preview and verify an rsync operation without hiding its destructive edge cases.
Use trailing slashes to express the intended directory layout.
Add metadata options not covered by archive mode when required.
Review itemized dry-run output before the real sync.
Verify SSH identity and endpoint direction.
Treat deletion and backup retention as explicit policies.
Keep your learning progress
Create a free account to save this lesson and continue learning on any device.
Create a free account