Created
March 10, 2023 17:54
-
-
Save ssaid/e711082f9a757e8730ed6ca2ee996387 to your computer and use it in GitHub Desktop.
Dump data and schema from PostgreSQL DB
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
#!/bin/bash | |
DBNAME="dbname" | |
tables=$(psql -d $DBNAME -t -c "SELECT table_name FROM information_schema.tables WHERE table_schema='public' and table_type='BASE TABLE'"|cut -d' ' -f2) | |
while IFS= read -r table; do | |
pg_dump --schema-only -t $table $DBNAME > $table.schema | |
pg_dump --data-only -t $table $DBNAME > $table.data | |
done <<< "$tables" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment