Run full, incremental and differential backups and restore a chosen day

short · 50 min · Objective 4.4

Task

Back up a changing folder for four "days" with GNU tar: a full backup on day 0, then both an incremental and a differential chain on days 1 to 3. Restore the state of day 3 from each chain, prove both match the live data, and record which backup files each restore needed -- the question the exam asks about schedules.

Steps

  1. Day 0: create 100 files in /srv/data. Take a full backup with tar --listed-incremental=/srv/backup/full.snar -czf /srv/backup/full.tgz -C /srv data, and keep a copy of full.snar.
  2. Days 1 to 3: each day, add ten files and change five. For the incremental chain, back up with a snapshot file that carries on from the previous day. For the differential chain, first copy the day-0 full.snar fresh, then back up against that copy.
  3. Save ls -l /srv/backup to lab/backup/files.txt and the size of each backup in lab/backup/sizes.csv with header day,type,file,bytes.
  4. Save checksums of the live data after day 3 to lab/backup/live.txt. Restore the incremental chain (full then each incremental, in order, with --listed-incremental=/dev/null) into /tmp/r-inc, and the differential (full then day-3 differential) into /tmp/r-diff. Save checksums of each to lab/backup/r-inc.txt and lab/backup/r-diff.txt.
  5. Record in lab/backup/restore-needs.txt the files each restore needed.

Verify

These checks run in a POSIX shell: Terminal on macOS or Linux, and on Windows Git Bash (it comes with Git for Windows) or WSL. A stock Windows PowerShell or Command Prompt has no awk or grep, so there the first line fails.

awk -F, 'NR>1 && $2=="incremental" {print "inc day "$1": "$4}' lab/backup/sizes.csv
awk -F, 'NR>1 && $2=="differential" {print "diff day "$1": "$4}' lab/backup/sizes.csv
diff <(awk '{print $1}' lab/backup/live.txt | sort) <(awk '{print $1}' lab/backup/r-inc.txt | sort) && echo incremental restore matches
diff <(awk '{print $1}' lab/backup/live.txt | sort) <(awk '{print $1}' lab/backup/r-diff.txt | sort) && echo differential restore matches
grep -c . lab/backup/restore-needs.txt

The incremental backups stay roughly the same size each day while the differentials grow, because each differential carries everything since the full. Both restores match the live data. The incremental restore needed four files -- the full and three incrementals, in order -- and the differential restore needed two.

Notes

GNU tar's snapshot file plays the part of the archive bit here: the incremental chain updates it after each run, like clearing the bit, and the differential chain always starts from the day-0 copy, like leaving it set.

This is an independent study companion for CompTIA Server+ SK0-005 and is not produced by or endorsed by CompTIA.