Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: move-db-to-delta #1031

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Script to dump db by schema
aprilrieger committed Jul 18, 2024
commit bf422d94e7e73fc7807270c71ad1a2c220c28eb4
31 changes: 31 additions & 0 deletions dump_schema.sh
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