From 6bf2465adfc5f9dd0374754ee75aab2954acfb23 Mon Sep 17 00:00:00 2001 From: Nettika Date: Tue, 18 Jun 2024 15:40:17 -0700 Subject: [PATCH] Add notification for failed backups --- backup.nix | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/backup.nix b/backup.nix index f584414..4764dfe 100644 --- a/backup.nix +++ b/backup.nix @@ -1,6 +1,27 @@ { pkgs, config, ... }: { - environment.systemPackages = [pkgs.restic]; + environment.systemPackages = with pkgs; [ + restic + libnotify + ]; + + systemd.services = { + notify-backup-b2-failed = { + description = "Notify on failed backup to B2"; + serviceConfig = { + Type = "oneshot"; + User = "nettika"; + }; + environment = { + DBUS_SESSION_BUS_ADDRESS = "unix:path=/run/user/1000/bus"; + }; + path = [ pkgs.libnotify ]; + script = "notify-send -u critical \"Backup to B2 failed\" \"$(journalctl -u restic-backups-b2 -n 5 -o cat)\""; + }; + restic-backups-b2 = { + onFailure = ["notify-backup-b2-failed.service"]; + }; + }; services.restic.backups = { b2 = {