Skip to content

XtraBackup — online physical backups of MySQL/MariaDB

Hot, consistent physical backups of MySQL and MariaDB using Percona XtraBackup or MariaDB Backup — full, incremental, restore, and the operational discipline behind it.

mysqldump is fine for small schemas and one-off exports; it does not scale to multi-terabyte production databases that cannot tolerate a multi-hour read lock. Percona XtraBackup (and its MariaDB sibling, mariabackup) takes a physical copy of the InnoDB files while the server is running, replaying the redo log to produce a consistent snapshot. This article is the production backup procedure we run — full backup, incremental, restore — and the operational notes that decide whether the backup is actually restorable.

How to verify

A backup is only as good as the restore. Before trusting any backup pipeline, confirm the tool is present, the version matches the server, and the destination is reachable.

xtrabackup --version
mariabackup --version
df -h /backup
mysql -e "SHOW VARIABLES LIKE 'innodb_log_file_size';"
mysql -e "SELECT user, host FROM mysql.user WHERE user='backup';"

For MariaDB, use mariabackup — Percona XtraBackup has lagged behind MariaDB’s InnoDB internals for several releases and silently produces broken backups on newer MariaDB versions. For MySQL 8.x, use Percona XtraBackup 8.x. Match the tool to the server.

What’s happening

XtraBackup works by copying the InnoDB data files (.ibd, ibdata1, undo logs) while continuously tailing the redo log. Once the data file copy finishes, it captures the redo log position; the resulting snapshot is “inconsistent” — committed transactions that landed during the copy are partially reflected, in-progress ones may be torn.

The “prepare” phase fixes this. xtrabackup --prepare replays committed redo against the data files and rolls back uncommitted transactions, producing a consistent point-in-time snapshot at the LSN where the redo log was captured. After prepare, the data directory is identical (modulo the binary log position) to what mysqld would have on disk if you had cleanly stopped it at that LSN.

For incremental backups, XtraBackup writes only the pages that changed since a base LSN. The base can be a previous full backup or a previous incremental. To restore, prepare the base, then prepare each incremental in order with --apply-log-only on all but the last — that flag tells prepare not to roll back uncommitted transactions, because a later incremental may complete them.

The non-InnoDB pieces — MyISAM, the mysql.* system tables before MySQL 8, the schema definitions — are copied with a short FLUSH TABLES WITH READ LOCK at the end. This is the only window during which the server is briefly read-only. On modern InnoDB-only schemas the lock is sub-second.

The procedure

  1. Create a backup user with the precise grants XtraBackup needs.

    CREATE USER 'backup'@'localhost' IDENTIFIED BY 'BACKUP_PASS';
    GRANT BACKUP_ADMIN, RELOAD, PROCESS, LOCK TABLES, REPLICATION CLIENT
      ON *.* TO 'backup'@'localhost';
    GRANT SELECT ON performance_schema.* TO 'backup'@'localhost';
  2. Take a full backup to a fresh directory. The --target-dir must be empty.

    sudo mkdir -p /backup/$(date +%F)/full
    sudo xtrabackup --backup \
      --user=backup --password=BACKUP_PASS \
      --target-dir=/backup/$(date +%F)/full \
      --datadir=/var/lib/mysql

    Watch for completed OK! at the end of stdout. Anything else is a failed backup — do not put it in rotation.

  3. Take an incremental against the full backup later in the day.

    sudo xtrabackup --backup \
      --user=backup --password=BACKUP_PASS \
      --target-dir=/backup/$(date +%F)/inc1 \
      --incremental-basedir=/backup/$(date +%F)/full \
      --datadir=/var/lib/mysql
  4. To restore, prepare the chain. The base gets --apply-log-only; each incremental gets --apply-log-only except the last; the final prepare drops the flag so InnoDB rolls back uncommitted transactions.

    sudo xtrabackup --prepare --apply-log-only --target-dir=/backup/2026-06-02/full
    sudo xtrabackup --prepare --apply-log-only \
      --target-dir=/backup/2026-06-02/full \
      --incremental-dir=/backup/2026-06-02/inc1
    sudo xtrabackup --prepare --target-dir=/backup/2026-06-02/full
  5. Stop MySQL, move the prepared directory into place, set ownership, and start it.

    sudo systemctl stop mysql
    sudo mv /var/lib/mysql /var/lib/mysql.old
    sudo xtrabackup --copy-back --target-dir=/backup/2026-06-02/full --datadir=/var/lib/mysql
    sudo chown -R mysql:mysql /var/lib/mysql
    sudo systemctl start mysql
    mysql -e "SELECT @@version, NOW();"
  6. For replication restore, read xtrabackup_binlog_info in the prepared directory — it has the binlog file and position to feed into CHANGE MASTER TO. For GTID-based replication, xtrabackup_binlog_info contains the GTID set; use SET GLOBAL gtid_purged = ... before CHANGE MASTER TO ... MASTER_AUTO_POSITION=1.

Common pitfalls

  • xtrabackup against MariaDB 10.5+ — use mariabackup. Percona’s tool diverges from MariaDB’s InnoDB and the prepare phase will fail or, worse, produce a silently broken restore.
  • Skipping --apply-log-only on intermediate incrementals — the chain breaks; you cannot apply the next incremental on top because uncommitted transactions were already rolled back.
  • Backups to the same disk as the data directory — when the disk fills, the backup writer is what fills it. Always back up to a separate filesystem, ideally on a separate volume.
  • No restore drills — a backup that has never been restored is a hope, not a backup. We run a periodic restore drill against a scratch server and verify row counts on a sentinel table.
  • Ignoring xtrabackup_binlog_info — restoring a backup without recording the binlog position breaks point-in-time recovery; you can only restore to the snapshot, not to a later instant.

XtraBackup turns a multi-terabyte MySQL instance into something we can back up nightly without taking the application offline, and incrementally every few hours without saturating the disk. In the engagements we run, the full + incremental schedule is one piece of a backup architecture that also covers binary log shipping for point-in-time recovery, retention sweeps, and the restore drill we run before declaring the pipeline healthy. For the broader pattern of operating MySQL and MariaDB at this layer, see /en/services/managed-operations/.