Backups and Disaster Recovery: The Spare Tyre of Tech
At 14:05 on a Tuesday, a cleanup script meant for the test database runs against the shop's real one and deletes the orders table. The replica in another zone deletes it too, within moments. This lesson explains disaster recovery: why a replica is not a backup, how much data and time you can lose, the four recovery levels, and why only a tested restore counts.
Backup versus replication
Disaster recovery (DR) is how you get a service and its data back after a failure too big for normal redundancy, such as lost data or a whole region going dark. Its first tool is the backup.
A replica, from lesson 11, receives every change from the primary database within moments. That makes it a good spare when a machine dies, and useless here: it copies a deleted table or a bad data change as faithfully as a new order.
A backup is a separate copy of your data as it was at one moment. Last night's backup still holds the orders table. Replication protects you from losing a machine; backups protect you from losing or ruining the data itself. You need both.
Amazon RDS, for example, keeps daily snapshots, point-in-time copies of its disk, plus a log of every change, so it can restore a new copy of the database as it was at 14:04. That is called point-in-time recovery.
The 3-2-1 rule
A common rule of thumb, the 3-2-1 rule, says to keep:
- 3 copies of your data, the live data plus two backups, so one bad copy is not the end;
- on 2 kinds of storage, such as database disks and object storage like Amazon S3, so one storage fault cannot ruin every copy;
- with 1 copy off-site, out of reach of a fire, flood or regional outage; in the cloud, another region.
A replica does not count, because it shares the live copy's mistakes. For the shop, the three could be the live database, nightly snapshots in object storage, and a copy of each snapshot in a second region.
Many teams keep the off-site copy in a separate cloud account with its own logins, so one stolen password cannot delete everything.
Two numbers: RPO and RTO
Agree two targets with the service's owners. Like an SLO, each is an objective: a number you aim for and check.
The recovery point objective (RPO) is the most data you can afford to lose, measured in time back from the disaster. An RPO of one hour means at most the last hour of orders may be missing.
The recovery time objective (RTO) is the longest the service may be down, from the disaster until users can work again. The restore, the checks and the switch back must all fit inside it.
In the timeline, the shop has only a nightly backup, last run at 02:00, so the 14:05 disaster loses 12 hours and 5 minutes of orders. Notice that the two gaps sit on opposite sides: backup frequency shapes the one before, recovery speed the one after.
With nightly backups, a failure just before the next one loses almost a day. Point-in-time recovery shrinks that to minutes, because RDS uploads its change logs every five minutes.
Big restores are slow: copying data back, starting servers and checking can take hours. A 99.9 percent SLO allows about 43.2 minutes of downtime in 30 days, so the timeline's two-hour restore spends it nearly three times over.
Four levels of disaster recovery
If restoring is too slow for your RTO, keep a second site, usually another region, partly or fully ready. AWS's disaster recovery guidance describes four levels, with rough RPO and RTO targets:
- Backup and restore. Only backups wait at the second site; in a disaster you create servers and restore into them. Hours.
- Pilot light. Data is copied there continuously and core parts such as the database run, but app servers stay off until needed, like a boiler's small pilot flame. Tens of minutes.
- Warm standby. A smaller but complete copy runs all the time; you scale it up and send it traffic. Minutes.
- Active-active. Full copies at two or more sites serve users at once, so if one fails the others carry the load. Near zero, but costliest and most complex, because every write must reach every site.
In the ladder, notice the footer: every level above the first copies data continuously, so it would copy the 14:05 deletion too. Each rung buys speed against losing a site; none replaces backups.
Choose per service. Checkout, where every minute down loses sales, might justify a warm standby, while an internal report can wait hours. Pick the cheapest level that meets your RPO and RTO.
Practise the recovery
In a disaster, the incident process from lesson 12 still runs: the incident commander declares a disaster and starts the written recovery plan. In the flowchart, notice the first decision: if a site is lost but the data is intact, fail over; if the data is damaged, restore from before the damage.
Before users return, compare row counts, check the newest record's time and run smoke tests, quick checks that the main features work. The blameless postmortem then records the RPO and RTO you really achieved.
An untested backup is only a hope. Backups fail quietly: the job stopped months ago, it skipped a new database, the files are corrupt, the encryption key is lost, or the restore takes ten hours, not one.
GitLab learned this in January 2017: after an engineer deleted production database data by mistake, its regular backups turned out not to be working, and it restored from a copy about six hours old.
So restore on a schedule: for example, restore last night's backup into a test environment monthly, check it and time it. That time is your real RTO. Also alert when the newest backup is older than expected.
Immutable backups against ransomware
Ransomware is malicious software that encrypts your files and demands payment for the key. Attackers often delete backups first, so that paying looks like the only way out.
An immutable backup cannot be changed or deleted until a retention period you set has passed, so a stolen administrator password cannot remove it. In the compliance mode of Amazon S3 Object Lock, for example, not even the account's all-powerful root user can delete a locked object before its retention date.
Check yourself
Your shop runs active-active in two regions. Why do you still need backups if a bad release corrupts every customer's address?
Active-active copies every write to both regions within moments, so both hold the bad addresses. Only a backup, or point-in-time recovery, from before the release has the good data.
Backups run nightly and a tested restore takes three hours. The RPO is one hour and the RTO four hours. Which target do you miss, and what fixes it?
The RPO: a failure just before the next backup loses almost 24 hours of data. The restore meets the RTO. More frequent backups or point-in-time recovery fix the RPO.
An attacker with an administrator's password encrypts the servers and deletes every backup in the account. What would have saved the data?
An off-site copy in a separate account, or immutable backups nobody can delete before their retention date. Either leaves a copy that the stolen password cannot reach.
Go deeper
- Chaos Engineering in Production: A Practical Guide: rehearse failures on purpose, with experiments and game days, so recovery is practised before a real disaster.