borg-backup: send explicit email on backup failure

This sets a global BORG_UNDER_CRON=1 environment variable for
production hosts and makes the borg-backup script send an email if any
part of the backup job appears to fail (this avoids spamming ourselves
if we're testing backups, etc).

We should ideally never get this email, but if we do it's something we
want to investigate quickly.  There's nothing worse than thinking
backups are working when they aren't.

Change-Id: Ibb63f19817782c25a5929781b0f6342fe4c82cf0
This commit is contained in:
Ian Wienand 2021-02-16 14:42:36 +11:00
parent 94fe3610e5
commit 5ca69113fd
2 changed files with 11 additions and 0 deletions

View File

@ -53,6 +53,12 @@
name: '{{ item }}'
with_inventory_hostnames: borg-backup-server
- name: Set cron flag to enable error reports
cron:
name: BORG_UNDER_CRON
env: yes
job: '1'
- name: Install backup cron job
cron:
name: "Run borg backup to {{ item }}"

View File

@ -60,7 +60,12 @@ if [ ${backup_exit} -eq 0 ]; then
info "Backup finished successfully"
else
info "Backup finished with errors"
if [ ${BORG_UNDER_CRON:-0} -eq 1 ]; then
echo "Backups failed on host $(hostname) at $(date)." | \
mail -s "ACTION REQUIRED: Backup failed on $(hostname)" infra-root@openstack.org
fi
fi
exit ${backup_exit}