Disaster recovery and backups
Pick an RPO and an RTO, keep backups that a bad script cannot reach, and time real restores until you know you can get your data back.
Updated since you finished it. We changed this lesson after you marked it done. Your progress is kept.
What broke
On 5 April 2022, a cleanup script at Atlassian deleted 883 sites. They belonged to 775 customers. 1 You met this outage in incident response, from the communication side. Here is the restore side.
Atlassian was not careless about backups. It kept them for 30 days. It could restore any data store to a chosen point in time. It also kept immutable backups and tested its restores. 1
The data did come back. For most customers, Atlassian restored to five minutes before the deletion. For 57 customers restored early, some databases first went back further, and Atlassian recovered the missing data later. It says no customer lost more than five minutes of data. 1
Time was the problem. The first customers got their sites back on 8 April. The last sites came back on 18 April. Some customers waited up to 14 days. 1
Why so slow? Atlassian regularly restored one customer or a small set of customers, and it could restore all customers into a new environment. It had no tested way to restore hundreds of sites into the live, shared environment. Each data store held data for many customers. So the team had to pull each deleted site out of the backups, piece by piece. With its first method, Atlassian estimated three weeks to restore everyone. 1
The idea in simple words
Disaster recovery (DR) is your plan to get data and service back after something big goes wrong. That can be a lost data centre, a bad script, or ransomware.
Two numbers set the goal. The RPO (recovery point objective) is how much data, measured in time, you accept to lose. The RTO (recovery time objective) is how long you accept to be down. Atlassian describes them with two questions. How fresh is the data after you restore it? How quickly can you give it back to the customer? 1
Smaller numbers cost more. AWS calls the choice a trade-off between RTO and RPO on one side, and cost and complexity on the other. It also warns against a strategy that is stricter than you need. 6
You saw in the replication lesson that a follower copies every change from the leader. That includes a wrong DELETE, so a replica is not a backup. AWS says continuous replication "will not protect you against data corruption or destruction" unless you also have point-in-time recovery. 6
The key idea. A backup counts only after you have restored it and timed the restore, at the size and shape of the disaster you fear. Until then, it is a hope.
How it works
Kinds of backup
A full backup copies everything. It is simple to restore, but big and slow.
An incremental backup holds only what changed since the previous backup. Since version 17, Postgres can take one with pg_basebackup --incremental. To restore it, you need it and every earlier backup it depends on. Postgres does not track that chain for you, so you must not delete a backup that a later one needs. 3
A differential backup holds everything that changed since the last full backup. To restore, you load the full backup, then only the newest differential. Differentials grow every day, so Microsoft suggests a new full backup at set times, for example weekly. 5
There is a second split. A logical backup, like pg_dump, writes rows as SQL. A physical backup copies the database's own files, or a disk snapshot of them. Postgres says logical dumps "do not contain enough information to be used by WAL replay". 3 So they cannot give you point-in-time recovery.
Point-in-time recovery
Point-in-time recovery (PITR) needs two things: a base backup of the data files, and an archive of every write-ahead log (WAL) file since then. To recover, you load the base backup and replay the WAL. You can stop the replay at any moment after the base backup ended. 3
Step through a recovery from a bad DELETE. Use Next and Back, or the ← and → keys.
- A full base backup runs every Sunday at 02:00. After it, the database keeps every write-ahead log (WAL) file in an archive. Together they hold every change since Sunday.
- On Tuesday at 14:05, a script runs a DELETE without the right WHERE clause. The replica copies the DELETE a moment later. Replication cannot help you here.
- You start a new, empty server and load Sunday's base backup into it. You do not touch the broken primary yet. It may still hold good writes you need.
- You tell Postgres to replay the archived WAL and stop at 14:04:59. Every change up to that moment comes back. The DELETE, and everything after it, is skipped.
- The rows are back. Good writes made after 14:05 are only on the old primary, so you copy them over by hand. The downtime runs until the app uses the new server. Compare both with your RPO and RTO.
You choose the stop point by time, by a named restore point, or by a transaction ID. 3 You need an unbroken chain of WAL files back to the base backup. One missing file breaks it. Postgres advises you to set up and test WAL archiving before you take your first base backup. 3
A physical PITR restores the whole database cluster, not one table or one customer. 3 Atlassian hit a similar problem at a much larger scale: its data stores were shared by many customers. Restoring one customer from a shared store means a restore to a side server, then a careful copy back.
Where the copies live
The 3-2-1 rule says: keep 3 copies of important data (1 primary and 2 backups), on 2 different media types, with 1 copy offsite. A 2012 US-CERT paper states it and credits it to the second edition (2009) of The DAM Book, a book for photographers by Peter Krogh. 8
In the cloud, "offsite" should also mean "outside your blast radius". AWS says copying backups to another account helps against insider threats or a stolen account. 7
Attackers know where backups are. CISA says "many ransomware variants attempt to find and subsequently delete or encrypt accessible backups". It asks you to keep offline, encrypted backups. 9 An immutable backup cannot be changed or deleted until its retention time ends. CISA notes that some cloud vendors offer this, but says to use it "with caution". It may not meet some compliance rules, and a wrong setting can be costly. 9
Seatbelts against your own mistakes
- Deletion protection. Amazon RDS will not delete a database while deletion protection is on. It is on by default for databases created in the console. If you delete without keeping automated backups, RDS deletes those backups in the same region. 10
- A delayed replica. In Postgres,
recovery_min_apply_delay = '1h'makes a standby apply each commit only an hour after the primary made it. That gives you time to stop it before a bad change arrives. Longer delays fill its disk with waiting WAL files. 4 - Soft delete. Mark data as deleted and remove it only later. After the outage, Atlassian committed to soft deletes, keeping deleted data until a retention period ends. 1
Test the restore, and time it
GitLab learned this in 2017. An engineer wiped the primary database while fixing replication, and the replica's data had already been wiped. The team restored from a disk snapshot made six hours earlier, which sat on a staging server. Copying it took around 18 hours, because the disks were throttled to about 60 Mbps. 2 GitLab also wrote that nobody owned the backups, so "nobody was responsible for testing this procedure". 2
AWS says your backup strategy "must include testing your backups", and suggests restoring on a schedule. 7 CISA also asks you to test backups "in a disaster recovery scenario". 9
A good restore test is a job, not a promise. Every week it restores the newest backup to a fresh server. It checks row counts and a few known records. It records how long the restore took, and it pages someone when any step fails.
A game day goes further. The team acts out a whole disaster, with people, runbooks and the clock running. After the outage, Atlassian committed to regular DR exercises that restore every product for a large set of sites at once. 1
Trade-offs
AWS lists four strategies in order of rising cost and complexity, and falling RPO and RTO. The middle two, pilot light and warm standby, keep a second site partly ready. The ranges below are AWS's own. 6
| Strategy | RPO and RTO (AWS) | What runs at the second site | Use it when |
|---|---|---|---|
| Backup and restore | RPO in hours, RTO in 24 hours or less. PITR can bring RPO as low as 5 minutes in some cases. | Only backups. You rebuild servers and restore data after the disaster. | Most internal tools and young products. It is cheap and simple. |
| Pilot light | RPO in minutes, RTO in tens of minutes. | Data is replicated and always on. App servers are off until you need them. | Downtime of an hour hurts, but a second full stack is too costly. |
| Warm standby | RPO in seconds, RTO in minutes. | A smaller but working copy of the whole system. You scale it up. | Customer-facing systems where minutes matter. |
| Multi-site active/active | RPO near zero, RTO potentially zero. | Full production in every site, all taking traffic. | You already need several regions for users or law. |
Simple rule: every strategy still needs point-in-time backups. Even with active/active, a data disaster's recovery point "will always be at some point before the disaster was discovered". 7
At work: how a senior uses this
- Ask the business for the RPO and RTO of each system, and write them down.
- Ask, "Which restore have we timed this quarter, and how long did it take?" If nobody knows, the RTO is a guess.
- List the disasters you plan for: a lost zone, a bad migration, a deleted customer, ransomware. Check that each one has a tested restore of the right shape.
- Keep at least one backup copy in a separate account, with different credentials, that production scripts cannot delete.
- Before a risky migration or bulk delete, take a fresh backup and know the restore time. See schema migrations.
- Alert when a backup job fails or the newest backup is too old.
With AI
What to ask the agent
"Here is our Postgres setup. Write a weekly job that restores the newest base backup and WAL to a fresh server, runs these five checks, records the restore time, and fails loudly if any step fails."
"Read our Terraform. List every database, bucket and backup vault. For each, tell me if deletion protection, versioning or object lock is on, and who can delete it."
What to check yourself
- The restore test runs against a real, recent backup, not a tiny test database. Restore time grows with data size.
- The checks look at data, not only at "the server started".
- The backup credentials are different from the production credentials the agent saw. Code that can reach both is a single point of failure.
- Retention is long enough to reach back past the time a bug could go unnoticed.
Check yourself
Your progress is saved only in this browser. Export it to keep it safe.
You have finished 5 lessons. Your progress lives only in this browser. Export a copy so you don’t lose it.
Go deeper
Show 10 sources and related lessons
- Atlassian, “Post-Incident Review on the Atlassian April 2022 outage” (opens in a new tab)
How 883 deleted sites came back with little data loss, and why it still took up to 14 days. - GitLab, “Postmortem of database outage of January 31” (opens in a new tab)
Backup methods that were broken or never set up, and an 18-hour copy over slow disks. - PostgreSQL documentation: 25.3. Continuous Archiving and Point-in-Time Recovery (PITR) (opens in a new tab)
Base backups, WAL archiving, recovery targets and incremental backups, with their limits. - PostgreSQL documentation: 19.6. Replication (opens in a new tab)
The recovery_min_apply_delay setting for a time-delayed standby, and what it costs. - Microsoft Learn, “Differential Backups (SQL Server)” (opens in a new tab)
What a differential backup holds, why it grows, and what you need to restore it. - AWS Well-Architected Framework, Reliability Pillar, “REL13-BP02 Use defined recovery strategies to meet the recovery objectives” (opens in a new tab)
The four DR strategies with their RPO and RTO ranges, in order of cost and complexity. - AWS Whitepaper, Disaster Recovery of Workloads on AWS: Recovery in the Cloud, “Disaster recovery options in the cloud” (opens in a new tab)
Each strategy in detail, cross-account backups, scheduled restores, and why active/active still needs backups. - Paul Ruggiero and Matthew A. Heckathorn, “Data Backup Options”, US-CERT (Carnegie Mellon University, 2012) (opens in a new tab)
A short paper that states the 3-2-1 rule and credits it to Peter Krogh's The DAM Book. - CISA, “#StopRansomware Guide” (opens in a new tab)
Why backups must be offline and tested, and a warning about immutable storage. - Amazon RDS User Guide, “Deleting a DB instance” (opens in a new tab)
Deletion protection, final snapshots, and what happens to automated backups when you delete a database.
Real incident: Atlassian, 5 Apr 2022: Atlassian outage: a cleanup script deleted 883 sites
Related: Replication · Incident response and postmortems · Schema migrations without downtime · Safe deploys and config changes · Multi-region systems and data locality
Before this: Database replication, to see how followers copy every change. Next: Multi-region systems and data locality, for running in more than one region every day, not only after a disaster.
Related lessons: Incident response and postmortems, Safe deploys and config changes and Requirements and non-functional needs. Case study: the GitLab incident.