Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Backups that follow the 3-2-1 rule

After this lesson: I can check a set of backups against the 3-2-1 rule.

60 min lesson12 commandsIncident response and forensics lab: investigate a compromised server in your browser

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

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

WordWhat it meansExample
Backupa copy kept so data can be restored
Full backupa copy of every file
Incremental backupa copy of what changed since the last backup
3-2-1 rulethree copies, two media, one off site
Mediumthe kind of storage a copy sits onnas
Checksuma hash that shows a file is unchanged

The cells students fill in are left blank in this preview.

Starter

Have a go

Starter

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Three 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

PartWhat it asksWhat Kestrel has today
3Three copies of the dataThe share, backups and offsite folders
2Two different mediaAll three on the server's disk
1One copy off siteNone: offsite is a folder in the office
1One copy offline or lockedNone: every copy can be changed
0Zero errors in restore testsNever tested

The cells students fill in are left blank in this preview.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

A 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

Command
cd ~/rr && ls mkshare.py manifest.py drill.py compare.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Build a fresh share and its manifest

Command
rm -rf share && python3 mkshare.py share && python3 manifest.py share > before.txt

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Make day 1's full backup

Command
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 backups

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Count what the full backup holds

Command
tar -tzf backups/share-day1-full.tar.gz | wc -l

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Make day 2's changes and an incremental backup

Command
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.manifest

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

See what the incremental backup holds

Command
tar -tzf backups/share-day2-incr.tar.gz

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Record and check a checksum of each archive

Command
(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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Write 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

Command
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.csv

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Write the rule checker

Command
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.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Check today's copies

Command
python3 rule.py copies.csv

Shown 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

Command
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.csv

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Check the plan

Command
python3 rule.py plan.csv

Shown 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).

Code: python
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

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.