diff --git a/playbooks/roles/borg-backup/tasks/main.yaml b/playbooks/roles/borg-backup/tasks/main.yaml index b8418ab178..4ccc7f867b 100644 --- a/playbooks/roles/borg-backup/tasks/main.yaml +++ b/playbooks/roles/borg-backup/tasks/main.yaml @@ -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 }}" diff --git a/playbooks/roles/borg-backup/templates/borg-backup.j2 b/playbooks/roles/borg-backup/templates/borg-backup.j2 index d645575135..f5a24df369 100644 --- a/playbooks/roles/borg-backup/templates/borg-backup.j2 +++ b/playbooks/roles/borg-backup/templates/borg-backup.j2 @@ -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}