Effortless Backups for Galera Cluster with XtraBackup

John Timmer Avatar

·

·

Maintaining high availability in a Galera Cluster environment requires a robust and reliable backup solution. XtraBackup is a popular choice, offering non-blocking backups that preserve data consistency across all nodes. Whether you need a full backup for disaster recovery or incremental backups for efficient storage use, XtraBackup integrates seamlessly with Galera.

This guide walks you through the process of setting up XtraBackup for Galera, performing both full and incremental backups, and restoring data when needed.


Why Choose XtraBackup for Galera?

XtraBackup offers unique advantages for Galera clusters:

  • Non-blocking Backups: Minimize downtime by backing up live databases without halting operations.
  • Consistency: Ensures that backups align with Galera’s transactional state by capturing the Galera GTID (Global Transaction ID).
  • Incremental Backups: Save storage and time by only backing up changes since the last backup.

Preparing Your Environment

Before using XtraBackup with Galera, ensure the following prerequisites:

Galera Cluster Configuration:
Ensure your cluster is healthy, with all nodes synchronized.

Install XtraBackup:
Install the Percona XtraBackup tool on the nodes where backups will be performed.

Copied!
sudo apt-get install percona-xtrabackup-80

Permissions:
Configure the database user with the necessary privileges:

Copied!
GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT, PROCESS ON *.* TO 'backup_user'@'localhost' IDENTIFIED BY 'password';

Disk Space:
Ensure sufficient storage for full and incremental backups.


Full Backup with XtraBackup

To create a full backup, follow these steps:

Choose a Node
Select a node that is synchronized (wsrep_local_state=4) and has minimal workload.

Run the Backup Command
Use the --galera-info flag to capture Galera-specific details:

Copied!
xtrabackup --backup --target-dir=/backup/full --galera-info --user=backup_user --password=password

The --galera-info option creates the xtrabackup_galera_info file, which stores the GTID of the backup.

Validate the Backup
Check the output logs for any errors:

Copied!
cat /backup/full/xtrabackup_checkpoints

The file should indicate a completed backup.

Prepare the Backup
Preparing applies the redo logs, ensuring the backup is ready for restoration:

Copied!
xtrabackup --prepare --target-dir=/backup/full

Incremental Backups with XtraBackup

Incremental backups save time and disk space by only backing up changes since the last backup.

Create the Initial Full Backup
Start with a full backup as outlined above.

Run the Incremental Backup
Specify the directory of the previous backup:

Copied!
xtrabackup --backup --target-dir=/backup/incremental1 --incremental-basedir=/backup/full --user=backup_user --password=password

Prepare the Incremental Backup
To apply incremental changes to the full backup:

Copied!
xtrabackup --prepare --apply-log-only --target-dir=/backup/full xtrabackup --prepare --apply-log-only --target-dir=/backup/full --incremental-dir=/backup/incremental1

Repeat for Additional Incrementals
Each new incremental backup builds on the previous one

Copied!
xtrabackup --backup --target-dir=/backup/incremental2 --incremental-basedir=/backup/incremental1 --user=backup_user --password=password

Restoring a Backup

Restoration involves copying the prepared backup back to the data directory.

Stop the Database Service

Copied!
sudo systemctl stop mysql

Restore the Backup
Use the --copy-back option:

Copied!
xtrabackup --copy-back --target-dir=/backup/full

Adjust Permissions
Reset ownership of the restored files:

Copied!
sudo chown -R mysql:mysql /var/lib/mysql

Start the Database Service

Copied!
sudo systemctl start mysql

Best Practices for XtraBackup with Galera

  • Test Regularly: Validate backups by restoring them in a staging environment.
  • Automate: Use cron jobs or scripts to schedule backups.
  • Monitor Performance: Incremental backups reduce load, but ensure the process doesn’t impact cluster performance.

Common Pitfalls and Troubleshooting

Inconsistent Backups:
Always use the --galera-info flag to ensure backups are consistent.

Insufficient Disk Space:
Monitor backup directories to avoid running out of space.

Version Mismatches:
Ensure XtraBackup is compatible with your MySQL/MariaDB version.


XtraBackup is a powerful tool for managing backups in Galera Clusters, offering both full and incremental options to suit various needs. By following this guide, you can ensure your data is protected, your backups are consistent, and your restore processes are reliable. With proper automation and regular testing, XtraBackup becomes an essential part of your Galera high availability strategy.