Loading...

Lab 69: Remote Synchronization with rsync

Synchronize a project directory to a remote host using rsync and validate changes safely with a dry run. Use push and pull workflows to keep backups current and to restore content when needed.

backup access core

Scenario

You are backing up a local project directory to a remote server. Your job is to push project_files/ to a remote backup location, preview changes before syncing, and then pull updates from the remote backup back into your local directory to simulate a restore workflow.

Operator context

rsync is a default tool for backups and safe deployments because it is incremental and can preview its actions. A dry run helps prevent accidental overwrites and gives you evidence of what will change before you write.

Objective

  • Sync the local directory project_files/ to a remote backup path.
  • Perform a dry run to preview changes before writing data.
  • Sync the remote backup back to the local directory.

Concepts

  • Incremental copy: only changed blocks/files are transferred on subsequent runs.
  • Transport over SSH: remote targets typically use SSH, so authentication and host keys apply.
  • Archive mode (-a): recursive copy plus preservation of key metadata.
  • Dry run (-n): validates intent without touching the destination.
  • Trailing slash behavior: syncing a directory versus syncing its contents depends on the source path.
  • Push versus pull: backups usually push to remote; restores pull from remote.

Walkthrough

Step 1 : Sync project_files/ to the remote backup path.
Command
rsync -avz project_files/ student@remote.server.com:/home/student/backup/

-a enables archive mode, -v prints what is being transferred, and -z compresses data over the network. The trailing slash on project_files/ means “sync the contents of this directory.”

sending incremental file list
./
index.html
config.yaml
sent 2,048 bytes  received 64 bytes  4,224.00 bytes/sec
total size is 1,984  speedup is 0.92
Step 2 : Run a dry run to preview changes without copying data.
Command
rsync -avzn project_files/ student@remote.server.com:/home/student/backup/

The -n option shows what would change without writing. This is where you catch mistakes in source/dest paths before overwriting files on the remote side.

(DRY RUN) sending incremental file list
new_file.txt
(DRY RUN) total size is 512  speedup is 1.00
Step 3 : Sync from remote backup back into the local directory.
Command
rsync -avz student@remote.server.com:/home/student/backup/ project_files/

This “pull” pattern is common during restores or when synchronizing from a canonical remote copy. The trailing slash on project_files/ keeps the restore confined to that directory.

receiving incremental file list
new_file.txt
sent 128 bytes  received 2,048 bytes  4,352.00 bytes/sec
total size is 512  speedup is 0.94

Common breakpoints

Destination path is wrong (files land in an unexpected place)

Stop and re-run with -n. Most “rsync disasters” come from an incorrect destination path or missing trailing slash on the source.

SSH prompt or authentication failures

Confirm the correct user and host, then validate SSH access. If a new host key appears unexpectedly, verify it through a trusted channel before accepting.

Permission denied / partial transfer

Permissions on the remote path may block writes, or local files may be unreadable. Fix permissions and re-run; rsync will only transfer what is missing or changed.

Unexpected deletes after enabling deletion

If you ever add deletion behavior, validate with a dry run first. Deletion flags are powerful and should be treated as high-risk changes.

Cleanup checklist

Cleanup is confirming your local directory still contains what you expect and that your remote destination has the right structure. If this was a test run, remove the temporary file you introduced.

Commands
ls -la project_files/
# If you created a test file:
# rm -f project_files/new_file.txt
Success signal

Dry run output matches your intent, sync completes without path surprises, and repeated runs show minimal/no changes.

Reference

  • rsync -a : Archive mode (recursive copy + preserves permissions, timestamps, and other metadata).
    • -a : Equivalent to common preserve flags (recursive + keep key attributes).
  • rsync -v : Verbose output (shows what rsync is transferring).
    • -v : Prints files and summary stats during sync.
  • rsync -z : Compress file data during the transfer.
    • -z : Useful over slower links; may be unnecessary on fast LANs.
  • rsync -n : Dry run (preview what would change without copying).
    • -n : Use before any high-risk sync (new destination, new flags, or uncertain paths).
  • user@host:/path/ : Remote target syntax when using rsync over SSH.
  • source/ : A trailing slash means “sync the contents of the directory,” not the directory itself.