mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-11 20:28:01 +03:00
39 lines
971 B
Plaintext
39 lines
971 B
Plaintext
|
#!/usr/bin/env bash
|
||
|
|
||
|
|
||
|
### Create a database backup.
|
||
|
###
|
||
|
### Usage:
|
||
|
### $ docker-compose -f <environment>.yml (exec |run --rm) postgres backup
|
||
|
|
||
|
|
||
|
set -o errexit
|
||
|
set -o pipefail
|
||
|
set -o nounset
|
||
|
|
||
|
|
||
|
working_dir="$(dirname ${0})"
|
||
|
source "${working_dir}/_sourced/constants.sh"
|
||
|
source "${working_dir}/_sourced/messages.sh"
|
||
|
|
||
|
|
||
|
message_welcome "Backing up the '${POSTGRES_DB}' database..."
|
||
|
|
||
|
|
||
|
if [[ "${POSTGRES_USER}" == "postgres" ]]; then
|
||
|
message_error "Backing up as 'postgres' user is not supported. Assign 'POSTGRES_USER' env with another one and try again."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
export PGPASSWORD="${POSTGRES_PASSWORD}"
|
||
|
|
||
|
backup_filename="${BACKUP_FILE_PREFIX}_$(date +'%Y_%m_%dT%H_%M_%S').sql.gz"
|
||
|
pg_dump \
|
||
|
--host=postgres \
|
||
|
--dbname="${POSTGRES_DB}" \
|
||
|
--username="${POSTGRES_USER}" \
|
||
|
| gzip > "${BACKUP_DIR_PATH}/${backup_filename}"
|
||
|
|
||
|
|
||
|
message_success "'${POSTGRES_DB}' database backup '${backup_filename}' has been created and placed in '${BACKUP_DIR_PATH}'."
|