Skip to content
Navigation

Type at least two characters. Search covers page titles, headings, tags and database names.

↑ ↓ to navigateEnter to openEsc to close0 pages
MariaDBintermediate

MariaDB Backup and Restore

Physical backups with mariabackup, logical dumps, and restoring into a Galera cluster.

2 min readIntermediateUpdated Edit this page

MariaDB's physical backup tool is mariabackup, a fork of Percona XtraBackup adapted to MariaDB's InnoDB variant.

Physical backup

mariabackup --backup \
  --target-dir=/backups/base \
  --user=backup --password=… \
  --parallel=4
 
# Prepare makes the copy consistent. Required before any restore.
mariabackup --prepare --target-dir=/backups/base
 
# Incremental against a previous backup.
mariabackup --backup --target-dir=/backups/inc1 \
            --incremental-basedir=/backups/base

Restore into a stopped server with an empty data directory:

systemctl stop mariadb
rm -rf /var/lib/mysql/*
mariabackup --copy-back --target-dir=/backups/base
chown -R mysql:mysql /var/lib/mysql
systemctl start mariadb

Logical backup

mariadb-dump --single-transaction --master-data=2 \
             --routines --events --triggers \
             --databases shop | zstd -T0 > /backups/shop.sql.zst

--master-data=2 records the binlog coordinates as a comment, which is what a point-in-time recovery or a new replica needs.

Point-in-time recovery

Restore the last physical backup, then replay binlogs from its recorded position:

mariadb-binlog --start-position=1234 \
               --stop-datetime="2026-07-30 14:22:00" \
               mariadb-bin.000042 > /tmp/replay.sql
mariadb < /tmp/replay.sql

With GTIDs, --start-position accepts a GTID, which is more robust than a file offset across a failover.

Restoring into a Galera cluster

Procedure:

  1. Stop all nodes.
  2. Restore and prepare the backup on the intended bootstrap node.
  3. Remove grastate.dat on that node so it starts a fresh cluster state, or set safe_to_bootstrap appropriately.
  4. Start it with galera_new_cluster.
  5. Start remaining nodes; they take an SST from the bootstrap node.
  6. Verify wsrep_cluster_size matches the expected node count and every node reports Synced.

Verification

Restore into an isolated instance on a schedule, check row counts and one business invariant, and record the elapsed time against the recovery time objective. See Restore Testing.