DEV Community

Cover image for Database Backups: Logical Dumps, Snapshots, PITR and Restores That Work
Abdeldjalil Chougui
Abdeldjalil Chougui

Posted on Originally published at abdeldjalilchougui.biz

Database Backups: Logical Dumps, Snapshots, PITR and Restores That Work

Someone runs DELETE FROM orders without a WHERE at 14:32. Or a migration drops the wrong column. Or the disk dies. In each case, the question is the same: how far back can you go, and how long will it take to get there?

Two numbers frame every backup plan:

  • RPO (Recovery Point Objective): how much data you can afford to lose, measured in time. "At most 5 minutes of orders."
  • RTO (Recovery Time Objective): how long you can afford to be down while restoring. "Back online within 1 hour."

Each backup method gives a different answer to these two questions.

Logical backups (dumps)

A logical backup exports the database as SQL statements or a portable format: CREATE TABLE ..., then the data. Tools: pg_dump for PostgreSQL, mysqldump (or mysqlpump, mydumper) for MySQL.

pg_dump -Fc -d shop -f shop-2026-11-24.dump      # custom format, compressed
pg_restore -d shop_restored shop-2026-11-24.dump
Enter fullscreen mode Exit fullscreen mode

Strengths:

  • Portable across versions, operating systems and sometimes even databases.
  • You can restore one table or one schema from it.
  • Easy to understand and to store.

Limits:

  • It captures one moment. If you dump at 02:00 and the accident happens at 14:32, you lose 12 hours: RPO is the time since the last dump.
  • Restoring means replaying all inserts and rebuilding every index. For a large database this takes hours: a high RTO.
  • Dumping a big database adds load while it runs.

Good for small to medium databases, for moving data between environments, and as a second, independent copy.

Physical backups

A physical backup copies the database's actual data files. In PostgreSQL that is pg_basebackup; for MySQL, tools such as Percona XtraBackup. Restoring means putting the files back and starting the server, which is much faster than replaying SQL for large databases.

Physical backups are tied to the database version and platform, and restore the whole cluster, not one table. They are also the base for point-in-time recovery.

Snapshots

A snapshot is a copy of the whole disk volume at one instant, made by the storage layer: a cloud disk snapshot (AWS EBS, Google Persistent Disk), a filesystem snapshot (ZFS, LVM), or a managed database's automated snapshot.

Snapshots are fast to take, because most systems use copy-on-write: they record which blocks change after the snapshot instead of copying everything at once. Restoring creates a new volume from the snapshot, and the database starts from there.

Two cautions:

  • Consistency. A snapshot of a running database captures the files mid-write. Databases with a write-ahead log can usually recover from that like from a power cut (crash-consistent), but only if all files, including the log, are on the same snapshot taken at the same instant. Managed services handle this for you; with your own servers, read your database's documentation on snapshot backups.
  • Same place, same failure. A snapshot in the same account and region as the database does not protect you from an account compromise or a regional problem. Copy important snapshots elsewhere.

Point-in-time recovery (PITR)

PITR lets you restore the database to any moment, for example 14:31:59, one second before the bad DELETE. It combines two things:

  1. A base backup: a physical backup or snapshot taken regularly, say every night.
  2. A continuous archive of the transaction log: every change since the base backup. In PostgreSQL this is WAL archiving; in MySQL the binary log.

To restore:

  1. Restore the latest base backup taken before the target time.
  2. Replay the archived log from that point forward.
  3. Stop replaying at the target time (in PostgreSQL, recovery_target_time).

Your RPO becomes as small as the delay in archiving the log, often seconds to minutes. RTO depends on the base backup size plus how much log there is to replay, which is a good reason to take base backups often enough.

Most managed databases (Amazon RDS, Cloud SQL, Azure Database and others) offer PITR within a retention window you configure. On your own servers, tools such as pgBackRest, Barman or WAL-G for PostgreSQL manage base backups and log archives together.

Replicas are not backups

A replica copies every change from the primary within seconds. That includes your mistakes: the DELETE FROM orders reaches the replica almost immediately. Replicas protect against a server failing (availability). Backups protect against data being destroyed or corrupted (recovery). You need both.

The 3-2-1 rule

A widely used rule of thumb for any important data:

  • 3 copies of the data,
  • on 2 different types of storage or systems,
  • with 1 copy off-site (another region, another provider, another account).

Add to that: protect at least one copy from deletion by the same credentials that run production, for example with object lock or a separate account. Ransomware and compromised keys go after backups too.

Restores: the part people skip

A backup you have never restored is a hope, not a plan. Common surprises during a real restore:

  • the dump was failing silently for weeks,
  • the archive is missing a log segment, so PITR stops early,
  • nobody knows the decryption key or where it is,
  • the restore takes six hours, not the one hour everyone assumed.

What to do:

  1. Automate a restore test: on a schedule, restore the latest backup into a separate server and run a few checks (row counts, latest order date, a sample query).
  2. Measure the time. That measurement is your real RTO.
  3. Write a runbook: the exact commands, where credentials live, who decides to restore.
  4. Monitor backups: alert when a backup job fails or when the newest backup is older than expected.

Common mistakes

  • Only one kind of backup, stored next to the database.
  • Treating replication as a backup.
  • No PITR, so the best case loses a day of data.
  • Backups never restored, or restored only by one person who has since left.
  • Keeping backups forever without a retention policy, or keeping them too short to notice silent corruption.
  • Not backing up the things around the data: configuration, roles and permissions, encryption keys.

Watch the animated version: https://youtu.be/Wy6Pz5S4Gxw

In short

  • Decide your RPO and RTO first; they choose the method.
  • Logical dumps are portable and simple; physical backups and snapshots restore faster.
  • PITR (base backup plus archived transaction log) lets you rewind to just before the mistake.
  • Replicas are not backups. Follow 3-2-1, keep one copy out of reach of production credentials, and test restores regularly.

Originally published at abdeldjalilchougui.biz.

Top comments (0)