restic: allow prune without backup

fixes #97820

authored by

Matt McHenry and committed by helbling.dev 13bee29b ef2ac476

+14 -5
+8 -5
nixos/modules/services/backup/restic.nix
··· 93 }; 94 95 paths = mkOption { 96 - type = types.listOf types.str; 97 - default = []; 98 description = '' 99 - Which paths to backup. 100 ''; 101 example = [ 102 "/var/lib/postgresql" ··· 217 resticCmd = "${pkgs.restic}/bin/restic${extraOptions}"; 218 filesFromTmpFile = "/run/restic-backups-${name}/includes"; 219 backupPaths = if (backup.dynamicFilesFrom == null) 220 - then concatStringsSep " " backup.paths 221 else "--files-from ${filesFromTmpFile}"; 222 pruneCmd = optionals (builtins.length backup.pruneOpts > 0) [ 223 ( resticCmd + " forget --prune " + (concatStringsSep " " backup.pruneOpts) ) ··· 243 restartIfChanged = false; 244 serviceConfig = { 245 Type = "oneshot"; 246 - ExecStart = [ "${resticCmd} backup --cache-dir=%C/restic-backups-${name} ${concatStringsSep " " backup.extraBackupArgs} ${backupPaths}" ] ++ pruneCmd; 247 User = backup.user; 248 RuntimeDirectory = "restic-backups-${name}"; 249 CacheDirectory = "restic-backups-${name}";
··· 93 }; 94 95 paths = mkOption { 96 + type = types.nullOr (types.listOf types.str); 97 + default = null; 98 description = '' 99 + Which paths to backup. If null or an empty array, no 100 + backup command will be run. This can be used to create a 101 + prune-only job. 102 ''; 103 example = [ 104 "/var/lib/postgresql" ··· 219 resticCmd = "${pkgs.restic}/bin/restic${extraOptions}"; 220 filesFromTmpFile = "/run/restic-backups-${name}/includes"; 221 backupPaths = if (backup.dynamicFilesFrom == null) 222 + then if (backup.paths != null) then concatStringsSep " " backup.paths else "" 223 else "--files-from ${filesFromTmpFile}"; 224 pruneCmd = optionals (builtins.length backup.pruneOpts > 0) [ 225 ( resticCmd + " forget --prune " + (concatStringsSep " " backup.pruneOpts) ) ··· 245 restartIfChanged = false; 246 serviceConfig = { 247 Type = "oneshot"; 248 + ExecStart = (optionals (backupPaths != "") [ "${resticCmd} backup --cache-dir=%C/restic-backups-${name} ${concatStringsSep " " backup.extraBackupArgs} ${backupPaths}" ]) 249 + ++ pruneCmd; 250 User = backup.user; 251 RuntimeDirectory = "restic-backups-${name}"; 252 CacheDirectory = "restic-backups-${name}";
+6
nixos/tests/restic.nix
··· 45 ''; 46 inherit passwordFile initialize paths pruneOpts; 47 }; 48 }; 49 50 environment.sessionVariables.RCLONE_CONFIG_LOCAL_TYPE = "local"; ··· 84 "systemctl start restic-backups-rclonebackup.service", 85 '${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^4 snapshot"', 86 '${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots -c | grep -e "^4 snapshot"', 87 ) 88 ''; 89 }
··· 45 ''; 46 inherit passwordFile initialize paths pruneOpts; 47 }; 48 + remoteprune = { 49 + inherit repository passwordFile; 50 + pruneOpts = [ "--keep-last 1" ]; 51 + }; 52 }; 53 54 environment.sessionVariables.RCLONE_CONFIG_LOCAL_TYPE = "local"; ··· 88 "systemctl start restic-backups-rclonebackup.service", 89 '${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^4 snapshot"', 90 '${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots -c | grep -e "^4 snapshot"', 91 + "systemctl start restic-backups-remoteprune.service", 92 + '${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"', 93 ) 94 ''; 95 }