From 7ec14bc40148cc74028fe9aaf087037191ca7960 Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Mon, 11 Mar 2024 19:23:06 +0300 Subject: [PATCH 1/4] fix: reset public schema --- restore_backup.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) mode change 100644 => 100755 restore_backup.sh diff --git a/restore_backup.sh b/restore_backup.sh old mode 100644 new mode 100755 index ad92ee9..06a3ae3 --- a/restore_backup.sh +++ b/restore_backup.sh @@ -7,8 +7,24 @@ CPU_COUNT=4 DB_CONTAINER_ID=$(docker-compose ps -q db) BACKUP_NAME="${BACKUP_NAME:-unknown-backup}" +# download dump aws s3 cp s3://palladium-backup/"$BACKUP_NAME" . + +# reset the public schema & define access privileges +docker exec \ +-u postgres \ +"$DB_CONTAINER_ID" \ +psql -c \ +'DROP SCHEMA public CASCADE; CREATE SCHEMA public; GRANT ALL ON SCHEMA public TO postgres; GRANT ALL ON SCHEMA public TO public;' + +# restore pg_backup docker cp "$BACKUP_NAME" "$DB_CONTAINER_ID":/tmp/ -docker exec "$DB_CONTAINER_ID" pg_restore -j $CPU_COUNT -U postgres -d postgres /tmp/"$BACKUP_NAME" +docker exec "$DB_CONTAINER_ID" \ + pg_restore \ + -j $CPU_COUNT \ + -U postgres \ + -d postgres \ + /tmp/"$BACKUP_NAME" docker exec "$DB_CONTAINER_ID" rm /tmp/"$BACKUP_NAME" + rm "$BACKUP_NAME" From 847885d65c54d0e3cf4ede8c9445710b2891cb39 Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Wed, 13 Mar 2024 17:25:28 +0300 Subject: [PATCH 2/4] update: changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dc92fb..d67bf19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### New Features +* [fix] restore_backup.sh restores the default public scheme * SSL configuration is enabled by default * Add backup and restore scripts * Add `markdownlint` check in CI From 513f27129f0684b0c68eb885294151b87ef16846 Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Wed, 13 Mar 2024 17:26:34 +0300 Subject: [PATCH 3/4] feature: add survey script --- lib/survey.sh | 15 +++++++++++++++ restore_backup.sh | 5 +++++ 2 files changed, 20 insertions(+) create mode 100755 lib/survey.sh diff --git a/lib/survey.sh b/lib/survey.sh new file mode 100755 index 0000000..174c19d --- /dev/null +++ b/lib/survey.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +while true; do + +read -p "Do you want to proceed? (yes/no) " yn + +case $yn in + yes ) echo ok, we will proceed; + break;; + no ) echo exiting...; + exit;; + * ) echo invalid response;; +esac + +done diff --git a/restore_backup.sh b/restore_backup.sh index 06a3ae3..1607f8d 100755 --- a/restore_backup.sh +++ b/restore_backup.sh @@ -1,5 +1,10 @@ #!/bin/bash +echo 'The script restores the default state of the \ + public schema, which will delete all data' + +source lib/survey.sh + # Correctly configure aws cli before running this script # `aws configure` From c1d91d6c9dafb37c4b737e9a8addd283f204f4a4 Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Wed, 13 Mar 2024 17:33:29 +0300 Subject: [PATCH 4/4] fix: shellcheck rules [SC1091] [SC2162] --- lib/survey.sh | 15 --------------- restore_backup.sh | 25 ++++++++++++++++++++----- 2 files changed, 20 insertions(+), 20 deletions(-) delete mode 100755 lib/survey.sh diff --git a/lib/survey.sh b/lib/survey.sh deleted file mode 100755 index 174c19d..0000000 --- a/lib/survey.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -while true; do - -read -p "Do you want to proceed? (yes/no) " yn - -case $yn in - yes ) echo ok, we will proceed; - break;; - no ) echo exiting...; - exit;; - * ) echo invalid response;; -esac - -done diff --git a/restore_backup.sh b/restore_backup.sh index 1607f8d..4a8959b 100755 --- a/restore_backup.sh +++ b/restore_backup.sh @@ -1,10 +1,5 @@ #!/bin/bash -echo 'The script restores the default state of the \ - public schema, which will delete all data' - -source lib/survey.sh - # Correctly configure aws cli before running this script # `aws configure` @@ -12,6 +7,26 @@ CPU_COUNT=4 DB_CONTAINER_ID=$(docker-compose ps -q db) BACKUP_NAME="${BACKUP_NAME:-unknown-backup}" + +echo 'The script restores the default state of the' \ + 'public schema, which will delete all data' + +while true; do + + echo "Continue? (yes/no) " + read -r yn + + case $yn in + yes ) echo 'start of dump recovery'; + break;; + no ) echo 'exiting...'; + exit 1;; + * ) echo 'invalid response';; + esac + +done + + # download dump aws s3 cp s3://palladium-backup/"$BACKUP_NAME" .