Appearance
Hot backups with Percona XtraBackup
Perform non-locking MySQL backups without interrupting database reads or writes.
Percona XtraBackup copies InnoDB data files at the storage level while the database continues running. Unlike mysqldump, it does not acquire a global read lock, making it suitable for production databases where downtime or write delays are not acceptable.
Prerequisites
Before setting up this backup type, ensure you have:
- Percona XtraBackup installed on the server. See the Percona documentation for installation instructions.
- A
.my.cnfcredentials file readable only by the user running the backup script. - Sufficient permissions to run
xtrabackupand connect to MySQL.
Set up the backup script
- Create a
.my.cnfcredentials file and restrict its permissions:
plain
[client]
user=root
password=yourpasswordbash
chmod 600 ~/.my.cnf- Create a backup script — for example
backup_script.sh:
bash
#!/bin/bash
BACKUP_DIR=/mnt/hot-backups
DATABASE=mydatabase
CONFIG=~/.my.cnf
mkdir -p ${BACKUP_DIR}
xtrabackup --backup \
--defaults-file=${CONFIG} \
--databases=${DATABASE} \
--target-dir=${BACKUP_DIR}/${DATABASE}_$(date +%Y%m%d%H%M%S)
exit $?Replace mydatabase with your database name. If your .my.cnf is stored elsewhere, update the CONFIG path accordingly.
- Make the script executable:
bash
chmod +x backup_script.sh- Run the script to verify it completes without errors:
bash
./backup_script.shA successful run outputs a timestamped directory under BACKUP_DIR containing the backup files. In SimpleBackups, use Custom Script as the backup type and point it to this script to automate the process on a schedule.