Skip to content

Commit

Permalink
Sikre at dump-fil blir slettet ved error (#6230)
Browse files Browse the repository at this point in the history
  • Loading branch information
Watercolours authored Nov 7, 2024
1 parent c966083 commit 264b49e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions clone-dev-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ DUMP_FILE="${PROXY_DB}_$(date +%s).dump"
DOCKER_HOST="host.docker.internal"
CURRENT_CONTEXT=$(kubectl config current-context)

# Ensure the dump file is deleted on exit
trap "rm $DUMP_FILE 2> /dev/null" EXIT

nais device status | grep -q -i "naisdevice status: Disconnected" &> /dev/null
if [ $? -eq 0 ]; then # Grep returns 0 if there is a match
error "Naisdevice is not connected. Please run:\n\n\t$ nais device connect \n\nOr use the naisdevice.app"
Expand Down Expand Up @@ -120,8 +123,6 @@ pg_dump \
wait $!
PG_DUMP_EXIT_STATUS=$?

ps_loader

if [ $PG_DUMP_EXIT_STATUS -eq 0 ]; then
info "pg_dump was successful!"
else
Expand Down Expand Up @@ -149,14 +150,9 @@ pg_restore \
wait $!
PG_RESTORE_EXIT_STATUS=$?

ps_loader

if [ $PG_RESTORE_EXIT_STATUS -eq 0 ]; then
info "pg_restore was successful!"
info "Database cloning from dev-gcp completed!"
else
rm $DUMP_FILE 2> /dev/null
error "Unexpected error occurred while running pg_restore"
fi

rm $DUMP_FILE 2> /dev/null

0 comments on commit 264b49e

Please sign in to comment.