Restic: send an email on backup failure #202
No reviewers
Labels
No labels
Blocked
Existing Service
Infrastructure Issue
Refactor
Security Hardening
Security Issue
Service Idea
Service Removal
Upgrade service
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: data.coop/ansible#202
Loading…
Reference in a new issue
No description provided.
Delete branch "restic-notifications"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The restic docker image has a mechanism for specifying scripts to execute on success and failure. https://github.com/djmaze/resticker?tab=readme-ov-file#execute-commands-after-backup
However, a challenge is that the image comes with very few utilities. You are expected to use curl to notify a web service that then can send an email for you. Thankfully, curl can do everything including sending mail.
There is some tomfoolery in order to setup noreply.data.coop as a general purpose domain for sending notification emails. We can't use data.coop (I think) because mailu manages that.
I have manually tested the curl invocation in a random container that had curl installed and was on the postfix network. First attempt I sent it from noreply@services.data.coop, but that is not in our allowed sender domains. Then I (ab)used noreply@member.data.coop with success. The remaining changes are untested.
I also set restic to exclude backup of its own files just because they are all generated by ansible.
Some suggestions and minor things that need to be fixed, otherwise great work!
@ -53,0 +53,4 @@
# mail dance
domain: "noreply.{{ base_domain }}"
allowed_sender_domain: true
mail-from: "noreply@noreply.{{ base_domain }}"
I suggest
restic@noreply.{{ base_domain }}
orbackup@noreply.{{ base_domain }}
instead. Also, let's keep the syntax style with underscores, somail_from
instead ofmail-from
.@ -15,6 +15,7 @@ services:
--tag datacoop-volumes
--exclude '*.tmp'
--exclude '/mnt/volumes/mastodon/mastodon_data/cache/'
--exclude '/mnt/volumes/restic/'
Please change this line to use spaces instead of tabs, and have it on the same indentation level as the above lines.
@ -22,9 +23,13 @@ services:
--keep-weekly 5
--keep-monthly 12
TZ: Europe/Copenhagen
POST_COMMANDS_FAILURE=/run/libexec/failure.sh
This needs to be with a
:
instead of=
like the rest of the variables.@ -0,0 +1,14 @@
#!/bin/sh
curl smtp://postfix --mail-from {{ services.restic.mail-from }} --mail-rcpt admin-hold@data.coop --upload-file . << END_OF_MAIL
Our email is
admin@data.coop
🙂Also,
mail-from
->mail_from
like above.Actually we have both for some reason
One last thing, then it's approved 💯
@ -0,0 +1,14 @@
#!/bin/sh
curl smtp://postfix --mail-from {{ services.restic.mail_from }} --mail-rcpt admin@data.coop --upload-file . << END_OF_MAIL
Let's use
{{ smtp_host }}
here 😄You mean like
smtp://{{ smtp_host }}
?FINE!
One last thing (v2.0) 😃
@ -0,0 +1,14 @@
#!/bin/sh
curl smtp://{{ smtp_host }} --mail-from {{ services.restic.mail_from }} --mail-rcpt admin@data.coop --upload-file . << END_OF_MAIL
From: Restic backup <{{ services.restic.mail-from }}>
To: admin-hold@data.coop
Wrong email (perhaps a
services.restic.mail_to
is appropriate?) 😉@reynir
To: admin-hold@data.coop
LGTM 💯
Manually merged.
I deployed restic again, but this did not redeploy postfix even if its config changed.
(I have since then redeployed postfix)
Pull request closed