Home›Operate›Run it well 10: backups
Course · Stay upLesson 24 of 330 read
Run it well · Chapter 6

How long would a restore take, and how much would you lose?

What is the newest moment I can get back to, and how long until the database is serving again?

Everyone has backups. Fewer people know how long a restore takes, because they have never timed one. This page picks a side, shows what each engine offers, does the restore-time arithmetic, and lists what breaks.

Start with a story

2:04 PM: someone dropped the customers table

A migration script ran against production instead of staging. DROP TABLE customers committed at 14:00:12. The replicas copied it a few milliseconds later, which is why a replica is not a backup. You need the table exactly as it was at 14:00:11. Not last night's copy. The one from eleven seconds before the mistake.

That is a point-in-time restore. It is two steps in every engine: restore the last full backup, then replay the log up to one moment and stop. Here is that restore in each engine. Do it on a separate server, never on top of production, then copy the one table back.

Why not restore straight onto the production server?

Because everything written since 14:00:12 is valid data you would throw away. Orders placed at 14:01 are real. Restore to a scratch server, take out only what was lost, and put that back. The rest of production keeps running the whole time.

PostgreSQL

pgBackRest: restore to a time

# on a scratch server with the same major version
pgbackrest --stanza=main --type=time "--target=2026-12-01 14:00:11+00" \
  --target-action=promote restore
# start PostgreSQL; it restores the last full backup, then replays archived WAL up to 14:00:11

# copy the lost table back to production
pg_dump -h scratch -t customers -Fc shop > customers.dump
pg_restore -h prod -d shop customers.dump

If you only have pg_basebackup and a WAL archive, it is the same idea by hand: restore the base backup, set restore_command and recovery_target_time, create recovery.signal, and start the server.

MySQL

XtraBackup, then the binlog up to the DROP

# restore the last full backup on a scratch server
xtrabackup --prepare --target-dir=/backups/full
xtrabackup --copy-back --target-dir=/backups/full
cat /backups/full/xtrabackup_binlog_info        # the binlog file and position the backup ends at

# find the DROP in the binlog, and note the position just before it
mysqlbinlog --base64-output=decode-rows -v binlog.000412 | grep -n -B12 "DROP TABLE"

# replay from the backup's position up to just before the DROP
mysqlbinlog --start-position=<from xtrabackup_binlog_info> --stop-position=<start of the DROP event> \
  binlog.000411 binlog.000412 | mysql -uroot -p

Stopping at a position is exact. --stop-datetime also works, but it has one-second precision, and other transactions may have committed in the same second as the DROP.

MongoDB

A dump plus the oplog, or PBM

# Percona Backup for MongoDB, with point-in-time recovery enabled
pbm restore --time="2026-12-01T14:00:11"

# or with mongodump: a dump taken with --oplog, replayed up to a timestamp
mongorestore --oplogReplay --oplogLimit=1796133611:1 /backups/dump

The --oplogLimit value is Unix seconds (1796133611 is 14:00:11 UTC on that day), with an increment after the colon. Entries at or after it are not replayed.

The number that matters

Time the drill

Run this drill on a schedule, on a real backup, and write down how long each step took: finding the backup, copying it, replaying the log, checking the table. That total is your real recovery time. Most teams discover in the first drill that it is far longer than anyone assumed, or that one piece is missing: a gap in the WAL archive, a binlog that was already purged, a key nobody can find. The rest of this chapter is about planning for exactly those failures.

The decision

Physical backups plus a continuous log archive, restored on a schedule

I take a physical backup (a copy of the data files) every day or every week, and I archive the log continuously (WAL, binlog or oplog) to storage in another account. Together they let me restore to any moment, not just to last night. That is point-in-time recovery, PITR.

Two numbers decide the design. RPO, recovery point objective: how much recent data you can afford to lose. RTO, recovery time objective: how long you can be down. The archive sets the RPO, usually seconds to a few minutes. The size of the database and how much log has to be replayed set the RTO.

And the part that is skipped most: restore it, regularly, on purpose, and time it. A backup nobody has restored is a hope, not a backup.

In one line. A daily base backup plus a continuous log archive, in another account, with a restore tested every month and its time written down.

Three kinds of backup

Physical, logical and snapshot: what each is for

KindWhat it isGood forWeak at
PhysicalA copy of the data files, taken while the server runs, plus the log needed to make it consistentFast restores of big databases. The base for PITR.Same major version and platform only. Restores everything, not one table.
LogicalSQL statements or documents: pg_dump, mysqldump, MySQL Shell dump, mongodumpMoving data between versions or engines. Restoring one table.Slow to restore at size: every index is rebuilt. Not point in time on its own.
Storage snapshotA disk or cloud volume snapshotVery fast to take. Managed services use them under the hood.Consistent only if the log is on the same snapshot or the database is told first. Same region and account unless copied.
How each engine does it

The tools I would reach for

PostgreSQL

  • Base backup: pg_basebackup, or pgBackRest, Barman or WAL-G, which add compression, parallelism, retention and checks.
  • Log archive: archive_command or archive_library copies each WAL segment as it fills.
  • PITR: restore the base, set restore_command and recovery_target_time, create recovery.signal, start.
  • Since 17: incremental backups with pg_basebackup --incremental and pg_combinebackup, with summarize_wal = on.

MySQL

  • Physical: Percona XtraBackup or MySQL Enterprise Backup. The clone plugin (8.0.17 and later) copies a whole instance, mainly to build replicas.
  • Logical: MySQL Shell's util.dumpInstance(), parallel and much faster than mysqldump. mysqlpump is gone in 8.4.
  • PITR: restore the physical backup, then replay binlogs with mysqlbinlog --stop-datetime up to the moment before the mistake.
  • Keep binlogs long enough: binlog_expire_logs_seconds (30 days by default) and copy them off the server.

MongoDB

  • Self-managed: Percona Backup for MongoDB (PBM) takes physical or logical backups and slices the oplog for PITR, across shards too.
  • mongodump --oplog gives a consistent dump of a replica set, but not of a sharded cluster.
  • Filesystem snapshots work if the journal is on the same volume.
  • Atlas and Ops Manager: continuous cloud backup with PITR inside the retention window.

Managed services do most of this for you. Amazon RDS and Aurora, for example, restore to any second inside a retention window of up to 35 days, usually to within the last five minutes. What they do not do is tell you how long the restore takes for your size, or test that your application works after one.

Restore time, worked out

The arithmetic before the incident, not during it

The numbers on this page are arithmetic from the assumptions written next to them, not measurements. Put in your own sizes and speeds, and time a real restore before you trust any of them.

StepAssumptionTime
Copy the base backup to the new server2 TB at 400 MB/s from object storageabout 1 h 25 min
Replay the log since the base backupa daily base; 20 hours of WAL at 30 GB an hour, replayed at 150 MB/sabout 1 h 10 min
Start, check, point the application at itscripted and rehearsed15 to 30 min
Totalabout 3 hours

Two levers move this most. More frequent base backups shorten the replay. Faster storage and parallel restore (pgBackRest and XtraBackup both restore in parallel) shorten the copy. If three hours is too long, the answer is often not a better backup but a standby you can promote in seconds, with backups as the second line for the mistakes a standby faithfully copies, such as a dropped table.

What breaks

The failures that show up only during a restore

What happensWhyWhat I do
The restore fails halfwayA WAL or binlog file is missing from the archive; the archive command failed silently for daysAlert on archive failures (pg_stat_archiver.failed_count, the last archived time). Run a restore check that replays to the latest point.
The restore works but takes 9 hoursNobody timed it; a weekly base means days of log to replayTime a restore every month. Take base backups often enough to keep replay inside the RTO.
Backups deleted with the databaseSame account, same credentials; ransomware or a mistake removes bothCopy to another account with object lock or immutable retention.
Restored to the wrong momentClocks, time zones, or a target after the bad statementFind the exact transaction or binlog position of the mistake first; restore to just before it.
The data is back but the app is notUsers, grants, extensions, secrets or DNS were not part of the planThe runbook covers the whole service, not only the data files.
Logical dump of a big database "as the backup"Restoring rebuilds every index; a 500 GB restore can take most of a dayLogical dumps for portability; physical backups for recovery.
Alternatives rejected

Why not just...

How to operate it

Checks I would automate

What I look at every week, and what a monthly restore test runs:

-- PostgreSQL: is the archive keeping up?
SELECT archived_count, last_archived_wal, last_archived_time,
       failed_count, last_failed_wal, last_failed_time
FROM pg_stat_archiver;
-- pgBackRest: what backups exist, and are they complete?
pgbackrest --stanza=main info

-- MySQL: oldest binlog still on the server, and how long they are kept
SHOW BINARY LOGS;
SHOW VARIABLES LIKE 'binlog_expire_logs_seconds';

-- MongoDB with PBM: backups and the PITR window
pbm status
pbm list
Version notes

What changed recently

Your turn

Your database is 800 GB and grows 40 GB a day in WAL. The business can lose at most 5 minutes and be down at most 2 hours. You take a weekly base backup. Does this meet the targets? What would you change?

Write your answer down first. Then open mine.

Show my answer

RPO: with continuous archiving, a lost server costs at most the WAL segment being filled, usually well under 5 minutes. To be sure, set archive_timeout (for example 60 seconds) so a quiet database still ships a segment every minute. RPO is met.

RTO: a week of WAL is up to 280 GB to replay at the end of the week. At 150 MB/s that is over 30 minutes, plus copying 800 GB (about 35 minutes at 400 MB/s), plus checks: probably fine on day one and tight on day seven. Measure it.

What I would change: a daily base backup, or incremental backups on PostgreSQL 17, to keep the replay short; a standby for the dead-server case, so the backup is only for mistakes; and a monthly timed restore so the 2 hours is measured, not assumed.

Next · chapter 11SecurityWho can reach the data, and how← Chapter 9: Replicas
Connected

Where this shows up

The same mechanism, backups and restore, elsewhere on the site: in real incidents, in measurements, and in designs.

Check yourself · 4 questions

Check yourself

Pick an answer. You will see whether it is right, and why.

1. A developer drops a table. Your synchronous standby is perfectly in step. Does it help?

2. What sets how much data a PITR-based plan can lose?

3. Why is a logical dump a poor main backup for a 1 TB database?

4. What is the single most useful backup habit?

One database decision a weekA short email each week: one real decision, the trade-off, and the command to check it. Unsubscribe in one click.

Part 4 of 4 · Operate · 21 pagesAll pages

How do I run it in production? What to check when it is slow or broken, where it runs and what it costs, how big it must be, pooling, backups, security, upgrades and other changes made safely.