Created
August 28, 2019 14:31
-
-
Save BrianSigafoos/89b40e761f0ceb41ba39f8ff41a9c044 to your computer and use it in GitHub Desktop.
Reload database
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/sh | |
DB_DUMP=$HOME/<filename>.dump | |
DB_NAME=<db name> | |
if [ -f $DB_DUMP ]; then | |
echo Creating database: $DB_NAME | |
createdb $DB_NAME > /dev/null 2>&1 | |
if [ "$?" != "0" ]; then | |
echo " Database already exists, not re-creating" | |
fi | |
echo Dropping and re-creating public schema | |
psql -d $DB_NAME -c 'DROP SCHEMA public CASCADE;' | |
psql -d $DB_NAME -c 'CREATE SCHEMA public;' | |
psql -d $DB_NAME -c 'GRANT ALL ON SCHEMA public TO postgres;' | |
psql -d $DB_NAME -c 'GRANT ALL ON SCHEMA public TO public;' | |
psql -d $DB_NAME -c "COMMENT ON SCHEMA public IS 'standard public schema';" | |
echo Restoring database: $DB_NAME | |
# pg_restore -d $DB_NAME -c -v $DB_DUMP > tmp/pg-restore.log 2>&1 | |
pg_restore -d $DB_NAME -c -v $DB_DUMP | |
else | |
echo Error locating $DB_DUMP, Aborting! | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment