Skip to content

Commit

Permalink
fix: reset public schema
Browse files Browse the repository at this point in the history
  • Loading branch information
askonev committed Mar 11, 2024
1 parent 15b499c commit 7ec14bc
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion restore_backup.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 7ec14bc

Please sign in to comment.