cookiecutter-django/{{cookiecutter.repo_name}}/compose/postgres/backup.sh

23 lines
700 B
Bash
Raw Normal View History

2016-03-08 12:41:58 +03:00
#!/bin/bash
# stop on errors
set -e
# we might run into trouble when using the default `postgres` user, e.g. when dropping the postgres
# database in restore.sh. Check that something else is used here
if [ "$POSTGRES_USER" == "postgres" ]
then
echo "creating a backup as the postgres user is not supported, make sure to set the POSTGRES_USER environment variable"
exit 1
fi
# export the postgres password so that subsequent commands don't ask for it
export PGPASSWORD=$POSTGRES_PASSWORD
echo "creating backup"
echo "---------------"
FILENAME=backup_$(date +'%Y_%m_%dT%H_%M_%S').sql
pg_dump -h postgres -U $POSTGRES_USER >> /backups/$FILENAME
echo "successfully created backup $FILENAME"