From e862b7a5b28de96c426b2c105718519caf204039 Mon Sep 17 00:00:00 2001 From: Timo Wilken Date: Sun, 25 Aug 2024 19:11:54 +0200 Subject: Send mail output for some mcron jobs For mcron jobs that only output text when they fail, mail that output. --- tw/services/restic.scm | 68 ++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 33 deletions(-) (limited to 'tw/services/restic.scm') diff --git a/tw/services/restic.scm b/tw/services/restic.scm index f23da013..2ea8c084 100644 --- a/tw/services/restic.scm +++ b/tw/services/restic.scm @@ -249,24 +249,25 @@ true." prune? keep-last keep-hourly keep-daily keep-weekly keep-monthly keep-yearly keep-within) #~(job #$schedule - #$(program-file - ;; Make cron commands for different repos easier to distinguish. - (string-append "restic-cleanup-" (repo-path-basename repo) "-command") - #~(begin - #$(set-restic-variables repo password) - (execl #$(file-append restic "/bin/restic") - "restic" "forget" - #$(restic-cache-policy repo) - #$@(arg-with-value "--prune" prune?) - #$@(arg-with-value "--host" snapshot-host) - #$@(arg-with-value "--path" snapshot-paths) - #$@(arg-with-value "--keep-within" keep-within) - #$@(arg-with-value "--keep-last" keep-last) - #$@(arg-with-value "--keep-hourly" (norm-keep keep-hourly)) - #$@(arg-with-value "--keep-daily" (norm-keep keep-daily)) - #$@(arg-with-value "--keep-weekly" (norm-keep keep-weekly)) - #$@(arg-with-value "--keep-monthly" (norm-keep keep-monthly)) - #$@(arg-with-value "--keep-yearly" (norm-keep keep-yearly))))) + (with-mail-out + #$(program-file + ;; Make cron commands for different repos easier to distinguish. + (string-append "restic-cleanup-" (repo-path-basename repo) "-command") + #~(begin + #$(set-restic-variables repo password) + (execl #$(file-append restic "/bin/restic") + "restic" "forget" "--quiet" + #$(restic-cache-policy repo) + #$@(arg-with-value "--prune" prune?) + #$@(arg-with-value "--host" snapshot-host) + #$@(arg-with-value "--path" snapshot-paths) + #$@(arg-with-value "--keep-within" keep-within) + #$@(arg-with-value "--keep-last" keep-last) + #$@(arg-with-value "--keep-hourly" (norm-keep keep-hourly)) + #$@(arg-with-value "--keep-daily" (norm-keep keep-daily)) + #$@(arg-with-value "--keep-weekly" (norm-keep keep-weekly)) + #$@(arg-with-value "--keep-monthly" (norm-keep keep-monthly)) + #$@(arg-with-value "--keep-yearly" (norm-keep keep-yearly)))))) #$@(if (maybe-value-set? user) (list #:user user) '())))) (map cronjob configs)) @@ -314,21 +315,22 @@ must be given. Leading @code{~/} are replaced with @code{$HOME}.") (define (cronjob config) (match-record config (schedule paths repo password tags restic) #~(job #$schedule - #$(program-file "restic-backup-command" - #~(begin - (use-modules (ice-9 popen) - (ice-9 textual-ports) - (srfi srfi-1)) - (define (replace-home path) - (if (string-prefix? "~/" path) - (string-replace path (getenv "HOME") 0 1) - path)) - #$(set-restic-variables repo password) - (apply execl #$(file-append restic "/bin/restic") - "restic" "backup" - #$(restic-cache-policy repo) - #$@(append-map (lambda (tag) (list "--tag" tag)) tags) - (map replace-home '#$paths))))))) + (with-mail-out + #$(program-file "restic-backup-command" + #~(begin + (use-modules (ice-9 popen) + (ice-9 textual-ports) + (srfi srfi-1)) + (define (replace-home path) + (if (string-prefix? "~/" path) + (string-replace path (getenv "HOME") 0 1) + path)) + #$(set-restic-variables repo password) + (apply execl #$(file-append restic "/bin/restic") + "restic" "backup" "--quiet" + #$(restic-cache-policy repo) + #$@(append-map (lambda (tag) (list "--tag" tag)) tags) + (map replace-home '#$paths)))))))) (map cronjob configs)) (define home-restic-backup-service-type -- cgit v1.2.3