From 5873d148c10e51124b712e03de82b795f4541e7b Mon Sep 17 00:00:00 2001 From: xCyanGrizzly Date: Thu, 23 Jul 2026 01:06:22 +0200 Subject: [PATCH] Fix backup.sh: always clean up temp dump/tar files via EXIT trap 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 --- backup/backup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backup/backup.sh b/backup/backup.sh index 73c6208..2e596bd 100644 --- a/backup/backup.sh +++ b/backup/backup.sh @@ -11,6 +11,8 @@ 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 @@ -18,8 +20,6 @@ tar czf "$TAR_FILE" -C /data tdlib-worker tdlib-bot restic backup "$DUMP_FILE" "$TAR_FILE" restic forget --keep-daily 14 --prune -rm -f "$DUMP_FILE" "$TAR_FILE" - curl -fsS "$KUMA_PUSH_URL" --get \ --data-urlencode "status=up" \ --data-urlencode "msg=OK"