@@ -207,11 +207,17 @@ db.getSiblingDB('webhooks').dropDatabase();"
207207# ------ POSTGRESQL -------
208208# #
209209
210- docker run --rm \
211- -e PGPASSWORD=$POSTGRES_PASSWORD \
212- --network=$NETWORK \
213- postgres:17.6 \
214- bash -c " psql -h postgres -U $POSTGRES_USER -c 'DROP DATABASE IF EXISTS events;'"
210+ # Check if PostgreSQL backup exists before dropping database
211+ if [ -f " $ROOT_PATH /backups/postgres/events-${LABEL} .dump" ]; then
212+ echo " PostgreSQL backup found. Dropping existing events database..."
213+ docker run --rm \
214+ -e PGPASSWORD=$POSTGRES_PASSWORD \
215+ --network=$NETWORK \
216+ postgres:17.6 \
217+ bash -c " psql -h postgres -U $POSTGRES_USER -c 'DROP DATABASE IF EXISTS events;'"
218+ else
219+ echo " PostgreSQL backup not found for label ${LABEL} . Skipping PostgreSQL database drop..."
220+ fi
215221
216222# ####
217223#
@@ -238,13 +244,18 @@ docker run --rm -v $ROOT_PATH/backups/mongo:/data/backups/mongo --network=$NETWO
238244# ------ POSTGRESQL -------
239245# #
240246
241- echo " Restoring PostgreSQL 'events' database"
242- docker run --rm \
243- -e PGPASSWORD=$POSTGRES_PASSWORD \
244- -v $ROOT_PATH /backups/postgres:/backups \
245- --network=$NETWORK \
246- postgres:17.6 \
247- bash -c " createdb -h postgres -U $POSTGRES_USER events && pg_restore -h postgres -U $POSTGRES_USER -d events /backups/events-${LABEL} .dump"
247+ # Check if PostgreSQL backup exists before restoring
248+ if [ -f " $ROOT_PATH /backups/postgres/events-${LABEL} .dump" ]; then
249+ echo " PostgreSQL backup found. Restoring PostgreSQL 'events' database..."
250+ docker run --rm \
251+ -e PGPASSWORD=$POSTGRES_PASSWORD \
252+ -v $ROOT_PATH /backups/postgres:/backups \
253+ --network=$NETWORK \
254+ postgres:17.6 \
255+ bash -c " createdb -h postgres -U $POSTGRES_USER events && pg_restore -h postgres -U $POSTGRES_USER -d events /backups/events-${LABEL} .dump"
256+ else
257+ echo " PostgreSQL backup not found for label ${LABEL} . Skipping PostgreSQL database restore..."
258+ fi
248259
249260# #
250261# ------ ELASTICSEARCH -----
0 commit comments