From ba823b8961aa070e7f76d5a64223a6432a47afc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Fri, 4 Oct 2024 01:16:39 +0200 Subject: [PATCH] Add forget option --- backup.nix | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backup.nix b/backup.nix index 93a1a29..eda4a72 100644 --- a/backup.nix +++ b/backup.nix @@ -28,6 +28,11 @@ let echo "$output" fi done + if [ "$BACKUP_FORGET" -eq 1 ]; then + echo "Removing old backups" + output=$(restic forget -d 7 -w 4 -m 6 --keep-within 1d --prune) + echo "$output" + fi exit "$exit_code"; ''; }; @@ -60,6 +65,11 @@ in default = 0; description = "Randomized delay in seconds to spread out backups."; }; + forget = lib.mkOption { + type = lib.types.bool; + default = true; + description = "Run restic forget after backup."; + }; }; config = lib.mkIf cfg.enable { systemd.services."backup-helper" = { @@ -69,6 +79,7 @@ in { RESTIC_REPOSITORY = cfg.restic-repository; BACKUP_HELPER_DIRS = lib.strings.concatStringsSep "," cfg.backup-dirs; + BACKUP_FORGET = if cfg.forget then "1" else "0"; } // lib.attrsets.optionalAttrs (builtins.hasAttr "password-file" cfg) { RESTIC_PASSWORD_FILE = cfg.password-file;