-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
a4aa654
commit bf422d9
Showing
1 changed file
with
31 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,31 @@ | ||
# run this against the old database you are dumping from | ||
# after you execute shell in db run this script | ||
|
||
DB_NAME="pals-production-hyku" # Replace with your database name | ||
DB_USER="postgres" # Replace with your database username | ||
DUMP_DIR="/tmp/postgres" # Replace with your desired directory to store dump files | ||
|
||
# Create dump directory if it doesn't exist | ||
mkdir -p $DUMP_DIR | ||
|
||
# Get the list of schemas excluding system schemas | ||
SCHEMAS=$(psql -U $DB_USER -d $DB_NAME -t -c "SELECT schema_name FROM information_schema.schemata WHERE schema_name NOT IN ('pg_catalog', 'information_schema', 'pg_toast', 'public');") | ||
|
||
# Loop through each schema and dump it | ||
for SCHEMA in $SCHEMAS; do | ||
# Remove leading/trailing whitespace from schema name | ||
SCHEMA=$(echo $SCHEMA | xargs) | ||
|
||
# Output message | ||
echo "Dumping schema: $SCHEMA" | ||
|
||
# Dump the schema | ||
pg_dump -U $DB_USER -d $DB_NAME -n $SCHEMA -F c -f "$DUMP_DIR/${SCHEMA}.dump" | ||
|
||
# Check if the dump was successful | ||
if [ $? -eq 0 ]; then | ||
echo "Successfully dumped schema: $SCHEMA" | ||
else | ||
echo "Failed to dump schema: $SCHEMA" >&2 | ||
fi | ||
done |