Database Backups and Restores

Choose backup methods, schedules and retention that meet your RPO, and prove them by restoring regularly.

Intermediate · about 5 hours · difficulty 3/5

Learn first: Capacity Planning, High Availability and Disaster Recovery

Nobody wants backups; everybody wants restores. A backup you have never restored is an assumption. This topic makes sure your data can come back.

Backup types

  • Logical dumps (pg_dump, mysqldump, mongodump): portable, table-level restores, slow on large databases.
  • Physical backups (pg_basebackup, Percona XtraBackup, storage snapshots): fast full copies of data files.
  • Point-in-time recovery (PITR): a base backup plus continuous WAL or binlog archiving lets you restore to any second, which is how you recover from "someone ran DELETE without WHERE at 14:03".
  • Managed services (RDS, Cloud SQL, Azure Database) automate snapshots and PITR within a retention window; you still own cross-region copies and restore testing.

A sound backup policy

  • Match frequency and PITR to the RPO agreed with the business.
  • Follow 3-2-1: three copies, two media or services, one off-site. In cloud terms, another region and ideally another account.
  • Encrypt backups and restrict who can delete them; use immutable or object-locked storage against ransomware and mistakes.
  • Keep retention for compliance and cost, with lifecycle rules to cheaper tiers.

Restore drills

Automate a scheduled restore into a scratch environment, run sanity queries (row counts, latest timestamps), and record how long it took. That duration is your real RTO. Tools such as pgBackRest, WAL-G and Velero (for Kubernetes volumes) help automate both sides.

Good enough to move on: you can configure PITR for Postgres, restore to a specific timestamp into a new instance, and run a scheduled restore test that reports its duration.

Key concepts

  • Logical vs physical backups
  • Point-in-time recovery with WAL/binlog
  • Managed database snapshots
  • 3-2-1 rule and cross-region copies
  • Immutable and encrypted backups
  • Automated restore drills
  • pgBackRest, WAL-G and Velero

Mini project

Run Postgres with WAL archiving to object storage, insert data, simulate an accidental delete, restore to the second before it into a new instance, and script the whole drill so it runs weekly.

Check yourself

Nightly snapshots are taken at 02:00. A bad migration corrupts data at 16:00. How much data do you lose without PITR, and how does PITR change that?

Free resources