fix: report scheduled backup failures
All checks were successful
CI / test (pull_request) Successful in 9m12s
CI / deploy (pull_request) Has been skipped

This commit is contained in:
2026-09-15 18:53:06 +03:00
parent b933f95302
commit 69c1dd52cf
8 changed files with 16 additions and 12 deletions

View File

@@ -6,5 +6,5 @@ app_dir=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
trap 'rm -f -- "$temporary"' EXIT HUP INT TERM
crontab -l 2>/dev/null | grep -v 'postgres-backup.sh' > "$temporary" || true
printf '%s\n' "30 3 * * 0 flock -n /tmp/miem-postgres-backup.lock $app_dir/infra/postgres-backup.sh >/dev/null 2>&1" >> "$temporary"
printf '%s\n' "30 3 * * 0 flock -w 3600 /tmp/miem-postgres-backup.lock $app_dir/infra/postgres-backup.sh || logger -t miem-postgres-backup -- 'backup skipped or failed'" >> "$temporary"
crontab "$temporary"

View File

@@ -7,12 +7,14 @@ backup_dir="$HOME/backups/postgres"
backup="$backup_dir/postgres-latest.sql"
temporary="$backup.tmp.$$"
log() { logger -t miem-postgres-backup -- "$*" 2>/dev/null || true; }
mkdir -p "$backup_dir"
trap 'rm -f -- "$temporary"' EXIT HUP INT TERM
trap 'status=$?; rm -f -- "$temporary"; [ "$status" -eq 0 ] || log "backup failed"; exit "$status"' EXIT HUP INT TERM
cd "$app_dir"
docker compose exec -T postgres sh -c 'pg_dumpall -U "$POSTGRES_USER"' > "$temporary"
test -s "$temporary"
mv "$temporary" "$backup"
find "$HOME/backups/miem_workers" -maxdepth 1 -type f -name 'miem_workers-*.sql' -delete 2>/dev/null || true
printf '%s\n' "Created $backup"
log "created $backup"