Skip to content

Instantly share code, notes, and snippets.

@BrianSigafoos
Created August 28, 2019 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrianSigafoos/89b40e761f0ceb41ba39f8ff41a9c044 to your computer and use it in GitHub Desktop.
Save BrianSigafoos/89b40e761f0ceb41ba39f8ff41a9c044 to your computer and use it in GitHub Desktop.
Reload database
#!/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