From ae657c89f82c59778303225f240ed4712c127cbf Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Wed, 7 Apr 2021 05:17:16 +0200 Subject: [PATCH] new: [mariadb] added mysql's backup install script with debian 10 compatibility Signed-off-by: Valentin Lab --- mariadb/hooks/install.d/60-backup.sh | 102 +++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 mariadb/hooks/install.d/60-backup.sh diff --git a/mariadb/hooks/install.d/60-backup.sh b/mariadb/hooks/install.d/60-backup.sh new file mode 100644 index 0000000..1ab7e7d --- /dev/null +++ b/mariadb/hooks/install.d/60-backup.sh @@ -0,0 +1,102 @@ + +set -eux ## important for unbound variable ? + +## Require these to be set +# MYSQL_ROOT_PASSWORD= +# MYSQL_CONTAINER= + +[ "${MYSQL_ROOT_PASSWORD}" ] || { + echo "Error: you must set \$MYSQL_ROOT_PASSWORD prior to running this script." >&2 + exit 1 +} + +[ "${MYSQL_CONTAINER}" ] || { + echo "Error: you must set \$MYSQL_CONTAINER prior to running this script." >&2 + exit 1 +} + + +## +## Init, to setup passwordless connection to mysql +## + +type -p mysql >/dev/null || { + case $(lsb_release -is) in + Debian) + case $(lsb_release -rs) in + 10) + apt-get install -y default-mysql-client ~/.my.cnf +[client] +password=${MYSQL_ROOT_PASSWORD} +EOF + chmod 600 ~/.my.cnf +fi + +## +## installation of the mysql-backup script +## + + +apt-get install -y kal-shlib-{core,pretty,common} /etc/cron.d/mysql-backup +SHELL=/bin/bash +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin + +0 * * * * root /usr/local/sbin/mysql-backup --host \$(docker-ip "$MYSQL_CONTAINER" 2>/dev/null | sed -r 's/ +/ /g' | cut -f 3 -d " ") | logger -t mysql-backup + +EOF + + +## +## Connection with backup +## + +if type -p mirror-dir >/dev/null 2>&1; then + [ -d "/etc/mirror-dir" ] || { + echo "'mirror-dir' is installed but no '/etc/mirror-dir' was found." >&2 + exit 1 + } + depends shyaml + + if ! sources=$(shyaml get-values default.sources < /etc/mirror-dir/config.yml); then + echo "Couldn't query 'default.sources' in '/etc/mirror-dir/config.yml'." >&2 + exit 1 + fi + + if ! echo "$sources" | grep "^/var/backups/mysql$" 2>/dev/null; then + sed -i '/sources:/a\ - /var/backups/mysql' /etc/mirror-dir/config.yml + cat <> /etc/mirror-dir/config.yml +/var/backups/mysql: + exclude: + - "/*.inprogress" +EOF + fi +else + echo "warn: 'mirror-dir' not installed, backup won't be sent" >&2 +fi + + +