mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-09-21 05:21:43 +00:00
Previously the dump/tar cleanup only ran after restic forget succeeded, so a plaintext Postgres dump could be left behind in /tmp if tar or restic failed partway through. Add an EXIT trap that unconditionally removes both temp files on any exit path, and drop the now-redundant explicit rm -f from the success path. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
26 lines
625 B
Bash
26 lines
625 B
Bash
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
report_failure() {
|
|
curl -fsS "$KUMA_PUSH_URL" --get \
|
|
--data-urlencode "status=down" \
|
|
--data-urlencode "msg=$BASH_COMMAND failed" || true
|
|
}
|
|
trap report_failure ERR
|
|
|
|
DUMP_FILE=/tmp/dragonsstash.dump
|
|
TAR_FILE=/tmp/tdlib.tar.gz
|
|
|
|
trap 'rm -f "$DUMP_FILE" "$TAR_FILE"' EXIT
|
|
|
|
pg_dump -h dragonsstash-db -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Fc -f "$DUMP_FILE"
|
|
|
|
tar czf "$TAR_FILE" -C /data tdlib-worker tdlib-bot
|
|
|
|
restic backup "$DUMP_FILE" "$TAR_FILE"
|
|
restic forget --keep-daily 14 --prune
|
|
|
|
curl -fsS "$KUMA_PUSH_URL" --get \
|
|
--data-urlencode "status=up" \
|
|
--data-urlencode "msg=OK"
|