Managing Database Backup and Recovery

1. Understanding Backup Types

TypeDescription
FullComplete copy of all data
DifferentialChanges since last full
IncrementalChanges since last backup (any)
LogicalSQL dump (pg_dump, mysqldump)
PhysicalBinary files (pg_basebackup, percona xtrabackup)
Continuous (WAL)Stream WAL for PITR
SnapshotStorage-level (EBS, ZFS) — must be crash-consistent

2. Creating Database Backups

DBCommand
Postgres logicalpg_dump -Fc db > db.dump
Postgres physicalpg_basebackup -D /backup -Fp -X stream
MySQL logicalmysqldump --single-transaction db > db.sql
MySQL physicalxtrabackup --backup --target-dir=/bkp
SQL ServerBACKUP DATABASE db TO DISK='...'
OracleRMAN BACKUP DATABASE PLUS ARCHIVELOG

3. Scheduling Automated Backups

ToolDetail
cronSimple periodic jobs
pgBackRest / BarmanPostgres orchestrators with retention
AWS Backup / RDS automatedManaged retention + PITR
Ansible / TerraformInfra-as-code for backup policy
3-2-1 rule3 copies, 2 media, 1 offsite

4. Implementing Point-in-Time Recovery

RequirementDetail
Base backupRecent full physical backup
WAL archiveContinuous archiving (archive_mode=on)
Recovery targetrecovery_target_time, _xid, or _lsn
RPODetermined by WAL ship frequency
RTORestore + replay time

5. Restoring Databases from Backups

Restore Procedure

  1. Stop application traffic / fence the cluster
  2. Restore base backup to fresh instance
  3. Configure recovery target (time/LSN)
  4. Replay WAL up to target
  5. Promote to read/write
  6. Validate data; redirect traffic
DBRestore
Postgres logicalpg_restore -d db db.dump
MySQL logicalmysql db < db.sql
SQL ServerRESTORE DATABASE FROM DISK='...' WITH NORECOVERY

6. Testing Backup and Restore Procedures

PracticeDetail
Automated restore drillWeekly to disposable env
Verify checksumspg_verifybackup, RMAN VALIDATE
Smoke tests post-restoreRow counts, key queries
Documented runbookStep-by-step including auth
Game daysSimulate full DR scenarios
Warning: "A backup you haven't restored isn't a backup." Test recovery on a real schedule.

7. Managing Backup Storage and Retention

AspectDetail
Retention tiersDaily 7d, weekly 4w, monthly 12m
Immutable storageS3 Object Lock — ransomware defense
EncryptionAt rest with KMS-managed keys
Compressionzstd, parallel gzip
Geographic redundancyCross-region replication

8. Implementing Hot vs Cold Backups

TypeDescription
Hot (online)DB running during backup; uses MVCC + WAL
WarmRead-only mode during backup
ColdDB stopped (consistent file copy)
RecommendationHot for OLTP (zero downtime)

9. Handling Database Corruption Recovery

ToolDB
pg_amcheck, pg_dump --tablePostgres
CHECKSUM TABLE / innochecksumMySQL
DBCC CHECKDBSQL Server
RMAN VALIDATE / Data Recovery AdvisorOracle
Page-level restoreRestore individual corrupted page from backup

10. Documenting Recovery Procedures

DocContents
RunbookExact commands, paths, credentials source
RTO/RPO targetsPer database / tier
Decision treeWhich backup, which target time
Validation stepsPost-restore checks
ContactsOn-call, vendor support, escalation