Database Disaster Recovery: RPO and RTO
What you will learn
- What a disaster is, beyond a failed disk
- What RPO and RTO mean, and how to calculate them
- How backup frequency sets RPO
- What a recovery plan contains
- Why you must rehearse it
1. Disasters are more than hardware
Lesson 12.5 dealt with a machine failing. A disaster is a larger event that your normal setup cannot absorb:
- the building or data centre is lost (fire, flood, power, or a cloud region outage);
- someone deletes or corrupts data and the mistake is copied to every replica (lesson 12.5);
- an attacker or ransomware encrypts or destroys the data (chapter 8);
- a bad software change breaks the data.
Disaster recovery (DR) is the plan and the preparation for getting the service and its data back after such an event. Backups (lessons 8.1 to 8.3) are the foundation, and this lesson adds two numbers that say what "good enough" means.
2. Two numbers: RPO and RTO
| Term | Full name | Question | Measured in |
|---|---|---|---|
| RPO | Recovery Point Objective | How much data can we afford to lose? | time of data (for example "the last 15 minutes") |
| RTO | Recovery Time Objective | How long can we afford to be down? | time of outage (for example "at most 2 hours") |
Draw a timeline of a disaster:
time ──────────────────────────────────────────────────────────►
last good copy DISASTER service back
│◄──── data lost ────►│◄──── downtime ────────►│
(RPO) (RTO)
- RPO looks backwards from the disaster to the last copy you can restore. Everything written in that gap is lost.
- RTO looks forwards from the disaster to the moment users can work again.
These are targets the business chooses (and pays for), not facts about technology. A smaller RPO and RTO cost more.
3. Calculating them
Take a made-up shop. It takes about 40 orders an hour at an average of 800 taka. A backup is made every 6 hours and copied to another place. Restoring takes about 45 minutes, and then 30 minutes are needed to check the data and reconnect the application.
backup_every_hours = 6
orders_per_hour = 40
price = 800 # made-up average order value
restore_minutes = 45
check_minutes = 30
rto_minutes = restore_minutes + check_minutes
rpo_hours = backup_every_hours # worst case: crash just before the next backup
lost_orders = rpo_hours * orders_per_hour
print("worst-case RPO:", rpo_hours, "hours of data")
print("orders lost in that worst case:", lost_orders)
print("value lost:", lost_orders * price)
print("RTO:", rto_minutes, "minutes")
print("sales missed while down:", round(rto_minutes / 60 * orders_per_hour), "orders")
worst-case RPO: 6 hours of data
orders lost in that worst case: 240
value lost: 192000
RTO: 75 minutes
sales missed while down: 50 orders
The same calculation in SQL, on the sample data. This lesson runs on the sample database you chose in lesson 4.1 (use the Example data picker at the top). Arithmetic is plain SQL, and the sample tables show what a real RPO would have cost. The data is made up.
SELECT 6 AS backup_every_hours, 40 AS orders_per_hour, 6 * 40 AS lost_orders, 6 * 40 * 800 AS value_lost,
45 + 30 AS rto_minutes, ROUND((45 + 30) / 60.0 * 40) AS sales_missed;
backup_every_hours orders_per_hour lost_orders value_lost rto_minutes sales_missed
------------------ --------------- ----------- ---------- ----------- ------------
6 40 240 192000 75 50.0
(1 row)
SELECT 6 AS backup_every_hours, 40 AS orders_per_hour, 6 * 40 AS lost_orders, 6 * 40 * 800 AS value_lost,
45 + 30 AS rto_minutes, ROUND((45 + 30) / 60.0 * 40) AS sales_missed;
backup_every_hours orders_per_hour lost_orders value_lost rto_minutes sales_missed
------------------ --------------- ----------- ---------- ----------- ------------
6 40 240 192000 75 50.0
(1 row)
SELECT 6 AS backup_every_hours, 40 AS orders_per_hour, 6 * 40 AS lost_orders, 6 * 40 * 800 AS value_lost,
45 + 30 AS rto_minutes, ROUND((45 + 30) / 60.0 * 40) AS sales_missed;
backup_every_hours orders_per_hour lost_orders value_lost rto_minutes sales_missed
------------------ --------------- ----------- ---------- ----------- ------------
6 40 240 192000 75 50.0
(1 row)
What would an old backup cost? If the newest backup were taken on a given date, every row written after it would be lost:
Orders placed on or after 1 January 2026 would be lost if the newest backup dated from 31 December 2025:
SELECT COUNT(*) AS orders_lost, MIN(order_date) AS first_lost, MAX(order_date) AS last_lost
FROM orders WHERE order_date >= '2026-01-01';
orders_lost first_lost last_lost
----------- ---------- ----------
1150 2026-01-01 2026-09-30
(1 row)
Ledger rows written on or after 1 January 2026 would be lost if the newest backup dated from 31 December 2025:
SELECT COUNT(*) AS rows_lost, SUM(amount_cents) AS cents_moved, MIN(txn_date) AS first_lost, MAX(txn_date) AS last_lost
FROM transactions WHERE txn_date >= '2026-01-01';
rows_lost cents_moved first_lost last_lost
--------- ----------- ---------- ----------
1743 33077712 2026-01-01 2026-09-30
(1 row)
Submissions handed in on or after 1 January 2026 would be lost if the newest backup dated from 31 December 2025:
SELECT COUNT(*) AS submissions_lost, MIN(submitted_on) AS first_lost, MAX(submitted_on) AS last_lost
FROM submissions WHERE submitted_on >= '2026-01-01';
submissions_lost first_lost last_lost
---------------- ---------- ----------
1024 2026-02-13 2026-05-06
(1 row)
Reading the result:
- RPO is a worst case. With a backup every 6 hours, a disaster just before the next backup loses almost 6 hours of data. On average you would lose less, but plans must be built for the worst case.
- RTO is a sum of steps. Finding the problem, getting the backup, restoring it, checking it and reconnecting all take time. Here only restoring and checking are counted, so the real RTO is longer. People often underestimate it.
Suppose the owner says: "Losing 240 orders is too many. I can accept 15 minutes."
new_rpo_minutes = 15
print("to hit RPO of 15 minutes, the newest changes must be copied at least every", new_rpo_minutes, "minutes")
print("orders lost in the new worst case:", round(new_rpo_minutes / 60 * orders_per_hour))
to hit RPO of 15 minutes, the newest changes must be copied at least every 15 minutes
orders lost in the new worst case: 10
A backup every 6 hours cannot reach that. Options include: more frequent backups, or continuously shipping the log of changes to another place so that a restore can replay changes up to a chosen moment (lesson 8.2 on kinds of backup), or a replica in another location (lesson 12.5). Each option costs money and work. The right RPO is where the cost of losing data and the cost of protection meet.
4. The recovery plan
A plan is a written document that someone who is tired and stressed can follow. It should say:
| Part | Content |
|---|---|
| Targets | the agreed RPO and RTO |
| Who decides | who declares a disaster and who is in charge; their phone numbers |
| Where things are | where backups live, how to get access, where the passwords are kept (not in the same system that is down) |
| Steps | numbered steps for restoring: get the backup, restore it, check it (PRAGMA integrity_check, row counts, lesson 12.2), point the application to it |
| Checks | how to confirm that the data is right before opening to users |
| Communication | who tells customers and staff, and what they say |
| After | a review of what happened and what to change |
Keep a copy of the plan outside the systems it describes. A plan stored only on the broken server helps nobody.
5. Rehearse
A plan that has never been run usually fails in a surprise: the backup was incomplete, the password was lost, the restore took four hours instead of one, or a step was missing. So:
- Restore a backup onto a spare machine on a schedule, for example every quarter.
- Time it from the start. That is your measured RTO.
- Check the data (integrity check and sample queries), and find the age of the newest record. That is your measured RPO.
- Fix the plan with what you learned, and write it down.
Worked example: a rehearsal result
The tailor shop rehearses on a Sunday. The notes:
| Item | Target | Measured |
|---|---|---|
| Time to find the backup and the password | not set | 25 minutes (the password was in the old owner's notebook) |
| Restore | 45 minutes | 1 hour 10 minutes (the database had grown) |
| Check and reconnect | 30 minutes | 30 minutes |
| Measured RTO | 75 minutes | 2 hours 5 minutes |
| Newest order in the restored copy | within 6 hours | 5 hours 40 minutes old |
The result shows the real RTO is far above the target. The fixes: store the password in a shared password manager, move the backups to faster storage, and either accept a 2-hour RTO or buy a faster setup. The figures are made up; the value of the exercise is finding the 50 minutes that nobody had counted.
Common mistakes
- Never testing a restore. Many "backups" turn out unusable.
- Taking the RPO from the backup schedule, but forgetting that the backup may not have finished or may have failed silently. Monitor backup jobs (lesson 12.3).
- Keeping the only copy in the same place as the database (lessons 8.2 and 12.4).
- Treating a replica as disaster recovery (it copies mistakes).
- Writing a plan and filing it, with no owner, no updates and no rehearsal.
Key takeaways
- A disaster is anything normal failover cannot absorb: lost sites, deleted data, attacks, bad changes.
- RPO: how much data you can lose. RTO: how long you can be down. Both are business targets that cost money.
- Backup frequency (or log shipping) sets RPO; the sum of all recovery steps sets RTO.
- A recovery plan names the targets, the people, the places and the steps, and is stored outside the failing system.
- Rehearse restores, time them and fix the plan: measured numbers matter more than planned ones.
Practice
1. Define RPO and RTO in one sentence each.
Show answer
RPO: the most data (measured as time) you accept losing. RTO: the longest time you accept being unavailable.
2. A shop backs up every 12 hours and takes 30 orders an hour. What is the worst-case number of lost orders?
Show answer
12 × 30 = 360 orders.
3. Restoring takes 50 minutes, checking 20 and reconnecting 10. What is the RTO (counting only these steps)?
Show answer
80 minutes. The real RTO is longer if finding the problem and the backup also take time.
4. Why is a replica not enough for disaster recovery?
Show answer
It copies every change, including mistakes and malicious changes, and it may be in the same place as the primary. It does not keep earlier good versions.
5. Name three things a recovery plan should contain.
Show answer
Any three of: targets, who decides, where backups and passwords are, restore steps, checks, communication, after-action review.
6. In the rehearsal example, what made the measured RTO larger than the target?
Show answer
Time was lost finding the password (25 minutes), and the restore took longer than planned (1 hour 10 minutes instead of 45) because the database had grown.