Skip to content

Instantly share code, notes, and snippets.

@gbpereira
Forked from nathcampreguer/db_restore.sh
Created May 9, 2016 19:05
Show Gist options
  • Save gbpereira/7b67828d0a68af7fed8cf346168e4186 to your computer and use it in GitHub Desktop.
Save gbpereira/7b67828d0a68af7fed8cf346168e4186 to your computer and use it in GitHub Desktop.
#!/bin/bash
DBNAME=<database_name>
DBUSER=<database_user>
DBHOST=<host>
DUMP_FILE=$1
if [[ $DUMP_FILE == "" ]]; then
echo "[ERROR] Arquivo de dump não especificado"
echo " usage: restore.sh DUMP_FILE"
exit 0
fi
dropdb --username=$DBUSER --host=$DBHOST $DBNAME
createdb --username=$DBUSER --host=$DBHOST $DBNAME
pg_restore -v --exit-on-error --single-transaction --no-owner --no-privileges --host=$DBHOST --dbname=$DBNAME --username=$DBUSER $DUMP_FILE
reindexdb --username=$DBUSER --host=$DBHOST --system
reindexdb --username=$DBUSER --host=$DBHOST $DBNAME
vacuumdb --full --analyze --username=$DBUSER --host=$DBHOST $DBNAME
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment