Skip to content

Commit 4d1b80b

Browse files
committed
Setting up trap to make sure the dump file is deleted
1 parent 5caae23 commit 4d1b80b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

backup.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ case "${PG_BACKUP_ACTION:-dump}" in
5858
export AWS_SECRET_ACCESS_KEY=$S3_SECRET_ACCESS_KEY
5959
export AWS_DEFAULT_REGION=$S3_REGION
6060

61+
# Define a cleanup function
62+
cleanup() {
63+
echo "Cleaning up..."
64+
rm -f dump.backup
65+
}
66+
67+
# Set a trap to call the cleanup function when the script exits
68+
trap cleanup EXIT
69+
6170
# TODO: check if database is fresh
6271
echo "Snapshotting $POSTGRES_DB database"
6372
pg_dump -Fc $POSTGRES_HOST_OPTS $POSTGRES_DB > dump.backup
@@ -77,7 +86,6 @@ case "${PG_BACKUP_ACTION:-dump}" in
7786
fi
7887

7988
echo "Snapshot uploaded successfully, removing local file"
80-
rm dump.backup
8189

8290
if [ ! -z "$HEARTBEAT_URI" ]; then
8391
echo "Sending heartbeat signal"

0 commit comments

Comments
 (0)