This script automates the backup and restore processes for MySQL Galera (XtraDB) Clusters using Percona's XtraBackup. It provides functionality for full backups, incremental backups, backup preparation, restoration, and backup rotation.
- Full backups
- Incremental backups
- Backup preparation for restoration
- Backup restoration
- Backup rotation
- Configurable settings via a configuration file
- Logging with rotation
- Python 3.13 or higher
- Percona XtraBackup
- MySQL Galera Cluster or Percona XtraDB Cluster (I've only tested XtraDB)
- Python's UV Package Manager
- Clone this repository or download the
mysqlclusterbackup.pyscript. - Install Percona XtraBackup if not already installed.
- Ensure Python's UV Package Manager is installed.
While this script uses uv, you still run it like a cli application without the 'uv run' command.
Create a configuration file named mysqlclusterbackup.cfg in the same directory as the script, or specify a custom path when running the script. The configuration file should have the following structure:
[MYSQL_CLUSTER_BACKUP]
MYSQL_DATA: /data/mysql
BACKUP_ROOT_PATH: /data/backup
NOTIFICATION_EMAIL: your.email@example.com
NOTIFICATION_FROM: backup.system@example.com
SMTP_SERVER: smtp.example.com
XTRABACKUP_PATH: /usr/bin/xtrabackup
LOGS_DIRECTORY: /data/mysqlclusterbackup/logs
[MYSQL_CLUSTER_BACKUP_ROTATION]
BEGINNING_OF_WEEK: 0
YEARLY_BACKUP_DATE: 1
WEEKLY_BACKUP_COUNT: 4
MONTHLY_BACKUP_COUNT: 6
YEARLY_BACKUP_COUNT: 1