mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-08-08 14:04:52 +03:00
Export PG* envs when restoring postgres from backup
This commit is contained in:
parent
7e23b19c91
commit
68b526d176
|
@ -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."
|
||||
|
|
Loading…
Reference in New Issue
Block a user