diff --git a/roles/backup/templates/s3backup.sh b/roles/backup/templates/s3backup.sh index 1a8cabb..22227c7 100644 --- a/roles/backup/templates/s3backup.sh +++ b/roles/backup/templates/s3backup.sh @@ -75,6 +75,9 @@ backup() { # Dump Postgres DBs, if possible if command -v psql > /dev/null 2>&1; then + # Put down a place for us to store backups, if we don't have it already + backupdir="/opt/postgres-backups" + mkdir -p "$backupdir" # Populate a list of databases declare -a DATABASES while read line; do @@ -89,13 +92,11 @@ if command -v psql > /dev/null 2>&1; then echo "Will upload resultant backups to {{ backup_s3_bucket }}" for db in "${DATABASES[@]}"; do echo "Backing up $db" + path="$backupdir/$db.pgsql.gz" sudo -u postgres pg_dump "$db" \ - | gzip -v9 \ - | aws s3 cp - \ -{% if backup_s3_aws_endpoint_url is defined %} - --endpoint-url="{{ backup_s3_aws_endpoint_url }}" \ -{% endif %} - "s3://{{ backup_s3_bucket }}/$HOSTNAME/pgdump/$db/$(date "+{{ backup_dateformat }}").pgsql.gz" + | gzip -v9 > + "$path" + DIRS+=("$path") done fi