XtraBackup Manager

MySQL backups on Percona XtraBackup: full and incremental, compressed with zstd, with a restore command and a verify step that restores a copy into a throwaway container to prove it works.

Floors
B3archiveB3plant room
Stack
Percona XtraBackup, MySQL, Bash, zstd, Docker
Runs on
Docker, against MySQL in a container or on the host

What it is

A command-line tool I built that takes MySQL backups with Percona XtraBackup and keeps them honest. It takes full backups and incrementals, compresses them with zstd, restores them, and can prove a backup works by restoring a copy into a throwaway MySQL container and querying it.

The problem

Most backup setups are a cron job and a hope. They run every night, they exit cleanly, and nobody finds out whether they work until the day they're needed.

A big MySQL database adds a second problem. A logical dump reads every row back out through the server, and on enough data that takes longer than the night it's meant to fit in. XtraBackup copies the data files instead, but it has its own rules: it has to match the server's version, and its backups have to be prepared before they can be restored.

What I built

  • Full backups, and incrementals taken against the latest full
  • zstd compression in parallel, and a metadata file that records every backup's type, base and log position
  • A restore that decompresses, prepares and puts the files back, for MySQL in Docker Compose or on the host
  • A verify step that checks the files and the log positions, prepares a copy, restores it into a throwaway MySQL container and runs your own SQL checks against it
  • Checks before anything runs, like refusing a server whose MySQL is older than the XtraBackup version in use

The interesting parts

Incrementals against the full

Every incremental is taken against the latest full backup, not against the incremental before it. Each one grows a little through the week, but a restore only ever needs two pieces, the full and one incremental, and losing one incremental doesn't take the others with it.

Proving it restores

A backup that exists isn't a backup that works. The verify step prepares a copy, restores it into a fresh MySQL container on its own network, waits for it to answer, then runs the checks written for that project, the kind of queries that have to come back true before anyone calls the backup good.

The same tool, wherever MySQL lives

XtraBackup has to match the MySQL it reads, so the tool always runs it from a pinned Docker image. Against a MySQL container it borrows that container's volumes and network. Against MySQL on the host it mounts the data directory read-only. Either way the XtraBackup version is the one in the image, not whatever happens to be installed on the server.

Ring the bell

Want something like this built, or one of these explained? The intercom is downstairs.

Get in touch