-
Assess the current backup situation by checking existing backup configurations. For PostgreSQL: verify archive_mode, archive_command, and wal_level in postgresql.conf. For MySQL: check if binary logging is enabled with SHOW VARIABLES LIKE 'log_bin'.
-
Define RPO and RTO targets based on business requirements:
- RPO (acceptable data loss): determines backup frequency and WAL archiving interval
- RTO (acceptable downtime): determines backup type and recovery procedure complexity
- Typical targets: RPO < 1 hour (WAL archiving), RTO < 30 minutes (physical backup restore)
-
Configure WAL archiving for PostgreSQL PITR:
- Set
wal_level = replica and archive_mode = on
- Configure
archive_command = 'test ! -f /archive/%f && cp %p /archive/%f' (or use pgBackRest/WAL-G for S3)
- Verify archiving works:
SELECT * FROM pg_stat_archiver
- For MySQL, enable binary logging:
log_bin = mysql-bin, binlog_format = ROW
-
Create a full physical backup using pg_basebackup -D /backups/base -Ft -z -P (PostgreSQL) or xtrabackup --backup --target-dir=/backups/full (MySQL). Physical backups are faster to restore than logical backups for databases larger than 10GB.
-
Create logical backups for portability and selective restoration: pg_dump -Fc -f database.dump dbname (PostgreSQL) or mysqldump --single-transaction --routines --triggers dbname > database.sql (MySQL).
-
Upload backups to remote storage for disaster recovery: aws s3 cp /backups/base.tar.gz s3://backup-bucket/postgres/$(date +%Y%m%d)/ with server-side encryption enabled. Implement a retention policy (e.g., daily backups for 30 days, weekly for 90 days, monthly for 1 year).
-
Test recovery by restoring to a separate server or container:
- Restore physical backup:
pg_restore -d testdb database.dump or untar base backup and start PostgreSQL
- For PITR: restore base backup, copy WAL files to
pg_wal, create recovery.signal with recovery_target_time = '2024-01-15 14:30:00'
- Verify data integrity by running application test suite against restored database
- Measure actual recovery time to validate RTO target
-
Automate backup verification with a daily cron job that: takes backup, restores to a test instance, runs integrity checks (pg_catalog.pg_class row counts, checksum verification), and sends a success/failure notification.
-
Document the recovery runbook with exact commands for each recovery scenario: full database restore, PITR to a specific timestamp, single table restore, and cross-region failover.
-
Schedule monthly disaster recovery drills to verify the runbook works and the team can execute recovery within RTO targets.