Home›Operate›Backups and restore time
Course · Stay upLesson 24 of 330 read
Decision 3 · Backup, PITR and restore time

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.

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.

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?

Part 4 of 4 · Operate · 15 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.