◇ OpenCyber Academy
Technical · Chapter 17 · English

Chapter 17 — Contained laboratory II

Open, free learning for anyone who wants to protect people and technology. No account is required to read this text or its worked answers.

Chapter 17 — Contained laboratory II

Lesson map

Lesson 17 published. Map, example, EX065.

flowchart TD
  N0["Learning outcomes"]
  N1["17.1 Why test restores"]
  N2["17.2 Verifying integrity"]
  N3["Lab — Backup verification"]
  N4["17.3 Reading the verification"]
  N5["17.4 Timing recovery"]
  N6["Synthesis"]
  N0 --> N1 --> N2 --> N3 --> N4 --> N5 --> N6
  N6 --> EX["Worked example"]
  EX --> Q["Exercise EX065"]

Logical drawing

flowchart LR
  N0["Learning outcomes"]
  N1["17.1 Why test restores"]
  N2["17.2 Verifying integrity"]
  N3["Lab — Backup verification"]
  N4["17.3 Reading the verification"]
  N5["17.4 Timing recovery"]
  N6["Synthesis"]
  N0 --> N1 --> N2 --> N3 --> N4 --> N5 --> N6 --> Q["EX065"]
[Learning outcomes]
    |
    v
[17.1 Why test restores]
    |
    v
[17.2 Verifying integrity]
    |
    v
[Lab — Backup verification]
    |
    v
[17.3 Reading the verification]
    |
    v
[17.4 Timing recovery]
    |
    v
[Synthesis]
    |
    v
[Worked example] --> [Exercise EX065]

Learning outcomes

You will (1) practise backup and restore; (2) verify backup integrity; (3) test a recovery procedure.

17.1 Why test restores

Backups are only useful if they can be restored. Many organisations discover broken or incomplete backups only during an emergency. Amina's second lab tests the whole cycle for network configurations: export, store, verify and restore. She uses the lab firewall and switches, deliberately corrupting a configuration and restoring it from backup while timing each step. The aim is to prove the process works and to find gaps before Castleford ever needs it. The lab results go into the recovery procedure as realistic timings.

17.2 Verifying integrity

A backup file could be incomplete, corrupted or replaced. Amina records a SHA-256 digest of each configuration when it is exported and stores the digests in a manifest. Before restoring, the digest of the backup is compared with the manifest. If they match, the file is unchanged since export. If not, it must not be trusted. Digests are a simple, standard way to detect changes in files, built into Python's hashlib module. The manifest itself is stored separately from the backups, so one failure cannot damage both.

Lab — Backup verification

"""Verify synthetic configuration backups by comparing SHA-256 digests with a manifest (stdlib only)."""
import hashlib
backups = {"fw1.cfg": "hostname fw1\nlogging host 10.8.0.5\n", "sw1.cfg": "hostname sw1\nvlan 10 staff\n",
           "sw2.cfg": "hostname sw2\nvlan 10 staff\nvlan 20 guest\n", "ap-ctl.cfg": "controller ap-ctl\nssid staff\n"}
manifest = {"fw1.cfg": hashlib.sha256(b"hostname fw1\nlogging host 10.8.0.5\n").hexdigest(),
            "sw1.cfg": hashlib.sha256(b"hostname sw1\nvlan 10 staff\n").hexdigest(),
            "sw2.cfg": hashlib.sha256(b"hostname sw2\nvlan 10 staff\n").hexdigest(),
            "core.cfg": "missing-file"}
for name in sorted(set(backups) | set(manifest)):
    if name not in backups: print(f"{name:11}MISSING backup"); continue
    if name not in manifest: print(f"{name:11}NOT IN MANIFEST"); continue
    ok = hashlib.sha256(backups[name].encode()).hexdigest() == manifest[name]
    print(f"{name:11}{'ok' if ok else 'MISMATCH'}")

Run with python3 lab_restore.py. Verified output:

ap-ctl.cfg NOT IN MANIFEST
core.cfg   MISSING backup
fw1.cfg    ok
sw1.cfg    ok
sw2.cfg    MISMATCH

17.3 Reading the verification

Two backups match their manifest digests. The second switch's backup does not match, meaning its content differs from what was recorded: on inspection it is missing its guest VLAN line, perhaps from an interrupted export. The core switch appears in the manifest but has no backup at all, and the access point controller has a backup that is not in the manifest. Each is a gap: Amina fixes the export job to include the core switch, re-exports the second switch and adds the controller to the manifest.

17.4 Timing recovery

Amina restores the lab firewall from verified backup and times it: twenty-five minutes from starting to all tests passing. She records the steps in the recovery procedure and identifies the slowest step, reconnecting management access, which she simplifies. Knowing recovery time helps Castleford decide whether it is acceptable and what spare equipment to keep. Recovery that has been practised is faster and calmer in a real failure. She repeats the test after simplifying the slow step and records the improved time for comparison.

Worked example

Two backups verify, one mismatches, one is missing and one is unlisted; lab firewall recovery takes twenty-five minutes.

Synthetic case. Lab data are synthetic.

Errors and limits

Assuming backups are complete without verifying them leads to failed recoveries.

Exercises

Synthesis

Verified backups and practised restores turn recovery from hope into a tested procedure.

Continue studying — chapter 17 of 18

← Chapter 16 (draft) · Course chapter index · Chapter 18 (draft) →