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

Free lesson

Restore tests against RPO and RTO

After this lesson: I can test a restore and measure it against a recovery point objective.

60 min lesson10 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

Every night it said success

A charity's backup software sent a green tick every night for a year. On the day they needed it, the archives would not open.

Nobody had ever tried to restore one. A backup you have not restored is a hope, not a plan.

By the end of this lesson

Note

I can test a restore and measure it against a recovery point objective.

Key words

WordWhat it meansExample
Restore testbringing a backup back to prove it works
RPOthe most recent work you can afford to lose24 hours
RTOhow long you can afford to be down8 hours
Restore chaina full backup and the incrementals after it
Integritydata being exactly as it was saved

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

Two numbers decide what good enough means

The RPO is how much recent work the business can afford to lose. Nightly backups give an RPO of about a day.

The RTO is how long it can afford to be down. Both are set by the business, not by IT. A restore test shows whether the backups really meet them.

Worked example: Kestrel Accounts on a Wednesday

FactValueAgainst the target
Last good backupTuesday 02:00
Files lockedWednesday 14:00
Work lost36 hoursMisses an RPO of 24 hours
Service backThursday 10:00
Time down20 hoursMeets an RTO of 24 hours

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 restore test checks every file

restoretest.py restores archives in order into an empty folder. A restore chain is the full backup, then each incremental after it.

It then checks every file's hash against the manifest taken when the backup ran. That checks integrity, not just that the archive opened. It also times the restore.

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.

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.

Write the restore test, part 1

Command
printf '%s\n' 'import hashlib, os, shutil, subprocess, sys, time' 'manifest, archives = sys.argv[1], sys.argv[2:]' 'start = time.monotonic()' 'shutil.rmtree("restore-test", ignore_errors=True)' 'os.mkdir("restore-test")' 'for archive in archives:' '    done = subprocess.run(["tar", "--listed-incremental=/dev/null", "-xzf", os.path.abspath(archive)], cwd="restore-test", capture_output=True)' '    if not done.returncode == 0:' '        print("FAIL: could not read", archive)' '        sys.exit(1)' '    print("restored", archive)' 'want = dict(line.split()[::-1] for line in open(manifest))' 'got = {}' 'for base, dirs, files in os.walk("restore-test/share"):' '    for name in files:' '        path = os.path.join(base, name)' '        got[os.path.relpath(path, "restore-test/share")] = hashlib.sha256(open(path, "rb").read()).hexdigest()' 'right = [p for p in want if got.get(p) == want[p]]' 'wrong = [p for p in want if p in got and not got[p] == want[p]]' > restoretest.py

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

Write the restore test, part 2

Command
printf '%s\n' 'missing = [p for p in want if p not in got]' 'print("files expected:", len(want), " right:", len(right), " wrong:", len(wrong), " missing:", len(missing))' 'for p in wrong + missing:' '    print("  not as backed up:", p)' 'print("restore took", round(time.monotonic() - start, 1), "seconds")' 'print("PASS" if len(right) == len(want) else "FAIL")' >> restoretest.py

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

Test the whole chain against day 2

Command
python3 restoretest.py backups/share-day2.manifest backups/share-day1-full.tar.gz backups/share-day2-incr.tar.gz

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

Test the full backup alone against day 2

Command
python3 restoretest.py backups/share-day2.manifest backups/share-day1-full.tar.gz

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

A broken archive fails the test

A disk that fills up, or a job stopped half way, leaves an archive cut short. The backup job may still report success.

Make one on purpose: copy the first 400 bytes of day 2's archive. Then test the chain with it.

Make a cut-short copy of day 2's archive

Command
head -c 400 backups/share-day2-incr.tar.gz > backups/share-day2-bad.tar.gz && ls -l backups/share-day2-*.tar.gz

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

Test the chain with the broken archive

Command
python3 restoretest.py backups/share-day2.manifest backups/share-day1-full.tar.gz backups/share-day2-bad.tar.gz; echo "exit status $?"

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

A common mistake

Warning

Many people think a backup job that reports success can be restored. It only says the job finished. Only a restore, checked file by file, proves the archive is whole. Test on a schedule, and after every change to the backups.

Test on a schedule and keep the result

Run a restore test every month, and a full rehearsal at least once a year. Write down the time it took and the files that failed.

Compare the time with the RTO and the backup times with the RPO. A failed test is an alert, like any other.

Try it: how much work is lost?

Code: python
backups = [2, 26, 50]  # hours since Monday 00:00 when each backup finished
incident = 63

last = max(b for b in backups if b <= incident)
print("lost", incident - last, "hours of work")
print("meets a 24 hour RPO" if incident - last <= 24 else "misses a 24 hour RPO")
# Remove 50 from the list, then press Run.

Make a free account to save your work and track your progress.

Assignment: measure a restore against targets

Times are strings written "YYYY-MM-DD HH:MM".

hours_between(start, end) returns the hours from start to end as a float.

last_good(backups, incident) takes a list of (time, ok) pairs and returns the latest time whose backup is ok and is at or before incident, or None.

report(backups, incident, restored, rpo, rto) returns a dictionary: "lost" (hours from the last good backup to the incident), "down" (hours from the incident to restored) and "misses", a list holding "RPO" when lost is over rpo and "RTO" when down is over rto, in that order. With no good backup, lost is None and "RPO" is missed.

Code: python
def hours_between(start, end):
    return 0.0

def last_good(backups, incident):
    return None

def report(backups, incident, restored, rpo, rto):
    return {"lost": 0.0, "down": 0.0, "misses": []}

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.