From 25890a485b20f9530f769c23af841d6a50593b37 Mon Sep 17 00:00:00 2001 From: Marcin Juszkiewicz Date: Thu, 12 Sep 2019 11:48:07 +0200 Subject: Stein: support mariabackup for backups This is a combination of 3 commits from Train. Rather than dropping xtrabackup, we are keeping it in addition to adding support for backups using mariabackup. 1. Drop Percona XtraBackup in favour of MariaDB Backup XtraBackup started failing to install on Ubuntu and does not support MariaDB 10.3 version. Related-Bug: #1843043 I9cf62c8e03a02574d85e5349df1d23a51d4c99be 2. Fix mariabackup arguments After switching from innobackupex to mariabackup [1] for database backups, the kolla_mariadb_backup.sh script was not modified to account for the difference in arguments between innobackupex and mariabackup. There is a compatibility mode, the documentation [2] for which covers some of the differences. The following have been changed: - Add explicit --backup argument, now required - Remove './' positional argument - not required with --stream - Remove --no-timestamp argument - only supported in innobackupex compatibility mode - Remove --incremental argument - implied by --incremental-history-name - Remove deprecated --compress argument, which requires qpress to be installed (it is not). The stream is now passed through gzip instead [3] [1] https://mariadb.com/kb/en/library/mariabackup-overview/ [2] https://mariadb.com/kb/en/library/mariabackup-options/#-innobackupex [3] https://mariadb.com/kb/en/library/using-encryption-and-compression-tools-with-mariabackup/ I67cff47cbf56570b8eaeb66092dd87c2769fc8a6 Closes-Bug: #1843043 (cherry picked from commit 65b27d772be32738a8508ea8e6c07f74f229cdb7) 3. Set pipefail in kolla_mariadb_backup.sh Without this, a failure in mariabackup would be ignored due to the pipe to gzip. I84536b302991e8fb04d5fa67ea266bc428437ce1 Related-Bug: #1843043 Change-Id: Idf1aed905a7d9ad461dd6fe17ed199c8d60370e6 --- docker/mariadb/Dockerfile.j2 | 3 +++ docker/mariadb/backup.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 docker/mariadb/backup.sh (limited to 'docker') diff --git a/docker/mariadb/Dockerfile.j2 b/docker/mariadb/Dockerfile.j2 index 4e2f57f48..1ee875222 100644 --- a/docker/mariadb/Dockerfile.j2 +++ b/docker/mariadb/Dockerfile.j2 @@ -52,6 +52,9 @@ RUN chmod 755 /usr/local/bin/kolla_extend_start \ RUN mkdir -p /var/run/mysqld && chown mysql /var/run/mysqld && chmod 755 /var/run/mysqld {% endif %} +COPY backup.sh /usr/local/bin/kolla_mariadb_backup.sh +RUN chmod 755 /usr/local/bin/kolla_mariadb_backup.sh + {% if use_dumb_init %} {% block mariadb_entrypoint %} # NOTE(mgoddard): Override the dumb-init arguments to avoid passing diff --git a/docker/mariadb/backup.sh b/docker/mariadb/backup.sh new file mode 100644 index 000000000..e56450171 --- /dev/null +++ b/docker/mariadb/backup.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +set -eu +set -o pipefail + +# Execute a full backup +backup_full() { + echo "Taking a full backup" + mariabackup \ + --defaults-file=/etc/mysql/my.cnf \ + --backup \ + --stream=xbstream \ + --history=$(date +%d-%m-%Y) | gzip > \ + $BACKUP_DIR/mysqlbackup-$(date +%d-%m-%Y-%s).qp.xbc.xbs.gz +} + +# Execute an incremental backup +backup_incremental() { + echo "Taking an incremental backup" + mariabackup \ + --defaults-file=/etc/mysql/my.cnf \ + --backup \ + --stream=xbstream \ + --incremental-history-name=$(date +%d-%m-%Y) \ + --history=$(date +%d-%m-%Y) | gzip > \ + $BACKUP_DIR/incremental-$(date +%H)-mysqlbackup-$(date +%d-%m-%Y-%s).qp.xbc.xbs.gz +} + +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 -- cgit v1.2.3