Skip to content

Instantly share code, notes, and snippets.

@duhast
Created June 10, 2014 20:28
Show Gist options
  • Select an option

  • Save duhast/9dedc5212951254c95a3 to your computer and use it in GitHub Desktop.

Select an option

Save duhast/9dedc5212951254c95a3 to your computer and use it in GitHub Desktop.
(re)Create PostgreSQL databases from a bunch of .sql.gz dumps
#!/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