Learn Understand first, then practice while the concept is still fresh.

M45 - Scripting Lab: Backup Automation

Use robocopy or rsync to synchronize a practice folder, log the result, and understand why mirror operations need caution.

Scripting

Scripting Lab: Backup Automation

Use robocopy or rsync to synchronize a practice folder, log the result, and understand why mirror operations need caution.

35 min INTERMEDIATE BOTH Curriculum-reviewed
What you should be able to do after this
  • Use robocopy or rsync to synchronize a practice folder, log the result, and understand why mirror operations need caution.

The Goal: A Repeatable Backup Workflow

This lab introduces a simple but important idea:

  • copying a folder once is not the same as maintaining a synchronized backup

Backup tools such as robocopy and rsync exist because repeated copy jobs need better behavior:

  • skip unchanged files
  • preserve structure
  • log what happened

We will keep the learning scenario small. Use practice folders first, not your real system data.


1. Start with Two Practice Folders

Set up a source folder and a destination folder you can safely inspect.

Examples:

  • Windows: C:\Users\You\Documents\backup-source and D:\backup-dest
  • Linux: $HOME/backup-source and $HOME/backup-dest

Add a few small test files to the source so you can clearly see what changes after each sync.


2. Windows with robocopy

Robocopy is Windows’ standard folder synchronization tool. It is useful because it handles repeated copy work more deliberately than basic file-copy commands.

Practice robocopy command

robocopy “$HOME\Documents\backup-source” “D:\backup-dest” /E /LOG+:“$HOME\Documents\backup-audit.log”

This first pattern is intentionally conservative:

  • /E copies subfolders, including empty ones
  • /LOG+ appends results to a log file

Mirror mode exists, but treat it carefully:

Mirror mode requires caution

robocopy “$HOME\Documents\backup-source” “D:\backup-dest” /MIR /LOG+:“$HOME\Documents\backup-audit.log”

The Linux equivalent below uses rsync.

/MIR can delete files from the destination if they no longer exist in the source. That can be exactly what you want, but only once you are certain your source and destination are correct.


3. Linux with rsync

rsync is a standard Linux sync tool for local and remote copies.

The Windows example above shows the same workflow with robocopy.

Practice rsync command

rsync -av “$HOME/backup-source/” “$HOME/backup-dest/” >> “$HOME/backup-audit.log” 2>&1

This is a good first learning pattern:

  • -a preserves useful file metadata
  • -v shows what was copied
  • the output is saved to a log file

Delete synchronization is powerful and should be tested first:

Delete mode requires caution

rsync -av —delete “$HOME/backup-source/” “$HOME/backup-dest/” >> “$HOME/backup-audit.log” 2>&1

On Linux, the trailing slash matters:

  • source folder without trailing slash means copy the folder itself
  • source folder with trailing slash means copy the folder contents

4. Log the Result and Compare the Folders

After each run:

  • inspect the destination folder
  • inspect the log file
  • change one source file
  • run the sync again
  • confirm the tool copied only what actually changed

That feedback loop teaches more than memorizing flags.

Practice Before Mirror

Delete-style sync flags such as /MIR and —delete are not “advanced because they are cool.” They are advanced because they can remove data in the destination. Use them only after you have confirmed the source, destination, and expected behavior on practice folders.


What You Just Learned

  • Backup automation is really about repeated synchronization, not just one-time copying.
  • robocopy and rsync are better tools than basic copy commands for repeated folder sync work.
  • Logs matter because unattended backup jobs need evidence.
  • Mirror and delete flags are useful but must be tested carefully.
  • Practice folders are the right place to learn backup logic before touching real data.

Next, the curriculum shifts back into system administration topics such as logs, services, and startup behavior.