Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions infrastructure/backups/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ echo "🧹 cleanup for indices: $approved_words from $indices"
echo "--------------------------"
for index in ${indices[@]}; do
for approved in $approved_words; do
echo "Checking index $index against approved pattern $approved..."
case "$index" in
"$approved_words"*)
"$approved"*)
echo "Delete index $index..."
docker run --rm --network=$NETWORK appropriate/curl curl -sS -XDELETE "http://$(elasticsearch_host)/$index"
break
Expand Down Expand Up @@ -214,7 +215,7 @@ if [ -f "$ROOT_PATH/backups/postgres/events-${LABEL}.dump" ]; then
-e PGPASSWORD=$POSTGRES_PASSWORD \
--network=$NETWORK \
postgres:17.6 \
bash -c "psql -h postgres -U $POSTGRES_USER -c 'DROP DATABASE IF EXISTS events;'"
bash -c "psql -h postgres -U $POSTGRES_USER -c 'DROP DATABASE IF EXISTS events WITH (FORCE);'"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naftis I had to add a force drop here as there might be clients connected to the DB when this restore procedure is ran. Is this ok?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm feeling confident that line was there. It was added by @cibelius about month ago.

I was reviewer on that PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be a merge issue once again

Copy link
Contributor

@cibelius cibelius Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm feeling confident that line was there. It was added by @cibelius about month ago.

I added WITH (FORCE) to clear-all-data.sh but not this restore.sh:
https://github.com/opencrvs/opencrvs-countryconfig/blob/develop/infrastructure/clear-all-data.sh#L147-L148

Copy link
Member

@naftis naftis Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the services restarted on restore? Not sure to be honest if we have any long running clients - but they'll get dropped then. At least restart solves it

To be honest it's a database drop so if someone is listening they'll get some funky errors any way

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I think we actually do have in our documentation https://documentation.opencrvs.org/setup/3.-installation/3.3-set-up-a-server-hosted-environment/4.3.7-backup-and-restore/4.3.7.1-restoring-a-backup

OpenCRVS requires to be re-deployed to function properly once a backup has been restored.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking into wrong file, sorry for misleading you

else
echo "PostgreSQL backup not found for label ${LABEL}. Skipping PostgreSQL database drop..."
fi
Expand Down Expand Up @@ -252,7 +253,11 @@ if [ -f "$ROOT_PATH/backups/postgres/events-${LABEL}.dump" ]; then
-v $ROOT_PATH/backups/postgres:/backups \
--network=$NETWORK \
postgres:17.6 \
bash -c "createdb -h postgres -U $POSTGRES_USER events && pg_restore -h postgres -U $POSTGRES_USER -d events /backups/events-${LABEL}.dump"
bash -c "createdb -h postgres -U $POSTGRES_USER events && \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to also create the database back here, with the schema and correct grants @naftis

psql -h postgres -U $POSTGRES_USER -d events -c 'CREATE SCHEMA app AUTHORIZATION events_migrator; GRANT USAGE ON SCHEMA app TO events_app;' && \
pg_restore -h postgres -U $POSTGRES_USER -d events --schema=app /backups/events-${LABEL}.dump"
echo "Update credentials in Postgres on restore"
docker service update --force opencrvs_postgres-on-update
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This updates PostgreSQL credentials after restore

else
echo "PostgreSQL backup not found for label ${LABEL}. Skipping PostgreSQL database restore..."
fi
Expand Down Expand Up @@ -309,3 +314,15 @@ tar -xzvf $ROOT_PATH/backups/vsexport/ocrvs-$LABEL.tar.gz -C $ROOT_PATH/vsexport
if [ "$IS_LOCAL" = false ]; then
docker service update --force --update-parallelism 1 opencrvs_migration
fi

##
# ------ REINDEX -----
##
docker run --rm \
-v /opt/opencrvs/infrastructure/deployment:/workspace \
-w /workspace \
--network $NETWORK \
-e 'AUTH_URL=http://auth:4040/' \
-e 'EVENTS_URL=http://gateway:7070/events' \
alpine \
sh -c 'apk add --no-cache curl jq && sh reindex.sh'
Loading