From c09d9a5e9ddfa1342b548fa260360baa946179b7 Mon Sep 17 00:00:00 2001 From: Ahwx Date: Tue, 7 Oct 2025 13:04:21 +0200 Subject: [PATCH] feat: adds `borgbackup` job for `grafana` --- modules/services/grafana.nix | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/modules/services/grafana.nix b/modules/services/grafana.nix index e55d70c..e5eaa61 100644 --- a/modules/services/grafana.nix +++ b/modules/services/grafana.nix @@ -1,4 +1,13 @@ -{ config, ... }: +{ + config, + host, + username, + pkgs, + ... +}: +let + baseRepo = "ssh://liv@dandelion:9123/spinners/rootvol/backups/${host}"; +in { services = { grafana = { @@ -19,5 +28,30 @@ proxyWebsockets = true; }; }; + borgbackup.jobs."violet-grafana" = { + paths = [ "/var/lib/grafana" ]; + repo = "${baseRepo}/var-grafana"; + encryption.mode = "none"; + compression = "auto,zstd"; + startAt = "daily"; + preHook = '' + systemctl stop grafana + ''; + postHook = '' + systemctl start grafana + if [ $exitStatus -eq 2 ]; then + ${pkgs.ntfy-sh}/bin/ntfy send https://notify.liv.town/${host} "borgbackup: ${host} backup (grafana) failed with errors" + else + ${pkgs.ntfy-sh}/bin/ntfy send https://notify.liv.town/${host} "borgbackup: ${host} backup (grafana) completed succesfully with exit status $exitStatus" + fi + ''; + user = "root"; + extraCreateArgs = [ + "--stats" + ]; + environment = { + BORG_RSH = "ssh -p 9123 -i /home/${username}/.ssh/id_ed25519"; + }; + }; }; }