git.iko.soy/typeable/nixpkgs
on master help sign in
restic: allow prune without backup

fixes #97820

commit13bee29b9b7e8dc04e6212ceb2704530d38c86a9 authorMatt McHenry <github@matt.mchenryfamily.org> dateFri 19 Mar 2021, 20:14 (6 years ago) parentef2ac47
2 files changed+14−5
nixos/modules/services/backup/restic.nix+8−5 nixos/tests/restic.nix+6
nixos/modules/services/backup/restic.nix+8−5
@@ -93,10 +93,12 @@ in
9393 };
9494
9595 paths = mkOption {
96− type = types.listOf types.str;
97− default = [];
96+ type = types.nullOr (types.listOf types.str);
97+ default = null;
9898 description = ''
99− Which paths to backup.
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.
100102 '';
101103 example = [
102104 "/var/lib/postgresql"
@@ -217,7 +219,7 @@ in
217219 resticCmd = "${pkgs.restic}/bin/restic${extraOptions}";
218220 filesFromTmpFile = "/run/restic-backups-${name}/includes";
219221 backupPaths = if (backup.dynamicFilesFrom == null)
220− then concatStringsSep " " backup.paths
222+ then if (backup.paths != null) then concatStringsSep " " backup.paths else ""
221223 else "--files-from ${filesFromTmpFile}";
222224 pruneCmd = optionals (builtins.length backup.pruneOpts > 0) [
223225 ( resticCmd + " forget --prune " + (concatStringsSep " " backup.pruneOpts) )
@@ -243,7 +245,8 @@ in
243245 restartIfChanged = false;
244246 serviceConfig = {
245247 Type = "oneshot";
246− ExecStart = [ "${resticCmd} backup --cache-dir=%C/restic-backups-${name} ${concatStringsSep " " backup.extraBackupArgs} ${backupPaths}" ] ++ pruneCmd;
248+ ExecStart = (optionals (backupPaths != "") [ "${resticCmd} backup --cache-dir=%C/restic-backups-${name} ${concatStringsSep " " backup.extraBackupArgs} ${backupPaths}" ])
249+ ++ pruneCmd;
247250 User = backup.user;
248251 RuntimeDirectory = "restic-backups-${name}";
249252 CacheDirectory = "restic-backups-${name}";
nixos/tests/restic.nix+6
@@ -45,6 +45,10 @@ import ./make-test-python.nix (
4545 '';
4646 inherit passwordFile initialize paths pruneOpts;
4747 };
48+ remoteprune = {
49+ inherit repository passwordFile;
50+ pruneOpts = [ "--keep-last 1" ];
51+ };
4852 };
4953
5054 environment.sessionVariables.RCLONE_CONFIG_LOCAL_TYPE = "local";
@@ -84,6 +88,8 @@ import ./make-test-python.nix (
8488 "systemctl start restic-backups-rclonebackup.service",
8589 '${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^4 snapshot"',
8690 '${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"',
8793 )
8894 '';
8995 }