All checks were successful
cc-ci/testme cc-ci: success
Move the postgres and clickhouse backup/restore hook logic out of inline compose labels into dedicated pg_backup.sh / clickhouse_backup.sh config scripts (the pattern other recipes use), and trim the verbose explanatory comments down to the essential rationale, now living in the scripts.
31 lines
1.1 KiB
Bash
31 lines
1.1 KiB
Bash
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
# clickhouse-backup output lives inside the event-data volume (snapshotted via
|
|
# backupbot.backup.volumes.event-data.path). Restoring the raw data files under a
|
|
# running server is unsafe, so restore performs a logical restore instead.
|
|
BACKUP_DIR=/var/lib/clickhouse/backup/events
|
|
MIGRATIONS_TSV="$BACKUP_DIR/schema_migrations.tsv"
|
|
|
|
backup() {
|
|
clickhouse-backup create events
|
|
# schema_migrations is a TinyLog table — clickhouse-backup only FREEZEs MergeTree
|
|
# data, so its rows aren't captured. Export them alongside the backup, else a restore
|
|
# leaves the ledger empty and the next boot re-runs every migration (DUPLICATE_COLUMN).
|
|
clickhouse-client --query "SELECT * FROM plausible_events_db.schema_migrations FORMAT TSV" > "$MIGRATIONS_TSV"
|
|
}
|
|
|
|
backup_cleanup() {
|
|
rm -rf "$BACKUP_DIR"
|
|
}
|
|
|
|
restore() {
|
|
clickhouse-backup restore --rm events
|
|
clickhouse-client --query "TRUNCATE TABLE plausible_events_db.schema_migrations"
|
|
clickhouse-client --query "INSERT INTO plausible_events_db.schema_migrations FORMAT TSV" < "$MIGRATIONS_TSV"
|
|
rm -rf "$BACKUP_DIR"
|
|
}
|
|
|
|
"$@"
|