fix(backup): proper backup/restore hooks + healthcheck start_period
Some checks failed
cc-ci/testme cc-ci: failure
Some checks failed
cc-ci/testme cc-ci: failure
- Add mysql_backup.sh: mysqldump to backup.sql.gz with proper restore hook (old --tab backup had no restore hook → restored backup silently lost DB data) - Update db backupbot labels: pre-hook → /mysql_backup.sh backup, restore.post-hook → /mysql_backup.sh restore - Fix app healthcheck start_period 1m → 15m (Ghost fresh-DB migration takes ~6-9min on slow hosts; old 1m caused migration lock deadlocks on deploy) - Fix db healthcheck start_period 1m → 15m (InnoDB init on fresh data dir ~6-10min) - Add MYSQL_BACKUP_VERSION=v1 to abra.sh
This commit is contained in:
28
mysql_backup.sh
Executable file
28
mysql_backup.sh
Executable file
@ -0,0 +1,28 @@
|
||||
#!/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
|
||||
}
|
||||
|
||||
$@
|
||||
Reference in New Issue
Block a user