Back up every MySQL database separately, skipping system schemas.
IntermediateScenarioScenarios: backups, log rotation and housekeeping
Answer
Situation read → Separate dumps allow restoring one database without the others.
What I'd do →
set -Eeuo pipefail
mapfile -t dbs < <(mysql --defaults-extra-file=/etc/mysql/backup.cnf -NBe 'SHOW DATABASES' |
grep -Ev '^(information_schema|performance_schema|mysql|sys)$')
for db in "${dbs[@]}"; do
mysqldump --defaults-extra-file=/etc/mysql/backup.cnf --single-transaction --routines --triggers -- "$db" |
gzip > "/var/backups/mysql/${db}-$(date -u +%Y%m%dT%H%M%SZ).sql.gz"
done
- Credentials in a
0600option file, not on the command line. --single-transactiongives a consistent snapshot for InnoDB without locking tables.-NBgives raw output without headers or boxes.
Why → Per-database dumps make partial restores fast, and pipefail catches a failing mysqldump.
Interview tip → Mention that logical dumps are slow for very large databases; physical tools (Percona XtraBackup) or managed snapshots fit better there.
More on Scenarios: backups, log rotation and housekeeping
Design a nightly backup of `/etc` and application data to S3 with retention.IntermediateWrite the core of a Postgres backup that streams `pg_dump` through gzip to S3 and never uploads an empty dump.IntermediateBackups have "succeeded" every night for a year, but the first real restore failed. How do you make backups trustworthy?Advanced`/var` is 100% full because an app's logs were never rotated, and the app now fails to start. What do you do now, and what do you set up after?BeginnerShould you use `copytruncate` or a `postrotate` signal for an application's logs? How do you decide?Intermediate`/srv/app/releases` has 300 old release directories. Write a cleanup that keeps the newest 5 and never deletes the current release.Beginner