15.1. Designing a Recoverable Backup System

Backup design answers four questions before any command is run: how much loss is acceptable, how fast recovery must be, what exactly has to be recoverable, and which failures each copy must survive. The answers decide the retention policy, the copy count, where copies live, and who is allowed to delete them. Every later section implements part of that design; this one states it.

15.1.1. Recovery Objectives, Retention, and Failure Domains

Objective The question it answers What it decides
Recovery point objective (RPO) How much data may be lost when a failure happens? Backup frequency: hourly backups give an hour of exposure, weekly backups a week
Recovery time objective (RTO) How long may the service stay down? Restore method, staging hardware, and whether restores have been rehearsed
Retention window How far back must a recovery reach? Prune policy and repository capacity; also how far back accidental changes remain reversible
Failure domain coverage Which failures must be survivable? Number of copies, separation of storage, accounts, and credentials

RPO and RTO are measured in the units the service is judged by. A public web server might tolerate twenty-four hours of data loss and an hour of downtime; a ledger database may tolerate neither. The objectives are properties of the workload, not of the backup tools.

A failure domain is anything whose single failure can destroy a group of copies at once. Disks, machines, racks, power circuits, and sites are the familiar ones; this chapter adds two that are specific to backups. The first is authority: a client that holds the credentials that write to a repository usually also holds the credentials that delete from it, so one compromised client is a failure domain for every copy it can reach. The second is consistency: a copy made while its source is changing is a failure domain of its own, because the copy is valid for no single moment. Section 15.2 addresses consistency and Section 15.5 addresses authority; both produce properties that a storage purchase cannot.

Retention is the compromise between history and capacity: every additional generation kept makes accidental deletion further reversible, and costs space and check time. Retention policies are expressed as time-bucketed rules - keep the latest archive, one per day for a week, one per week for a month, one per month for a year - rather than as a fixed archive count, so that policy survives gaps in the schedule. Section 15.4.4 implements such a policy and shows the commands that enforce it.

15.1.2. Selecting Data, Configuration, Metadata, and Secrets

A restorable system needs more than its payload data. The categories below are selected - and restored - together:

Category Examples on the practice systems Notes
Application data /srv/appdata, the PostgreSQL inventory database the payload; usually the largest part
Service configuration /etc/postgresql, systemd unit files, /etc/borg without it the data has nothing to run in
System metadata accounts and groups in /etc/passwd, /etc/group; package selections; the partition and LVM layout decides whether a restored root can boot and log people in
Secrets and keys repository keys and passphrases, SSH host and user keys, LUKS passphrases custody rules differ: see below

Configuration and data have a dependency order on restore: storage and configuration first, then data, then services. Section 15.6.3 makes that order concrete. System metadata is partially embedded in a whole-root backup - accounts and unit files are ordinary files under /etc - but two pieces need explicit attention: the disk layout, which must be rebuilt before the first file can be extracted (Section 15.7.1), and the package list, which Chapter 6 records through apt-mark showmanual when a bare restore needs a package baseline.

Secrets follow a different rule from everything else. A repository key or passphrase stored only on the machine it protects is lost with the machine, and one stored in every backup copy travels with whatever steals a copy. The practice system keeps each secret where its tool expects it - the Borg key file under /etc/borg, the passphrase in a mode-600 root file - and then makes deliberate offline copies of the key and passphrase, which Section 15.5.3 builds. SSH host keys are deliberately kept in the whole-root archive, so that a recovered system still proves its old identity to clients; the backup client's own SSH keys are just as deliberately excluded from that archive (Section 15.7.1 lists both exclusions).

15.1.3. Offline, Off-Site, and Access-Isolated Copies

The oldest workable shape is three copies on two different media with one outside the building. The reasoning is failure-domain arithmetic, and it extends naturally to credentials:

The copy ladder from production host to online repository, vault, and offline disk, with what each copy survives.

Figure 15.1. The copy ladder. A conceptual schematic: each arrow adds one failure-domain boundary - hardware, then authority, then physical detachment.

The online repository on backup1 already sits in a different failure domain from client1's disks. It does not sit outside the reach of client1's backup credentials, though, so a second copy is kept under a separate account and path that the backup credentials cannot touch at all (Section 15.5.2). A third copy lives on a disk that is attached only while it is being refreshed and unmounted afterwards (Section 15.5.3); a copy with no network path cannot be reached by any compromised machine, only by whoever holds the physical media.

Offline copies earn their cost only if they are genuinely detached. A disk that stays mounted on the backup server is online storage with a cable's worth of extra hope: the walkthrough's offline disk is unmounted, and Section 15.5.3 verifies the unmount before treating the copy as detached. Off-site finally means a different building, town, or region: the practice environment keeps all of its disks inside one host, so the off-site property is one the reader must add by carrying real media - or an encrypted copy - to another location. Rotation frequency is the same decision as RPO applied to the worst case: how old may the surviving copy be after a site is lost?

The same arithmetic decides credential placement. The key that writes backups should not be the key that can prune history; the offline key copy should not live on the machine whose compromise is feared. The rest of Section 15.5 is those two sentences turned into accounts, authorized_keys entries, and an offline disk.

15.1.4. Choosing File, Application, and Image Backups

Approach What it captures Versioning Restore granularity Typical use Watch out for
File copy (rsync) files and their metadata none - each copy is one state any file or subtree, immediately browsable fast local copies, staging trees, migration deletions and mistakes propagate to a mirror unless designed around
Archive (tar) files and metadata in one file one archive per invocation whole archive or named members interchange, cold storage, one-shot snapshots grows linearly with data; no dedup; member extraction is manual
Versioned repository (BorgBackup, restic) files as deduplicated, encrypted, checksummed chunks built-in: named archives plus retention single files, subtrees, or whole trees from any archive multi-generation network backups key and passphrase custody become part of the system
Application export (pg_dump, etc.) the application's logical data one file per export rows, tables, databases databases and services with internal state must be paired with a file backup of configuration; live data files are not a backup
Block image (dd, partclone, filesystem-level send) whole devices or filesystems one image per invocation whole volume unsupported filesystems, bare-metal clones, virtual machines huge transfers; restores everything including unused space; needs the same layout back

The categories compose rather than compete: the practice system uses a repository for generations, exports the database with pg_dump because a database's live files are not safely copyable while the server runs (Section 15.2.1), and keeps rsync in the toolbox for controlled copies and staged restore trees. Image backups are the right tool when the filesystem is unknown or when whole-disk identity matters, and Chapter 11 covers dd itself; this chapter does not exercise image backup, and its whole-system recovery in Section 15.7 is file-level by design, because file-level restore works onto different disks and layouts.

Repository tools are close cousins. BorgBackup and restic both chunk, encrypt, deduplicate, and verify on the client side, and both are packaged in Debian:

BorgBackup 1.4 restic 0.18
Repository access local, or SSH to a host running borg serve local, SFTP (no server-side tool), REST server, or cloud backends
Compression yes: lz4, zstd, zlib, lzma yes: zstandard
Retention borg prune with time-bucketed rules restic forget with the same rule style, then restic prune
Server-side append mode borg serve --append-only (see Section 15.5.1 for its limits) REST server --append-only; SFTP access relies on filesystem permissions
Browsing without restore borg mount through FUSE restic mount through FUSE

The walkthrough uses Borg because its restricted borg serve mode makes the two-account design of Section 15.5 explicit and inspectable. The same design works with restic by replacing the forced command with a restricted repository path and letting filesystem permissions, rather than a server-side tool, define what the backup account may write.