#!/usr/bin/env bash
set -euxo pipefail

DB_URI=$(echo $VCAP_SERVICES | jq -r '.postgres[0].credentials.uri')
echo -n "${PUBKEY}" > /app/public.key
gpg2 --import /app/public.key
pg_dump "${DB_URI}" --no-acl --no-owner | gzip | \
  gpg2 --trust-model always -r "${RECIPIENT}" --out /app/"${DUMP_FILE_NAME}" --encrypt

/usr/local/bin/python /app/upload-dump-to-s3.py

#!/usr/bin/env bash
set -euxo pipefail

DB_URI=$(echo $VCAP_SERVICES | jq -r '.postgres[0].credentials.uri')
echo -n "${PUBKEY}" > /app/public.key
gpg2 --import /app/public.key
pg_dump "${DB_URI}" --no-acl --no-owner --clean --if-exists | gzip | \
  gpg2 --trust-model always -r "${RECIPIENT}" --out /app/"${DUMP_FILE_NAME}" --encrypt

/usr/local/bin/python /app/upload-dump-to-s3.py

Add `--clean` flag to db_backups
Add `--clean` flag to db_backups

If you try to import the backup currently to a non empty db you get a
lot of errors.

The clean flag will remove old objects before importing the data.
