Created
February 7, 2019 13:08
-
-
Save viewpointsa/e230f6171762f52b36405c3b8df24ba0 to your computer and use it in GitHub Desktop.
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 | |
if [ $# -ne 2 ]; then | |
echo $0: usage: myscript databasename zipfile | |
exit 1 | |
fi | |
dbname=$1 | |
psql --command "select pg_terminate_backend(procpid) from pg_stat_activity where datname = '$dbname';" | |
dropdb $dbname | |
createdb $dbname | |
gunzip -c ${2} | psql $dbname | |
psql $dbname --command "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO admin ;" | |
psql $dbname --command "GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO admin ;" | |
if [ -f "post_$dbname.sql" ] | |
then | |
cat "post_$dbname.sql" | psql $dbname | |
fi; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment