From 41c7fa448fbc81b8345d5cf2a8495fba253b879d Mon Sep 17 00:00:00 2001 From: Guillaume Girol Date: Thu, 13 May 2021 12:00:00 +0000 Subject: [PATCH] nixos/duplicity: add options to exercise all possible verbs except restore ;) --- nixos/modules/services/backup/duplicity.nix | 30 +++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/backup/duplicity.nix b/nixos/modules/services/backup/duplicity.nix index 42d78376d83..1f6883ed02b 100644 --- a/nixos/modules/services/backup/duplicity.nix +++ b/nixos/modules/services/backup/duplicity.nix @@ -84,7 +84,7 @@ in extraFlags = mkOption { type = types.listOf types.str; default = [ ]; - example = [ "--full-if-older-than" "1M" ]; + example = [ "--backend-retry-delay" "100" ]; description = '' Extra command-line flags passed to duplicity. See duplicity @@ -92,6 +92,20 @@ in ''; }; + fullIfOlderThan = mkOption { + type = types.str; + default = "never"; + example = "1M"; + description = '' + If "never" (the default) always do incremental + backups (the first backup will be a full backup, of course). If + "always" always do full backups. Otherwise, this + must be a string representing a duration. Full backups will be made + when the latest full backup is older than this duration. If this is not + the case, an incremental backup is performed. + ''; + }; + cleanup = { maxAge = mkOption { type = types.nullOr types.str; @@ -112,6 +126,16 @@ in associated incremental sets). ''; }; + maxIncr = mkOption { + type = types.nullOr types.int; + default = null; + example = 1; + description = '' + If non-null, delete incremental sets of all backups sets that are + older than the count:th last full backup (in other words, keep only + old full backups and not their increments). + ''; + }; }; }; @@ -133,10 +157,12 @@ in ${dup} cleanup ${target} --force ${extra} ${lib.optionalString (cfg.cleanup.maxAge != null) "${dup} remove-older-than ${lib.escapeShellArg cfg.cleanup.maxAge} ${target} --force ${extra}"} ${lib.optionalString (cfg.cleanup.maxFull != null) "${dup} remove-all-but-n-full ${toString cfg.cleanup.maxFull} ${target} --force ${extra}"} - exec ${dup} incr ${lib.escapeShellArgs ( + ${lib.optionalString (cfg.cleanup.maxIncr != null) "${dup} remove-all-incr-but-n-full ${toString cfg.cleanup.maxIncr} ${target} --force ${extra}"} + exec ${dup} ${if cfg.fullIfOlderThan == "always" then "full" else "incr"} ${lib.escapeShellArgs ( [ cfg.root cfg.targetUrl ] ++ concatMap (p: [ "--include" p ]) cfg.include ++ concatMap (p: [ "--exclude" p ]) cfg.exclude + ++ (lib.optionals (cfg.fullIfOlderThan != "never" && cfg.fullIfOlderThan != "always") [ "--full-if-older-than" cfg.fullIfOlderThan ]) )} ${extra} ''; serviceConfig = {