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
This commit is contained in:
Nick Jones 2018-03-09 17:27:00 +00:00 committed by Nick Jones
parent 8aac00972d
commit 25de6deb4b
No known key found for this signature in database
GPG Key ID: F6D24C8669938334
8 changed files with 107 additions and 3 deletions

View File

@ -63,15 +63,17 @@ COPY yum.conf /etc/yum.conf
'influxdb.repo', 'influxdb.repo',
'nfs_ganesha.repo', 'nfs_ganesha.repo',
'opendaylight.repo', 'opendaylight.repo',
'td.repo', 'percona-release.repo',
'rabbitmq_rabbitmq-server.repo' 'rabbitmq_rabbitmq-server.repo',
'td.repo'
] %} ] %}
{% set base_yum_repo_keys = [ {% set base_yum_repo_keys = [
'https://artifacts.elastic.co/GPG-KEY-elasticsearch', 'https://artifacts.elastic.co/GPG-KEY-elasticsearch',
'https://grafanarel.s3.amazonaws.com/RPM-GPG-KEY-grafana',
'https://repos.influxdata.com/influxdb.key', 'https://repos.influxdata.com/influxdb.key',
'https://packagecloud.io/gpg.key', 'https://packagecloud.io/gpg.key',
'https://grafanarel.s3.amazonaws.com/RPM-GPG-KEY-grafana', 'https://www.percona.com/downloads/RPM-GPG-KEY-percona',
'https://packages.treasuredata.com/GPG-KEY-td-agent' 'https://packages.treasuredata.com/GPG-KEY-td-agent'
] %} ] %}
{% endif %} {% endif %}

View File

@ -0,0 +1,4 @@
# Lower the priority of packages from Percona's repos
Package: *
Pin: origin repo.percona.com
Pin-Priority: 100

View File

@ -2,3 +2,8 @@
Package: ceph* *cephfs* librbd* *rados* python-rbd librgw* Package: ceph* *cephfs* librbd* *rados* python-rbd librgw*
Pin: version 13.* Pin: version 13.*
Pin-Priority: -1 Pin-Priority: -1
# Lower the priority of packages from Percona's repos
Package: *
Pin: origin repo.percona.com
Pin-Priority: 100

View File

@ -0,0 +1,13 @@
[percona-release-$basearch]
name = Percona-Release YUM repository - $basearch
baseurl = http://repo.percona.com/release/$releasever/RPMS/$basearch
enabled = 0
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Percona
[percona-release-noarch]
name = Percona-Release YUM repository - noarch
baseurl = http://repo.percona.com/release/$releasever/RPMS/noarch
enabled = 0
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Percona

View File

@ -15,3 +15,7 @@ deb [arch=amd64] https://artifacts.elastic.co/packages/5.x/apt stable main
# main docker repo # main docker repo
deb https://download.docker.com/linux/debian stretch stable deb https://download.docker.com/linux/debian stretch stable
# Percona XtraBackup repo
deb http://repo.percona.com/apt stretch main

View File

@ -35,3 +35,6 @@ deb http://ppa.launchpad.net/odl-team/carbon/ubuntu xenial main
# rabbitmq repo # rabbitmq repo
deb https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ xenial main deb https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ xenial main
# Percona XtraBackup repo
deb http://repo.percona.com/apt bionic main

View File

@ -0,0 +1,24 @@
FROM {{ namespace }}/{{ image_prefix }}base:{{ tag }}
LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build_date }}"
{% block xtrabackup_header %}{% endblock %}
{% import "macros.j2" as macros with context %}
{% if base_distro in ['centos', 'oraclelinux', 'rhel'] %}
RUN yum-config-manager --enable percona\*
{% endif %}
{% if base_distro in ['centos', 'oraclelinux', 'rhel', 'ubuntu', 'debian'] %}
{% set xtrabackup_packages = ['percona-xtrabackup-24', 'qpress'] %}
{% endif %}
{{ macros.install_packages(xtrabackup_packages | customizable("packages")) }}
COPY backup.sh /usr/local/bin/kolla_mariadb_backup.sh
RUN chmod 755 /usr/local/bin/kolla_mariadb_backup.sh
CMD /usr/local/bin/kolla_mariadb_backup.sh
{% block xtrabackup_footer %}{% endblock %}
{% block footer %}{% endblock %}

49
docker/xtrabackup/backup.sh Executable file
View File

@ -0,0 +1,49 @@
#!/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