Skip to content
Skip to this exploration
All explorations

Practical self-hosting · intermediate

15 · A backup is a claim you can test

Define recovery through restored data and usable service behavior.

10 min 5 sectionsv1

What you can take away

  • Design a disposable restore test with integrity checks.
  • Write a restore plan for that fixture into a fresh, isolated destination

Your trail through this idea

Checking saved progress…

A backup job reports success. Could you answer a family member’s question from the restored data tomorrow? File creation and recovery are different outcomes.

Prerequisite: complete the preceding lesson or bring its worksheet.

Mark sections complete when you choose. Reading alone does not mark them.

Understand the system

PostgreSQL’s SQL-dump documentation explains logical backups and restoration considerations. Database backups need appropriate tooling and permissions; application files, roles, and external assets may require separate treatment. Match the procedure to the installed database version. Do not assume copying its live storage directory is equivalent to a supported consistent backup.

Define recovery point objective as tolerated data loss and recovery time objective as tolerated time to useful service. These are promises to test, not properties automatically supplied by a backup product. Encryption helps protect stored copies only if the recovery operator can obtain the key when needed.

Checking saved progress…

Work through the case

Original fixture: a practice catalog contains three records with IDs A, B, and C, plus one attachment referenced by B. A restore with three rows but a missing attachment is incomplete. A restore with the attachment but broken permissions is also not a usable service. Row count is a starting check, not a full test.

Checking saved progress…

Make something useful

Try this

Original exercise

Write a restore plan for that fixture into a fresh, isolated destination. Specify source backup, required key, software version, record-count check, sample-value check, attachment check, and reader login check. If you run it, use a disposable database and synthetic records only. Stop before any command whose destination could be production. Retain the original backup until verification completes.

Runnable recovery lab

Prerequisite: Python 3 with its standard sqlite3 module. Save the following as lesson_restore.py in a new practice folder and run python3 lesson_restore.py. It creates only an automatically cleaned temporary directory, uses synthetic records, and contacts no service. This tests recovery reasoning with SQLite; it is not a PostgreSQL backup procedure. The relevant APIs are documented in Python's sqlite3 reference and temporary-directory reference.

import sqlite3
from contextlib import ExitStack, closing
import tempfile
from pathlib import Path

with tempfile.TemporaryDirectory(prefix="rassy-restore-") as folder, ExitStack() as connections:
    root = Path(folder)
    live = connections.enter_context(closing(sqlite3.connect(root / "practice.db")))
    live.execute("CREATE TABLE catalog (id TEXT PRIMARY KEY, title TEXT)")
    live.executemany("INSERT INTO catalog VALUES (?, ?)",
                     [("A", "Atlas"), ("B", "Ballad"), ("C", "Chronicle")])
    live.commit()
    backup = connections.enter_context(closing(sqlite3.connect(root / "backup.db")))
    live.backup(backup)
    live.execute("DELETE FROM catalog WHERE id = 'B'")
    live.commit()
    restored = connections.enter_context(closing(sqlite3.connect(root / "restored.db")))
    backup.backup(restored)
    actual = restored.execute("SELECT id, title FROM catalog ORDER BY id").fetchall()
    expected = [("A", "Atlas"), ("B", "Ballad"), ("C", "Chronicle")]
    assert actual == expected, (actual, expected)
    assert live.execute("SELECT count(*) FROM catalog").fetchone()[0] == 2
    print("PASS: restored 3 exact records; damaged practice source still has 2")

Expected output is the single PASS line. The restored destination is separate from the damaged practice source. Now move the backup step after the deletion and rerun: the equality assertion should fail because a faithfully restored incomplete backup is still incomplete. Restore the script order afterward. The temporary files are removed on exit; deleting the practice script completes cleanup. Attachments, roles, encryption keys and PostgreSQL consistency remain separate production checks.

Checking saved progress…

Check your reasoning

A quick check · for your own learning

Which restore evidence is stronger?

Choose one answer

A self-study prompt. You can retry; this is not an exam.

Checking saved progress…

Keep the result and follow the sources

The deliverable is a recovery report with elapsed time, failed checks, and next actions. 'Not tested' is an honest status. Only a successful restore supports a recovery claim.

Sources and scope

  • Primary documentation or archival source, reviewed 14 November 2026. Additional direct links appear beside the claims they support.
  • Editorial basis: Ian's historical self-hosting questions and current repository inspection informed the case selection. Historical requests do not establish current deployment. Private chat records, credentials and host details are excluded.
  • Examples and exercises are original educational synthesis. External sources support the stated technical or historical context, not every hypothetical scenario.
Checking saved progress…

These checks are for reflection and practice. Your answers and reflection notes are not sent anywhere.

Back to all explorations