Skip to content

Lesson 6 of 9 · 28m

Backup Strategies and Restore Drills That Actually Work

Compare logical and physical backups, point-in-time recovery, consistency requirements, encryption, verification, and restore rehearsal.

Backups are files until the day they are the company. I have seen teams celebrate successful backup jobs that produced unusable restores: missing binlogs, inconsistent credentials, no InnoDB redo handling, encryption keys stored beside ciphertext, and nobody aware of how long a terabyte takes to copy back. The only meaningful backup metric is whether you can restore the required state inside the required time.

Logical and physical backups solve different problems

Logical backups export schema and data as SQL or structured output. mysqldump is the classic tool:

mysqldump --single-transaction --routines --events --triggers \
  --set-gtid-purged=ON --databases appdb \
  --result-file=/backups/appdb-$(date +%Y%m%d%H%M%S).sql

--single-transaction gives InnoDB a consistent snapshot without locking the whole server, but it does not make every object magically consistent. Non-transactional tables, DDL races, huge undo growth, and extremely long snapshots still matter.

Physical backup tools copy data files while handling InnoDB redo and consistency. Percona XtraBackup is the common choice:

xtrabackup --backup --target-dir=/backups/full-20261130 --defaults-file=/etc/mysql/backup.cnf
xtrabackup --prepare --target-dir=/backups/full-20261130

Physical backups are usually faster for large databases and faster to restore because you copy files rather than replaying INSERT statements. Logical backups are portable and useful for selective restore, but restore time grows painfully with size.

Point-in-time recovery needs continuous binlogs

A nightly full backup plus retained binary logs lets you restore to a transaction boundary or just before a bad write. That means binlogs must be copied somewhere safer than the database host and retention must overlap every full backup window.

mysqlbinlog --start-datetime="2026-11-30 02:10:00" --stop-datetime="2026-11-30 02:42:00" \
  /backups/binlogs/mysql-bin.000421 > recovery-window.sql

Practice identifying the exact transaction; 'before the incident' is a forensic decision, not just a timestamp guess.

Consistency, encryption, and access control are one design

Backups contain production data. Encrypt them, restrict access, audit retrieval, and store decryption keys separately. A perfectly encrypted backup with the key in the same object store bucket is compliance theater.

gpg --batch --yes --recipient backup-prod@sudosecurity.org --encrypt /backups/appdb-20261130.sql

Document who may restore what; emergency access that requires improvising permissions is not emergency access.

Restore drills measure truth

A restore drill should capture:

time to locate backup, credentials, and target capacity
time to copy, prepare, and apply required binlogs
application compatibility and data validation checks
total recovery time and recovery point achieved

Automate validation. Count rows in sentinel tables, inspect max IDs or timestamps, run checksums where appropriate, and compare application-level invariants. A restore that boots MySQL but is missing the last six hours is not success unless that was the objective.

Backup failure is often operational, not technical

Jobs silently fail because disks fill, object-store credentials rotate, backup users lose grants, or the backup is throttled until it no longer finishes before the next one starts. Alert on absence of success, size anomalies, duration anomalies, and restore-test failure — not merely nonzero exit codes.

Field notes

  • Replication is not a backup; corruption and destructive writes replicate too.
  • Keep at least one backup copy outside the blast radius of production credentials and infrastructure.
  • Test selective restore procedures. Restoring one table from a monolithic dump can be miserable.
  • Do not store only compressed streams you have never decompressed during a drill.
  • Measure restore time at realistic scale. Small staging restores create false confidence.

Was this lesson helpful?

Sign in to rate