Lesson 6 of 9 · 26m
Backups, Restores, and Point-in-Time Recovery
Logical versus physical backups, mysqldump, mariabackup and XtraBackup, binary logs, restore rehearsal, and the recovery math that matters.
A backup is not a file. A backup is a successful restore you have rehearsed recently enough to trust. Everything else is a hopeful artifact occupying disk. The two questions that matter are recovery point objective — how much committed data you can lose — and recovery time objective — how long you can be down while bringing it back.
Logical backups are portable and slow to restore
mysqldump emits SQL. It is great for small databases, selective restores, migrations, and inspection. It is usually the wrong primary mechanism for a multi-terabyte hot database because restore means replaying every row and rebuilding every index.
mysqldump --single-transaction --routines --events --triggers --set-gtid-purged=OFF appdb > appdb-2026-11-29.sql--single-transaction gives a consistent InnoDB snapshot without locking the whole database. MySQL 8.0.26+ calls the position option --source-data; older MySQL and MariaDB commonly use --master-data. Know which dialect your installed client speaks before writing backup scripts around it.
Physical backups copy the data files safely
Physical tools understand InnoDB redo and copy files while the server is running. For MariaDB, use mariabackup. For MySQL, Percona XtraBackup is the mature open-source option.
mariabackup --backup --user=backup --password='another-long-random-password' --target-dir=/backups/maria/2026-11-29-full
mariabackup --prepare --target-dir=/backups/maria/2026-11-29-fullPreparation applies redo so the copied tablespaces become a consistent database. A copied-but-unprepared directory is not a finished restore artifact. Encrypt backups at rest and restrict the backup account to the minimum server and filesystem access it needs.
Binary logs turn a full backup into time travel
A full backup gets you to backup time. Binary logs let you replay forward to just before the mistake.
mysqlbinlog --start-datetime='2026-11-29 18:00:00' --stop-datetime='2026-11-29 18:42:00' binlog.000431 binlog.000432 | mysql -h restore-db appdbThis is the heart of point-in-time recovery after DROP TABLE, bad deploys, and runaway updates. Preserve binary logs beyond your full-backup cadence. In MySQL 8 use binlog_expire_logs_seconds; check MariaDB's corresponding expiration variables for your version.
Test recovery as a procedure, not a vibe
Run regular drills: provision a scratch host, restore the full backup, apply binary logs, run application smoke checks, and time every step. Document exact commands and storage layout. During a real incident you should be executing a checklist, not rediscovering flags.
RPO 5 minutes: binlogs retained continuously, full backup daily
RTO 1 hour: restore hardware already available, rehearsed procedure under 30 minutesIf restore takes six hours and the business can tolerate one, the backup system is decorative.
Field notes
- A replica is not a backup. It faithfully replicates
DROP TABLEtoo. - Store backups off-machine and off-account where possible; ransomware and operator error should not be able to delete primary and backup in the same blast radius.
- Include users, grants, triggers, events, routines, and server configuration in your recovery plan.
- Backups of encrypted or compressed data need the keys and tooling preserved just as carefully as the bytes.
Was this lesson helpful?