From 26ef5e6625d2654126ecf90ea1d226a46ed449e8 Mon Sep 17 00:00:00 2001 From: notplants <@notplants> Date: Tue, 2 Jun 2026 17:04:02 +0000 Subject: [PATCH] refactor(backup): inline backupbot hooks, drop mysql_backup.sh Move the mysqldump/gunzip commands directly into the backupbot.backup.pre-hook / backupbot.restore.post-hook label values on the db service and delete the external mysql_backup.sh + its config mount + MYSQL_BACKUP_VERSION. Matches the inline pattern used by akaunting / engelsystem / forgejo and removes one file from the recipe surface area. --- abra.sh | 1 - compose.yml | 11 ++--------- mysql_backup.sh | 28 ---------------------------- 3 files changed, 2 insertions(+), 38 deletions(-) delete mode 100755 mysql_backup.sh diff --git a/abra.sh b/abra.sh index 30b222f..8c8eb64 100644 --- a/abra.sh +++ b/abra.sh @@ -1,2 +1 @@ export GHOST_ENTRYPOINT_VERSION=v1 -export MYSQL_BACKUP_VERSION=v1 diff --git a/compose.yml b/compose.yml index c873d1f..50d36de 100644 --- a/compose.yml +++ b/compose.yml @@ -67,18 +67,14 @@ services: MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_password secrets: - db_password - configs: - - source: mysql_backup - target: /mysql_backup.sh - mode: 0555 volumes: - "mysql:/var/lib/mysql" deploy: labels: - "backupbot.backup=true" - - "backupbot.backup.pre-hook=/mysql_backup.sh backup" + - 'backupbot.backup.pre-hook=mysqldump -u root -p"$$(cat /run/secrets/db_password)" --single-transaction --routines --triggers --databases ghost | gzip > /var/lib/mysql/backup.sql.gz' - "backupbot.backup.volumes.mysql.path=backup.sql.gz" - - "backupbot.restore.post-hook=/mysql_backup.sh restore" + - 'backupbot.restore.post-hook=gunzip -c /var/lib/mysql/backup.sql.gz | mysql -u root -p"$$(cat /run/secrets/db_password)"' healthcheck: test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p\"$$(cat /run/secrets/db_password)\""] @@ -108,6 +104,3 @@ configs: ghost_entrypoint: name: ${STACK_NAME}_ghost_entrypoint_${GHOST_ENTRYPOINT_VERSION} file: entrypoint.sh - mysql_backup: - name: ${STACK_NAME}_mysql_backup_${MYSQL_BACKUP_VERSION} - file: mysql_backup.sh diff --git a/mysql_backup.sh b/mysql_backup.sh deleted file mode 100755 index 10a58b4..0000000 --- a/mysql_backup.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -# MySQL backup/restore hook for the `db` service. Invoked by backupbot-two via: -# backupbot.backup.pre-hook = "/mysql_backup.sh backup" -# backupbot.backup.path = "/var/lib/mysql/backup.sql.gz" -# backupbot.restore.post-hook = "/mysql_backup.sh restore" -# Backup dumps the `ghost` DB to a single gzipped file inside the mysql data volume; backupbot -# archives it. Restore reimports it. The previous recipe shipped a `mysqldump --tab` backup with NO -# restore hook (and the mysql data volume itself was not backed up), so a restored backup silently -# kept the live, un-restored DB state — data loss on restore. - -set -e - -BACKUP_FILE="/var/lib/mysql/backup.sql.gz" -export MYSQL_PWD="$(cat "${MYSQL_ROOT_PASSWORD_FILE:-/run/secrets/db_password}")" -DB_NAME="ghost" - -function backup { - mysqldump -u root --single-transaction --routines --triggers --databases "$DB_NAME" | gzip > "$BACKUP_FILE" -} - -function restore { - # --databases dump carries CREATE DATABASE/USE + per-table DROP+CREATE (mysqldump default), so the - # reimport deterministically rebuilds every table from the archived dump. - gunzip -c "$BACKUP_FILE" | mysql -u root -} - -$@