aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfgang Müller2021-04-30 16:52:35 +0200
committerWolfgang Müller2021-04-30 16:52:35 +0200
commit15442e278022a377931774e311e257dc75f1df4c (patch)
tree1483593f5bc522f3c6c2ae092c6cecaeb3b9fa81
parent455ffc5223bead2df4477bdae94d959855f7478f (diff)
downloadlifeboat-15442e278022a377931774e311e257dc75f1df4c.tar.gz
Add command to mail the output of a backup run
This commit introduces the 'run-report' command and a new config file 'config/recipient' which indicates the recipient of the report. Since lifeboat was always intended to be run via a cronjob, we assumed mail functionality would come from the specific crond implementation. This is well-supported throughout, but not a feature that systemd's timers (yet?) have. Since one of our systems is now running systemd, we needed a decent alternative. A wrapper script was considered, but at that point we could also just as simply include mail support in lifeboat itself. We have chosen to implement this by calling out to sendmail, which seems to be a de-facto standard (postfix has sendmail compatibility, as does msmtp). It should be available on a wide range of systems. For now, hardcode the message headers and send mail to one recipient only. Set the X-Report header for simple filtering by mail clients.
Diffstat (limited to '')
-rwxr-xr-xlifeboat17
-rw-r--r--lifeboat.112
2 files changed, 28 insertions, 1 deletions
diff --git a/lifeboat b/lifeboat
index e84c916..b8724fc 100755
--- a/lifeboat
+++ b/lifeboat
@@ -18,6 +18,22 @@ usage() {
exit 1
}
+report_backup() {
+ cd "$LIFEBOAT_ROOT/$repo"
+
+ test -r config/recipient || errx "Could not read recipient from config/recipient"
+ read -r recipient < config/recipient
+ test -n "$recipient" || errx "No recipient given in config/recipient"
+
+ cat <<-EOF | sendmail "$recipient"
+ From: Lifeboat <lifeboat@$(hostname -f)>
+ Subject: lifeboat: backup for $(hostname) on $(date)
+ X-Report: lifeboat
+
+ $(run_backup 2>&1)
+ EOF
+}
+
run_backup() {
cd "$LIFEBOAT_ROOT/$repo"
@@ -75,5 +91,6 @@ export RESTIC_PASSWORD_FILE=$LIFEBOAT_ROOT/$repo/credentials/restic
case "$1" in
run) run_backup;;
+ run-report) report_backup;;
*) restic "$@";;
esac
diff --git a/lifeboat.1 b/lifeboat.1
index 1cbf61c..5d76ea1 100644
--- a/lifeboat.1
+++ b/lifeboat.1
@@ -1,4 +1,4 @@
-.Dd January 17, 2020
+.Dd April 30, 2021
.Dt LIFEBOAT 1
.Os
.Sh NAME
@@ -24,6 +24,11 @@ or as follows:
.Bl -tag -width Ds
.It Sy run
Create a snapshot for the specified repository.
+.It Sy run-report
+Like
+.Sy run ,
+but send any program output to the mail address specified in
+.Pa config/recipient .
.El
.Sh DIRECTORY STRUCTURE
.Nm
@@ -78,6 +83,11 @@ if the combined size of the repository is below 10G:
.Bd -literal -offset indent
nas:backups/ 10485760
.Ed
+.It Sy config/recipient
+A file containing the mail address of the recipient for backup reports.
+Only needed for the
+.Sy run-report
+command.
.It Sy credentials/restic
A file containing the password for the
.Xr restic 1