From ff50a9b4a158bb543d77c3d4aeca1acbbf92d0dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Sun, 2 Jun 2024 23:50:20 +0200 Subject: [PATCH] Improve backup script --- backup.nix | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/backup.nix b/backup.nix index d21cafd..d2df465 100644 --- a/backup.nix +++ b/backup.nix @@ -5,16 +5,26 @@ let name = "restic-wrapper"; runtimeInputs = [ pkgs.restic - pkgs.systemd ]; text = '' if [ -z "$BACKUP_HELPER_DIRS" ]; then - echo "BACKUP_HELPER_DIRS is not set"; + echo "BACKUP_HELPER_DIRS is not set" exit 1; fi + exit_code=0; for i in ''${BACKUP_HELPER_DIRS//,/ }; do echo "Starting backup of $i"; + output=$(restic backup "$i" && rc=$? || rc=$?); + if [ $rc -ne 0 ]; then + echo "Backup of $i failed with exit code $rc:" + echo "$output" + exit_code="$rc" + else + echo "Backup of $i successful:" + echo "$output" + fi done + exit "$exit_code"; ''; }; in