diff --git a/{{cookiecutter.project_slug}}/compose/production/postgres/maintenance/restore b/{{cookiecutter.project_slug}}/compose/production/postgres/maintenance/restore index 498140073..eacca1ee4 100644 --- a/{{cookiecutter.project_slug}}/compose/production/postgres/maintenance/restore +++ b/{{cookiecutter.project_slug}}/compose/production/postgres/maintenance/restore @@ -37,7 +37,10 @@ if [[ "${POSTGRES_USER}" == "postgres" ]]; then exit 1 fi +export PGHOST="postgres" +export PGUSER="${POSTGRES_USER}" export PGPASSWORD="${POSTGRES_PASSWORD}" +export PGDATABASE="${POSTGRES_DB}" message_info "Dropping all connections to the database..." # Source: http://dba.stackexchange.com/a/11895 @@ -54,23 +57,12 @@ psql \ --command="${drop_postgres_connections_sql}" message_info "Dropping the database..." -dropdb \ - --host=postgres \ - --username="${POSTGRES_USER}" \ - "${POSTGRES_DB}" +dropdb "${PGDATABASE}" message_info "Creating a new database..." -createdb \ - --host=postgres \ - --username="${POSTGRES_USER}" \ - --owner="${POSTGRES_USER}" \ - "${POSTGRES_DB}" +createdb --owner="${POSTGRES_USER}" message_info "Applying the backup to the new database..." -gunzip -c "${backup_filename}" \ - | psql \ - --host=postgres \ - --username="${POSTGRES_USER}" \ - "${POSTGRES_DB}" +gunzip -c "${backup_filename}" | psql "${POSTGRES_DB}" message_success "The '${POSTGRES_DB}' database has been restored from the '${backup_filename}' backup."