DatabasesDeeper

Kayavak / Databases / DB·64 Durability, Backups and Recovery / Deeper

Deeper · Databases

Durability, Backups and Recovery

The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.

Why does this exist?

Data loss rarely comes from the disaster people plan for. On 31 January 2017 an engineer at GitLab, working late on a replication problem, deleted the primary database's data directory on the wrong server. Of the backup methods the company believed it had, none produced a usable recent copy; they restored from a snapshot taken six hours earlier, losing that data. Their public post-mortem became a standard lesson: a backup that hasn't been restored is a hope, not a backup.

The techniques are older. Write-ahead logs, designed for crash recovery (ARIES, 1992), also enable point-in-time recovery: restore a base backup and replay archived logs to any moment, such as one second before a bad DELETE. The photographer Peter Krogh's 3-2-1 rule (three copies, two kinds of media, one off-site) spread from photo archives to IT. Ransomware added a new requirement: backups that attackers with your credentials can't delete or encrypt.

The mental model

Try it yourself first: write your own model in the Mental Model Explorer, then compare.

Replicas protect against hardware failure; backups protect against everything else, including you. Their value is measured only by a successful, timed restore.

Question Answer
What is it? Copies of data and logs from which a database can be rebuilt, and the procedures to do it
Problem it solves Recovering from deletion, corruption, bugs, attacks and disasters that replicas faithfully copy
Parts Logical and physical backups, WAL archiving, point-in-time recovery, retention, immutability, RPO and RTO, restore drills
How it works Take base backups, archive the log continuously, store copies separately; restore and replay to a chosen time
Assumptions Backups are complete, uncorrupted, reachable and restorable within the RTO
When they change Untested backups fail when needed: missing files, wrong versions, unknown passwords, too slow to restore
Where it fails Backups in the same account an attacker or a mistake can delete; restores slower than anyone measured
Related ideas WAL (ch58); replication and failover (ch61); disaster recovery (Infrastructure, Observability and SRE)

What if?

What if your only protection were a synchronous replica?

Reason it through, then open

It would survive the primary's hardware dying with zero data loss, and it would apply a mistaken DROP TABLE within milliseconds, faithfully. Replication copies every change, good or bad. Recovering from a mistake needs a copy from before it: a backup plus logs to replay up to just before the mistake.

What if you'd never timed a full restore?

Reason it through, then open

Your recovery time objective would be a guess. Restoring terabytes, then replaying a day of logs, can take many hours, and the first real attempt often uncovers missing steps, permissions and tools. Regular restore drills turn RTO from a number in a document into a measured fact.

Where the boundary is

Aspect RPO RTO
Measures How much data you can afford to lose How long you can afford to be down
Set by Backup and log-archive frequency Restore speed and procedures
Proven by Restoring and checking the latest data Timing a full restore drill

How sure are we?

Claim How it's known Where from
GitLab's 2017 incident and its six-hour loss Historical GitLab's public post-mortem
Point-in-time recovery from base backups and archived WAL Convention PostgreSQL documentation; same idea in other engines
Untested backups often fail Model Repeatedly reported in incident reviews; exact rates vary

Still open

Defending backups against attackers who already hold administrator credentials (immutable storage, separate accounts, air gaps) is an active practical concern, and so is restoring very large datasets fast enough.

What would change your mind? If your restore drills always succeeded within RTO, you could drill less often. Most organisations discover they can't until they try.

Recall

Why aren't replicas backups?

They copy every change immediately, including deletions and corruption.

What's the difference between RPO and RTO?

RPO is acceptable data loss; RTO is acceptable downtime.

What makes point-in-time recovery possible?

A base backup plus continuously archived write-ahead logs replayed to the chosen moment.

What's the 3-2-1 rule?

Three copies of data, on two kinds of media, with one off-site.

Reflect

Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.