DBAtlas · Atlas für Datenbankbetrieb

Physisches Voll- + inkrementelles Backup und Restore mit XtraBackup

MySQLBackup & PITR

Befehl

# Full backup
xtrabackup --backup --host=127.0.0.1 --user=bkp --password='Bkp#2024' --target-dir=/backup/full --parallel=4
# Incremental (based on the previous backup)
xtrabackup --backup --host=127.0.0.1 --user=bkp --password='Bkp#2024' --target-dir=/backup/inc1 --incremental-basedir=/backup/full

# Prepare: full and intermediate incrementals with --apply-log-only, final step without it
xtrabackup --prepare --apply-log-only --target-dir=/backup/full
xtrabackup --prepare --apply-log-only --target-dir=/backup/full --incremental-dir=/backup/inc1
xtrabackup --prepare --target-dir=/backup/full

# Restore: mysqld stopped and datadir empty
systemctl stop mysqld
xtrabackup --copy-back --target-dir=/backup/full --datadir=/var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
systemctl start mysqld
cat /backup/full/xtrabackup_binlog_info

Was es tut

Erstellt ein physisches Hot Backup, indem InnoDB-Dateien und das Redo-Log bei laufendem Server kopiert werden; ein inkrementelles Backup enthält nur seit dem vorherigen Backup geänderte Seiten. Der Prepare-Schritt wendet Redo an und macht das Backup konsistent.

Wann einsetzen

Für große Datenbanken, die schnelle Restores brauchen (um ein Vielfaches schneller als logisch), zum Initialisieren von Replicas und für Strategien mit täglichem Voll- + stündlichem inkrementellem Backup.

Vorsicht

Die XtraBackup-Version muss zur Release-Serie des Servers passen (Server 8.0 → XtraBackup 8.0, 8.4 → 8.4); nutzt der Server ein neueres Redo-/Data-Dictionary-Format als der XtraBackup-Build, wird das Backup verweigert. Ein nicht vorbereitetes Backup ist inkonsistent. Wird --apply-log-only bei Zwischenschritten vergessen, sind spätere Inkremente unbrauchbar. Das datadir muss für den Restore leer sein; --move-back spart Platz, verbraucht aber das Backup. Backup-Benutzer: BACKUP_ADMIN, PROCESS, RELOAD, LOCK TABLES, REPLICATION CLIENT sowie SELECT auf performance_schema.log_status, keyring_component_status, replication_group_members.

In DBAtlas öffnen →

Verwandte Einträge