Created
June 10, 2014 20:28
-
-
Save duhast/9dedc5212951254c95a3 to your computer and use it in GitHub Desktop.
(re)Create PostgreSQL databases from a bunch of .sql.gz dumps
This file contains hidden or 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 | |
| # (re)Create PostgreSQL databases from a bunch of .sql.gz dumps | |
| DBHOST=localhost | |
| DBUSER=root | |
| for f in *.sql.gz | |
| do | |
| echo "Unpacking $f ..." | |
| gzip -d $f | |
| done | |
| for f in *.sql | |
| do | |
| echo "Processing $f file..." | |
| dbname=$(basename "$f" .sql) | |
| psql -h $DBHOST -U $DBUSER -d postgres -c "DROP DATABASE $dbname" | |
| psql -h $DBHOST -U $DBUSER -d postgres -c "CREATE DATABASE $dbname WITH ENCODING 'UTF8'" | |
| psql -h $DBHOST -U $DBUSER -d $dbname -f $f | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment