Skip to content
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

fix: reset public schema before restore pg_dump #20

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 37 additions & 1 deletion restore_backup.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,44 @@ 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" .

# 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"
Loading