kolla/docker/xtrabackup/backup.sh
Nick Jones 25de6deb4b
Introduce Percona XtraBackup image
blueprint database-backup-recovery

Implements an image suitable for taking MariaDB backups via Percona's
XtraBackup tool.

Install XtraBackup from Percona's repos, ensuring that packages from
this source aren't used for any other purpose.

Include a script which invokes XtraBackup with the appropriate
options for either a full or incremental backup.

Change-Id: Ifebe2045e5815c573c0a2ae05951c428c3f06a92
2018-11-06 11:29:45 +00:00

50 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eu
# Execute a full backup
backup_full() {
echo "Taking a full backup"
innobackupex --defaults-file=/etc/mysql/my.cnf \
--no-timestamp \
--stream=xbstream \
--compress \
--history=$(date +%d-%m-%Y) ./ > \
$BACKUP_DIR/mysqlbackup-$(date +%d-%m-%Y-%s).qp.xbc.xbs
}
# Execute an incremental backup
backup_incremental() {
echo "Taking an incremental backup"
innobackupex --defaults-file=/etc/mysql/my.cnf \
--no-timestamp \
--stream=xbstream \
--compress \
--incremental \
--incremental-history-name=$(date +%d-%m-%Y) \
--history=$(date +%d-%m-%Y) ./ > \
$BACKUP_DIR/incremental-$(date +%H)-mysqlbackup-$(date +%d-%m-%Y-%s).qp.xbc.xbs
}
BACKUP_DIR=/backup/
cd $BACKUP_DIR
if [ -n $BACKUP_TYPE ]; then
case $BACKUP_TYPE in
"full")
backup_full
;;
"incremental")
backup_incremental
;;
*)
echo "Only full or incremental options are supported."
exit 1
;;
esac
else
echo "You need to specify either full or incremental backup options."
exit 1
fi