Merge pull request #188881 from shadaj/patch-4

nixos/restic: make it possible to use the existing backup cache for prune/check

Changed files
+18 -2
nixos
modules
services
backup
tests
+14 -2
nixos/modules/services/backup/restic.nix
···
];
};
dynamicFilesFrom = mkOption {
type = with types; nullOr str;
default = null;
···
then if (backup.paths != null) then concatStringsSep " " backup.paths else ""
else "--files-from ${filesFromTmpFile}";
pruneCmd = optionals (builtins.length backup.pruneOpts > 0) [
-
(resticCmd + " forget --prune " + (concatStringsSep " " backup.pruneOpts))
-
(resticCmd + " check")
];
# Helper functions for rclone remotes
rcloneRemoteName = builtins.elemAt (splitString ":" backup.repository) 1;
···
];
};
+
checkOpts = mkOption {
+
type = types.listOf types.str;
+
default = [ ];
+
description = lib.mdDoc ''
+
A list of options for 'restic check', which is run after
+
pruning.
+
'';
+
example = [
+
"--with-cache"
+
];
+
};
+
dynamicFilesFrom = mkOption {
type = with types; nullOr str;
default = null;
···
then if (backup.paths != null) then concatStringsSep " " backup.paths else ""
else "--files-from ${filesFromTmpFile}";
pruneCmd = optionals (builtins.length backup.pruneOpts > 0) [
+
(resticCmd + " forget --prune --cache-dir=%C/restic-backups-${name} " + (concatStringsSep " " backup.pruneOpts))
+
(resticCmd + " check --cache-dir=%C/restic-backups-${name} " + (concatStringsSep " " backup.checkOpts))
];
# Helper functions for rclone remotes
rcloneRemoteName = builtins.elemAt (splitString ":" backup.repository) 1;
+4
nixos/tests/restic.nix
···
package = pkgs.writeShellScriptBin "restic" ''
echo "$@" >> /tmp/fake-restic.log;
'';
};
};
···
'${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"',
"systemctl start restic-backups-custompackage.service",
"grep 'backup .* /opt' /tmp/fake-restic.log",
"timedatectl set-time '2017-12-13 13:45'",
"systemctl start restic-backups-remotebackup.service",
"rm /opt/backupCleanupCommand",
···
package = pkgs.writeShellScriptBin "restic" ''
echo "$@" >> /tmp/fake-restic.log;
'';
+
+
pruneOpts = [ "--keep-last 1" ];
+
checkOpts = [ "--some-check-option" ];
};
};
···
'${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"',
"systemctl start restic-backups-custompackage.service",
"grep 'backup .* /opt' /tmp/fake-restic.log",
+
"grep 'check .* --some-check-option' /tmp/fake-restic.log",
"timedatectl set-time '2017-12-13 13:45'",
"systemctl start restic-backups-remotebackup.service",
"rm /opt/backupCleanupCommand",