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 bidirectional workflows to keep backups current and to restore updates back to the source when needed.

backup remote-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 or a mirrored workflow.

Operator context

rsync is a default tool for backups and safe deployments because it is incremental and can preview its actions. In production, dry runs help prevent accidental overwrites and give you audit-friendly evidence of what will change.

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.

What You’ll Practice

  • Using rsync -a for archive-mode sync (preserves metadata and copies recursively).
  • Compressing transfers with -z for remote syncs.
  • Previewing changes with -n (dry run) before applying updates.
  • Understanding source vs destination paths and trailing slash behavior during directory syncs.

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. This is a typical “push backup” pattern for a project directory.

sending incremental file list
project_files/
project_files/index.html
project_files/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 (dry run) shows what would change. This is where you catch mistakes in source/dest paths before overwriting files on the remote side.

(DRY RUN) sending incremental file list
project_files/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. Ensure you target the correct destination directory to avoid mixing contents into the wrong path.

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

Reference

  • rsync -a : Archive mode (recursive copy + preserves permissions, timestamps, and other metadata).
  • -v : Verbose output (shows what rsync is transferring).
  • -z : Compress file data during the transfer (helpful for remote links).
  • -n : Dry run (preview what would change without copying).
  • user@host:/path/ : Remote destination syntax when using rsync over SSH transport.
  • Trailing slash note : Directory sync behavior changes based on whether the source path ends in /. Be explicit and verify with a dry run when it matters.