Three copies, one fire
A firm keeps its files on a server and a backup on a second disk in the same cupboard. A burst pipe floods the cupboard.
Two copies, both gone in one morning. Ransomware works the same way: it reaches every copy it can. This lesson is about where the copies live.
By the end of this lesson
Note
I can check a set of backups against the 3-2-1 rule.
Key words
| Word | What it means | Example |
|---|---|---|
| Backup | a copy kept so data can be restored | |
| Full backup | a copy of every file | |
| Incremental backup | a copy of what changed since the last backup | |
| 3-2-1 rule | three copies, two media, one off site | |
| Medium | the kind of storage a copy sits on | nas |
| Checksum | a hash that shows a file is unchanged |
The cells students fill in are left blank in this preview.
Starter
Have a go
Starter
3 questionsThree copies, two media, one off site
The 3-2-1 rule asks for three copies of your data: the live one and two backups. They sit on two different media, so one fault cannot ruin both.
One copy is off site, so one fire or flood cannot reach it. Against ransomware, many add 1 and 0: one copy offline or locked, and zero errors when it is restored.
Worked example: 3-2-1-1-0 at Kestrel Accounts
| Part | What it asks | What Kestrel has today |
|---|---|---|
| 3 | Three copies of the data | The share, backups and offsite folders |
| 2 | Two different media | All three on the server's disk |
| 1 | One copy off site | None: offsite is a folder in the office |
| 1 | One copy offline or locked | None: every copy can be changed |
| 0 | Zero errors in restore tests | Never tested |
The cells students fill in are left blank in this preview.
Check
Have a go
Check
3 questionsA full backup, then only what changed
A full backup copies every file. It is simple to restore, but slow and large.
An incremental backup copies only what changed since the last one. GNU tar does this with a snapshot file that remembers what it has seen. A checksum of each archive shows later that it has not changed.
Check lesson 1's scripts are here
cd ~/rr && ls mkshare.py manifest.py drill.py compare.pyShown here, not run. Press Start lab to type it into your own lab’s terminal.
Build a fresh share and its manifest
rm -rf share && python3 mkshare.py share && python3 manifest.py share > before.txtShown here, not run. Press Start lab to type it into your own lab’s terminal.
Make day 1's full backup
rm -rf backups && mkdir -p backups && tar --listed-incremental=backups/share.snar -czf backups/share-day1-full.tar.gz share && python3 manifest.py share > backups/share-day1.manifest && ls backupsShown here, not run. Press Start lab to type it into your own lab’s terminal.
Count what the full backup holds
tar -tzf backups/share-day1-full.tar.gz | wc -lShown here, not run. Press Start lab to type it into your own lab’s terminal.
Make day 2's changes and an incremental backup
python3 mkshare.py share 2 && tar --listed-incremental=backups/share.snar -czf backups/share-day2-incr.tar.gz share && python3 manifest.py share > backups/share-day2.manifestShown here, not run. Press Start lab to type it into your own lab’s terminal.
See what the incremental backup holds
tar -tzf backups/share-day2-incr.tar.gzShown here, not run. Press Start lab to type it into your own lab’s terminal.
Record and check a checksum of each archive
(cd backups && sha256sum share-*.tar.gz > SHA256SUMS && sha256sum -c SHA256SUMS)Shown here, not run. Press Start lab to type it into your own lab’s terminal.
Check
Have a go
Check
3 questionsWrite down every copy, then check it
A backup plan is only as good as the list of copies behind it. Write one row a copy: its medium, its site, whether it is offline and whether a restore was tested.
Then check the list against the rule. rule.py treats the first row as the live data.
Write today's list of copies
printf '%s\n' 'name,medium,site,offline,restore_tested' 'share,server disk,office,no,no' 'backups,server disk,office,no,no' 'offsite,server disk,office,no,no' > copies.csvShown here, not run. Press Start lab to type it into your own lab’s terminal.
Write the rule checker
printf '%s\n' 'import csv, sys' 'rows = list(csv.DictReader(open(sys.argv[1])))' 'live, copies = rows[0], rows[1:]' 'media = {r["medium"] for r in rows}' 'away = [r["name"] for r in copies if not r["site"] == live["site"]]' 'locked = [r["name"] for r in copies if r["offline"] == "yes"]' 'tested = [r["name"] for r in copies if r["restore_tested"] == "yes"]' 'checks = [' ' ("3 copies of the data", len(rows) >= 3, len(rows)),' ' ("2 different media", len(media) >= 2, len(media)),' ' ("1 copy off site", len(away) >= 1, len(away)),' ' ("1 copy offline or locked", len(locked) >= 1, len(locked)),' ' ("0 errors: every copy tested", len(tested) == len(copies), len(tested)),' ']' 'for label, ok, n in checks:' ' print("PASS" if ok else "FAIL", label.ljust(28), n)' 'print("Copies that are not the live data:", ", ".join(r["name"] for r in copies))' > rule.pyShown here, not run. Press Start lab to type it into your own lab’s terminal.
Check today's copies
python3 rule.py copies.csvShown here, not run. Press Start lab to type it into your own lab’s terminal.
A common mistake
Warning
Many people think a folder called offsite is off site. A name changes nothing: it is on the same disk, in the same building, under the same account. A copy counts only where a fire, a fault or a stolen password cannot reach it as well.
Write the plan for this module
printf '%s\n' 'name,medium,site,offline,restore_tested' 'share,server disk,office,no,no' 'backups,nas,office,no,yes' 'vault,object storage,cloud,yes,yes' > plan.csvShown here, not run. Press Start lab to type it into your own lab’s terminal.
Check the plan
python3 rule.py plan.csvShown here, not run. Press Start lab to type it into your own lab’s terminal.
Assignment: check copies against 3-2-1-1-0
A copy is a dictionary with "name", "medium", "site", "offline" (True or False) and "tested" (True or False). The first copy in the list is the live data.
media(copies) returns how many different media the copies use.
off_site(copies) returns the sorted names of the copies whose site differs from the live data's.
failures(copies) returns the parts that fail, in this order: "3 copies" (fewer than three), "2 media", "1 off site", "1 offline" (no copy other than the live one is offline) and "0 errors" (a copy other than the live one is not tested).
def media(copies):
return 0
def off_site(copies):
return []
def failures(copies):
return []
Make a free account to save your work and track your progress.
Exit quiz
Have a go