Run full, incremental and differential backups and restore a chosen day
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
- Day 0: create 100 files in
/srv/data. Take a full backup withtar --listed-incremental=/srv/backup/full.snar -czf /srv/backup/full.tgz -C /srv data, and keep a copy offull.snar. - 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.snarfresh, then back up against that copy. - Save
ls -l /srv/backuptolab/backup/files.txtand the size of each backup inlab/backup/sizes.csvwith headerday,type,file,bytes. - 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 tolab/backup/r-inc.txtandlab/backup/r-diff.txt. - Record in
lab/backup/restore-needs.txtthe 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.