From 89362838dc385129246a2c42a0428de5a227edf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Tue, 5 Mar 2024 22:15:31 +0100 Subject: [PATCH] Fix backup-home service --- home/scripts/backup-home.sh | 19 ---------------- home/scripts/default.nix | 6 +---- home/services/backup-home.nix | 41 ++++++++++++++++++++++++++++++++--- 3 files changed, 39 insertions(+), 27 deletions(-) delete mode 100644 home/scripts/backup-home.sh diff --git a/home/scripts/backup-home.sh b/home/scripts/backup-home.sh deleted file mode 100644 index 9214274..0000000 --- a/home/scripts/backup-home.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -export RESTIC_PASSWORD="gunter.home.2rjus.net" -export RESTIC_REPOSITORY="rest:http://10.69.12.52:8000/gunter.home.2rjus.net" - -notify-send -e -t 3000 "Backup started" "Backup of /home/torjus started" -SECONDS=0 -restic backup /home/torjus \ - --exclude '/home/torjus/.cache' \ - --exclude '/home/torjus/.local/share/Steam' \ - --exclude '/home/torjus/git/nixpkgs' -retval=$? -if [ $retval -ne 0 ]; then - notify-send -u critical "Backup failed" "Backup of /home/torjus failed" - exit 1 -fi -restic forget -d 7 -w 4 -m 6 --prune - -notify-send -e -t 3000 "Backup completed" "Backup of /home/torjus completed in $SECONDS seconds." diff --git a/home/scripts/default.nix b/home/scripts/default.nix index 4f55b66..c4d0c1b 100644 --- a/home/scripts/default.nix +++ b/home/scripts/default.nix @@ -1,4 +1,4 @@ -{ config, ... }: { +{ pkgs, config, ... }: { home.file.".local/bin/hl-no-opacity" = { source = ./hl-no-opacity.sh; executable = true; @@ -11,8 +11,4 @@ source = ./randomwp.sh; executable = true; }; - home.file.".local/bin/backup-home" = { - source = ./backup-home.sh; - executable = true; - }; } diff --git a/home/services/backup-home.nix b/home/services/backup-home.nix index 7a9a173..400b7b8 100644 --- a/home/services/backup-home.nix +++ b/home/services/backup-home.nix @@ -1,4 +1,39 @@ -{ pkgs, ... }: { +{ pkgs, ... }: +let + # Backup home script + backup-home = pkgs.writeShellScriptBin "backup-home.sh" + '' + export RESTIC_PASSWORD="gunter.home.2rjus.net" + export RESTIC_REPOSITORY="rest:http://10.69.12.52:8000/gunter.home.2rjus.net" + + ${pkgs.libnotify}/bin/notify-send -e -t 3000 "Backup started" "Backup of /home/torjus started" + retval=$? + if [ $retval -ne 0 ]; then + echo "Failed to send notification" + exit 1 + fi + + SECONDS=0 + ${pkgs.restic}/bin/restic backup /home/torjus \ + --exclude '/home/torjus/.cache' \ + --exclude '/home/torjus/.local/share/Steam' \ + --exclude '/home/torjus/git/nixpkgs' + retval=$? + if [ $retval -ne 0 ]; then + notify-send -u critical "Backup failed" "Backup of /home/torjus failed" + exit 1 + fi + ${pkgs.restic}/bin/restic forget -d 7 -w 4 -m 6 --prune + + ${pkgs.libnotify}/bin/notify-send -e -t 3000 "Backup completed" "Backup of /home/torjus completed in $SECONDS seconds." + retval=$? + if [ $retval -ne 0 ]; then + echo "Failed to send notification" + exit 1 + fi + ''; +in +{ systemd.user.services.backup-home = { Unit = { Description = "Backup home directory"; @@ -6,7 +41,7 @@ }; Service = { Type = "oneshot"; - ExecStart = "/home/torjus/.local/bin/backup-home"; + ExecStart = "${backup-home}/bin/backup-home.sh"; }; }; systemd.user.timers.backup-home = { @@ -15,7 +50,7 @@ After = [ "network.target" ]; }; Timer = { - OnCalendar = "*-*-* 00:00:00"; + OnCalendar = "*-*-* 0,6,12,18:00:00"; Persistent = true; }; Install = {