Chapter 16 · Security, Reliability, and Governance

Backups, Restore Testing, and Recovery Objectives

A backup is only a recovery input. Reliability comes from a tested path that restores the right data, reaches an acceptable point in time, verifies integrity, and returns service within a measured objective.

Intermediate155–190 minutesRecovery engineering + restore drillLast reviewed: August 2026

Learning outcomes

Engineer recovery, not merely backup creation

01

Define recovery point objective, recovery time objective, and restore scope.

02

Compare logical dumps, file-level copies, and continuous recovery mechanisms.

03

Create a consistent live SQLite backup through the backup API.

04

Build manifests, integrity checks, and application-level verification into a restore drill.

05

Measure restore performance and close gaps between objectives and observed results.

Translate tolerance into objectives

The recovery point objective limits acceptable data loss:

\[\mathrm{RPO} = t_{failure} - t_{latest\ recoverable\ point}\]

The recovery time objective limits service disruption:

\[\mathrm{RTO} = t_{service\ restored} - t_{incident\ declared}\]
QuestionExample answerDesign implication
How much committed data may be lost?At most 5 minutesBackups alone may be insufficient; continuous log capture may be needed
How quickly must core reads return?Within 30 minutesAutomated restore, infrastructure, credentials, and runbooks must fit the budget
What scope must be recovered?One database and its encryption keysThe backup set must include dependencies and key recovery
What consistency point is required?Orders and payments from the same pointCoordinate dependent systems or design reconciliation

Backup families

SQL

Logical dump

Portable SQL or archive representation. Useful for selective restore and migration, but restore time may be long.

FILE

Physical or file backup

Copies database storage. Fast for whole-system recovery but tied more closely to engine and version.

LOG

Continuous recovery

Combines a base backup with change logs so recovery can reach a later time or named target.

REP

Replica

Improves availability and read scaling, but normally propagates accidental deletes and is not a substitute for independent backups.

SQLite live backup

Copying only the main database file while it is active can miss associated journal state. Use SQLite’s Online Backup API, VACUUM INTO, or an engine-aware snapshot procedure.

python · consistent SQLite backup with manifest
from __future__ import annotationsimport hashlibimport jsonimport sqlite3from datetime import datetime, timezonefrom pathlib import Pathdef sha256(path: Path) -> str:    digest = hashlib.sha256()    with path.open("rb") as stream:        for block in iter(lambda: stream.read(1024 * 1024), b""):            digest.update(block)    return digest.hexdigest()def backup_sqlite(source_path: Path, backup_path: Path) -> Path:    backup_path.parent.mkdir(parents=True, exist_ok=True)    with sqlite3.connect(source_path) as source, sqlite3.connect(backup_path) as target:        source.backup(target, pages=256)    with sqlite3.connect(backup_path) as restored:        integrity = restored.execute("PRAGMA integrity_check").fetchone()[0]        if integrity != "ok":            raise RuntimeError(f"backup integrity failed: {integrity}")        row_count = restored.execute("SELECT COUNT(*) FROM sales_order").fetchone()[0]    manifest = {        "created_at": datetime.now(timezone.utc).isoformat(),        "source": str(source_path),        "backup": str(backup_path),        "sha256": sha256(backup_path),        "sales_order_rows": row_count,        "integrity_check": integrity,    }    manifest_path = backup_path.with_suffix(backup_path.suffix + ".json")    manifest_path.write_text(json.dumps(manifest, indent=2), encoding="utf-8")    return manifest_path

Restore is a separate operation

Select approved backup
Provision isolated target
Restore bytes or SQL
Recover keys + configuration
Integrity checks
Application invariants
Measured cutover decision

A restore drill must avoid overwriting production and must verify business correctness, not merely database startup.

sql · SQLite restore verification
PRAGMA foreign_keys = ON;PRAGMA integrity_check;PRAGMA foreign_key_check;SELECT COUNT(*) AS customer_rows FROM customer;SELECT COUNT(*) AS order_rows FROM sales_order;-- Application invariants.SELECT order_idFROM sales_orderWHERE total_cents < 0;SELECT o.order_idFROM sales_order AS oLEFT JOIN customer AS c ON c.customer_id = o.customer_idWHERE o.customer_id IS NOT NULL  AND c.customer_id IS NULL;

PostgreSQL recovery choices

shell · logical dump and restore
# Custom-format logical backup.pg_dump --format=custom --file=academy.dump academy# Inspect before restore.pg_restore --list academy.dump# Restore into an isolated database.createdb academy_restore_testpg_restore --clean --if-exists --no-owner   --dbname=academy_restore_test academy.dump
text · physical and point-in-time recovery model
Base backup + complete required WAL sequence    -> restore cluster files    -> replay WAL    -> stop at latest available point, timestamp, transaction, or restore point    -> verify database and application invariantsA logical pg_dump is not a physical base backup and cannot replace the WALrequirements of continuous archiving.

Recovery drill evidence

EvidenceWhy it matters
Backup identifier, timestamp, engine version, checksumProves which artifact was used and detects corruption
Key and credential recovery resultEncrypted backups are useless without controlled key recovery
Restore start and service-ready timestampsProvides measured RTO rather than an estimate
Recovered point in time or latest transactionProvides measured RPO
Integrity and business-query resultsDetects structurally valid but operationally incomplete restores
Operator notes and failed stepsImproves automation and runbook quality

Recovery review

  1. Why is a successful backup job not proof of recoverability?
  2. Why is replication not automatically a backup?
  3. Which value is measured by the age of the latest recoverable point?
  4. What should be restored before a production incident occurs?
Review the answers

The artifact may be corrupt, incomplete, inaccessible, too slow to restore, or missing keys and dependencies. Replicas usually copy destructive changes. The age determines RPO. Restore representative backups into isolated environments on a recurring schedule and measure the result.

Summary and references

  • Define RPO, RTO, scope, and consistency requirements before choosing tools.
  • Protect backups independently from the production account and failure domain.
  • Encrypt backup data and test controlled recovery of keys.
  • Restore regularly into an isolated target and verify engine plus business invariants.
  • Record measured RPO/RTO and automate the slowest or most failure-prone steps.

References

Keep knowledge open

Help the academy stay free and grow.

If these tutorials save you time, a small donation supports new lessons, technical review, diagrams, examples, and long-term maintenance.

ETHEthereum / ERC-20 only
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0

Send only assets compatible with the Ethereum/ERC-20 network. Do not send TRC-20/TRON assets.