#!/bin/sh -ex

BACKUP_DIR="<%= @backup_dir %>"

DATE_TODAY=$(date +%F)
TMP_FILE=$(mktemp --tmpdir=${BACKUP_DIR} --suffix=_${DATE_TODAY}.sql.gz)
BACKUP_FILE="${BACKUP_DIR}/postgres_whole_database_${DATE_TODAY}.sql.gz"

export PGUSER=postgres
export PGHOST=postgresql-primary

# Dump the entire database as one thing. See pp-manual for restore instructions.

pg_dumpall --clean --oids |gzip > ${TMP_FILE}

mv ${TMP_FILE} ${BACKUP_FILE}

# clean backups older than 30 days

find ${BACKUP_DIR} -mtime +30 -exec rm {} +

#!/bin/sh -ex

BACKUP_DIR="<%= @backup_dir %>"

DATE_TODAY=$(date +%F)
TMP_FILE=$(mktemp --tmpdir=${BACKUP_DIR} --suffix=_${DATE_TODAY}.sql.gz)
BACKUP_FILE="${BACKUP_DIR}/postgres_whole_database_${DATE_TODAY}.sql.gz"

export PGUSER=postgres

# Dump the entire database as one thing. See pp-manual for restore instructions.

pg_dumpall --clean --oids |gzip > ${TMP_FILE}

mv ${TMP_FILE} ${BACKUP_FILE}

# clean backups older than 30 days

find ${BACKUP_DIR} -mtime +30 -exec rm {} +

Fix postgres backup script on production
Fix postgres backup script on production

Turns out using `PGHOST` prevents us from authenticating on production
:S
