From 6417b5586e7320cad5fea2413387a1acace359d1 Mon Sep 17 00:00:00 2001 From: Dennis960 <66166638+Dennis960@users.noreply.github.com> Date: Tue, 3 Sep 2024 20:00:07 +0000 Subject: [PATCH] Add prod db restore script --- Server/scripts/sync-to-prod-db.bash | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 Server/scripts/sync-to-prod-db.bash diff --git a/Server/scripts/sync-to-prod-db.bash b/Server/scripts/sync-to-prod-db.bash new file mode 100755 index 0000000..183595a --- /dev/null +++ b/Server/scripts/sync-to-prod-db.bash @@ -0,0 +1,25 @@ +#!/bin/bash + +# Step 1: Connect to the server and create a dump with the --clean and --if-exists options +ssh Blumy << 'EOF' +echo "Creating production database dump with schema cleanup..." +docker exec blumy-production-db-1 pg_dump -U blumy -W --clean --if-exists blumy > /tmp/blumy_prod_dump.sql +EOF + +# Step 2: Download the dump from the server +echo "Downloading production database dump..." +scp Blumy:/tmp/blumy_prod_dump.sql ./ + +# Step 3: Completely wipe the local development database +echo "Dropping and recreating the local database schema..." +docker exec -e PGPASSWORD blumy -i blumy-dev-db-1 psql -U blumy -W blumy -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;" + +# Step 4: Restore the dump to the local development database +echo "Restoring the dump to the local development database..." +docker exec -i blumy-dev-db-1 psql -U blumy -W blumy < ./blumy_prod_dump.sql + +# Step 5: Clean up the local dump file +echo "Cleaning up local dump file..." +rm ./blumy_prod_dump.sql + +echo "Database synchronization complete."