diff --git a/ansible/roles/borg/backup-failure.service.j2 b/ansible/roles/borg/backup-failure.service.j2 new file mode 100644 index 0000000..a18d6f9 --- /dev/null +++ b/ansible/roles/borg/backup-failure.service.j2 @@ -0,0 +1,9 @@ +[Unit] +Description=Send backup failure notification + +[Service] +Type=oneshot +ExecStart=apprise --body="Failed to create backup!" {{ apprise_url }} + +[Install] +WantedBy=multi-user.target diff --git a/ansible/roles/borg/backup.service b/ansible/roles/borg/backup.service index ce1d25a..1673ef6 100644 --- a/ansible/roles/borg/backup.service +++ b/ansible/roles/borg/backup.service @@ -1,5 +1,6 @@ [Unit] Description=Backup data using Borgmatic +OnFailure=backup-failure.service [Service] ExecStart=/usr/bin/borgmatic --config /root/backup.yml diff --git a/ansible/roles/borg/backup.yml.j2 b/ansible/roles/borg/backup.yml.j2 index 882ea49..db42d9f 100644 --- a/ansible/roles/borg/backup.yml.j2 +++ b/ansible/roles/borg/backup.yml.j2 @@ -17,6 +17,4 @@ hooks: - guestunmount /mnt/thecloud && sleep 1 - virsh blockcommit tf-thecloud vdb --active --verbose --pivot - rm /kvm/snapshots/thecloud.qcow2 - - apprise --body="Backup succeeded" {{ apprise_url }} || true - on_error: - - apprise --body="Error while performing backup" {{ apprise_url }} || true + - apprise --body="Backup succeeded!" {{ apprise_url }} || true diff --git a/ansible/roles/borg/tasks/main.yml b/ansible/roles/borg/tasks/main.yml index 5229126..564a6f2 100644 --- a/ansible/roles/borg/tasks/main.yml +++ b/ansible/roles/borg/tasks/main.yml @@ -35,6 +35,12 @@ dest: /etc/systemd/system/backup.timer notify: systemd daemon reload +- name: Copy systemd backup failure service + template: + src: "{{ role_path }}/backup-failure.service.j2" + dest: /etc/systemd/system/backup-failure.service + notify: systemd daemon reload + - name: Enable backup timer systemd: name: backup.timer