Re-enable grants backup

as bug has been fiexed since 2019

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-04-01 13:36:01 +02:00
parent a26d9a3bd3
commit 0c2fdaaf8b
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5

View file

@ -2,52 +2,52 @@
set -euo pipefail set -euo pipefail
function step() { function step() {
echo "[$(date +"%Y-%m-%d %H:%M:%S")] $@" echo "[$(date +"%Y-%m-%d %H:%M:%S")] $@"
} }
[ -z "${MYSQL_PASSWORD:-}" ] && { [ -z "${MYSQL_PASSWORD:-}" ] && {
echo 'No $MYSQL_PASSWORD was set, aborting.' echo 'No $MYSQL_PASSWORD was set, aborting.'
exit 1 exit 1
} }
while [ 1 ]; do while [ 1 ]; do
# Remove old backups older than N days (default 2d) # Remove old backups older than N days (default 2d)
DELETE_OLDER_THAN=${DELETE_OLDER_THAN:-2} DELETE_OLDER_THAN=${DELETE_OLDER_THAN:-2}
# This directory is exposed by the postgres image # This directory is exposed by the postgres image
TARGET_DIR=/data TARGET_DIR=/data
BACKUP_DATE=$(date +%Y-%m-%d_%H-%M-%S) BACKUP_DATE=$(date +%Y-%m-%d_%H-%M-%S)
# Collect databases # Collect databases
step "Starting backup..." step "Starting backup..."
DATABASES=$(mysql \ DATABASES=$(mysql \
-h "${MYSQL_HOST:-mariadb}" -u "${MYSQL_USER:-root}" -p${MYSQL_PASSWORD} \ -h "${MYSQL_HOST:-mariadb}" -u "${MYSQL_USER:-root}" -p${MYSQL_PASSWORD} \
-B --disable-column-names -e 'SHOW DATABASES' | -B --disable-column-names -e 'SHOW DATABASES' |
grep -vE '(information_schema|performance_schema|mysql|tmp)') grep -vE '(information_schema|performance_schema|mysql|tmp)')
# Create backup # Create backup
for db_name in ${DATABASES}; do for db_name in ${DATABASES}; do
TARGET_FILE="${TARGET_DIR}/${BACKUP_DATE}_${db_name}.sql.gz" TARGET_FILE="${TARGET_DIR}/${BACKUP_DATE}_${db_name}.sql.gz"
step "Creating backup of ${db_name} in ${TARGET_FILE}..." step "Creating backup of ${db_name} in ${TARGET_FILE}..."
mysqldump \ mysqldump \
-h "${MYSQL_HOST:-mariadb}" -u "${MYSQL_USER:-root}" -p${MYSQL_PASSWORD} \ -h "${MYSQL_HOST:-mariadb}" -u "${MYSQL_USER:-root}" -p${MYSQL_PASSWORD} \
-a --databases "${db_name}" | gzip >"${TARGET_FILE}" -a --databases "${db_name}" | gzip >"${TARGET_FILE}"
done done
# Dump grants -- Disabled until https://jira.percona.com/browse/PT-1561 is fixed # Dump grants
#GRANTS_FILE="${TARGET_DIR}/${BACKUP_DATE}_grants.sql" GRANTS_FILE="${TARGET_DIR}/${BACKUP_DATE}_grants.sql"
#step "Creating grants backuo in ${GRANTS_FILE}..." step "Creating grants backup in ${GRANTS_FILE}..."
#pt-show-grants -h "${MYSQL_HOST:-mariadb}" -u "${MYSQL_USER:-root}" -p "${MYSQL_PASSWORD}" >"${GRANTS_FILE}" pt-show-grants -h "${MYSQL_HOST:-mariadb}" -u "${MYSQL_USER:-root}" -p "${MYSQL_PASSWORD}" >"${GRANTS_FILE}"
# Cleanup old backups # Cleanup old backups
step "Removing old backups..." step "Removing old backups..."
find "${TARGET_DIR}" -name '*.sql.gz' -mtime "${DELETE_OLDER_THAN}" -delete find "${TARGET_DIR}" -name '*.sql.gz' -mtime "${DELETE_OLDER_THAN}" -delete
find "${TARGET_DIR}" -name '*.sql' -mtime "${DELETE_OLDER_THAN}" -delete find "${TARGET_DIR}" -name '*.sql' -mtime "${DELETE_OLDER_THAN}" -delete
# Sleep until next full hour # Sleep until next full hour
step "I'm done, see ya next hour!" step "I'm done, see ya next hour!"
sleep $((3600 - $(date +%s) % 3600)) sleep $((3600 - $(date +%s) % 3600))
done done