-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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." |