From 7ec14bc40148cc74028fe9aaf087037191ca7960 Mon Sep 17 00:00:00 2001 From: MaxSorokin Date: Mon, 11 Mar 2024 19:23:06 +0300 Subject: [PATCH] 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"