Files
ghost/mysql_backup.sh
autonomic-bot a1e95fcbcd fix(backup): single-file mysqldump backup + reimport-on-restore hook
The previous recipe backed the DB up as a mysqldump --tab into /var/lib/mysql-files with NO restore
hook (and the mysql data volume itself was not backupbot-labelled), so a restored backup silently
kept the live, un-restored DB state — data loss on restore. Add mysql_backup.sh (backup: gzipped
mysqldump --databases ghost into the data volume; restore: reimport it) wired via backupbot
backup.pre-hook + restore.post-hook, mirroring the postgres recipes (mattermost-lts, immich). Bump
1.2.0 -> 1.3.0.
2026-05-30 04:58:53 +00:00

29 lines
1.1 KiB
Bash
Executable File

#!/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
}
$@