We use the Puppet code for deploying MariaDB. Those are the backup options.
mysql::backup::mysqldump: Implements mysqldump backups.
mysql::backup::mysqlbackup: Implements backups with Oracle MySQL
Enterprise Backup.- mysql::backup::xtrabackup: Implements backups with XtraBackup from Percona.
We don't own MySQL Enterprise Backup licenses.
Here the backup script. The big problem at the moment, we don't notice when backup is failing.
#!/bin/bash
#
# MySQL Backup Script
# Dumps mysql databases to a file for another backup tool to pick up.
#
# MySQL code:
# GRANT SELECT, RELOAD, LOCK TABLES ON *.* TO 'user'@'localhost'
# IDENTIFIED BY 'password';
# FLUSH PRIVILEGES;
#
##### START CONFIG ###################################################
USER=backup
DIR=/var/lib/mysql/backup
ROTATE=6
# Use a pwd file. See https://dev.mysql.com/doc/refman/5.1/en/password-security-user.html
PWD_FILE=$(mktemp ${DIR}/backup.cnf.XXXX)
echo "
[client]
password=sirugrwiuwiuwguisrkogos
" >> $PWD_FILE
PREFIX=mysql_backup_
ADDITIONAL_OPTIONS="--ignore-table=mysql.event"
##### STOP CONFIG ####################################################
PATH=/usr/bin:/usr/sbin:/bin:/sbin
set -o pipefail
cleanup()
{
find "${DIR}/" -maxdepth 1 -type f -name "${PREFIX}*.sql*" -mtime +${ROTATE} -print0 | xargs -0 -r rm -f
}
mysqldump --defaults-file=${PWD_FILE} -u${USER} --opt --flush-logs --single-transaction \
${ADDITIONAL_OPTIONS} \
--all-databases | bzcat -zc > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql.bz2
if [ $? -eq 0 ] ; then
cleanup
fi
rm -rf $PWD_FILE
backup time
# time /usr/local/sbin/mysqlbackup.sh
real 21m35.647s
user 20m47.059s
sys 0m7.843s
backup size
# du -sh mysql_backup_20160223-123920.sql
4.9G mysql_backup_20160223-123920.sql
Is it in our use case better to use xtrabackup
? When to use xtrabackup
?