-
Notifications
You must be signed in to change notification settings - Fork 69
Fix multiple bugs in the restore script #1112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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);'" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be a merge issue once again
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I added
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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 && \ | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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' | ||
Uh oh!
There was an error while loading. Please reload this page.