mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 21:50:33 +03:00
restic: add support for pruning
This commit is contained in:
parent
6f7c3fbff7
commit
c6994e90dc
1 changed files with 23 additions and 1 deletions
|
@ -103,6 +103,23 @@ in
|
||||||
Create the repository if it doesn't exist.
|
Create the repository if it doesn't exist.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pruneOpts = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [];
|
||||||
|
description = ''
|
||||||
|
A list of options (--keep-* et al.) for 'restic forget
|
||||||
|
--prune', to automatically prune old snapshots. The
|
||||||
|
'forget' command is run *after* the 'backup' command, so
|
||||||
|
keep that in mind when constructing the --keep-* options.
|
||||||
|
'';
|
||||||
|
example = [
|
||||||
|
"--keep-daily 7"
|
||||||
|
"--keep-weekly 5"
|
||||||
|
"--keep-monthly 12"
|
||||||
|
"--keep-yearly 75"
|
||||||
|
];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
default = {};
|
default = {};
|
||||||
|
@ -134,6 +151,11 @@ in
|
||||||
let
|
let
|
||||||
extraOptions = concatMapStrings (arg: " -o ${arg}") backup.extraOptions;
|
extraOptions = concatMapStrings (arg: " -o ${arg}") backup.extraOptions;
|
||||||
resticCmd = "${pkgs.restic}/bin/restic${extraOptions}";
|
resticCmd = "${pkgs.restic}/bin/restic${extraOptions}";
|
||||||
|
pruneCmd = if (builtins.length backup.pruneOpts > 0)
|
||||||
|
then [ ( resticCmd + " forget --prune " +
|
||||||
|
(concatStringsSep " " backup.pruneOpts) )
|
||||||
|
( resticCmd + " check" ) ]
|
||||||
|
else [];
|
||||||
in nameValuePair "restic-backups-${name}" ({
|
in nameValuePair "restic-backups-${name}" ({
|
||||||
environment = {
|
environment = {
|
||||||
RESTIC_PASSWORD_FILE = backup.passwordFile;
|
RESTIC_PASSWORD_FILE = backup.passwordFile;
|
||||||
|
@ -145,7 +167,7 @@ in
|
||||||
restartIfChanged = false;
|
restartIfChanged = false;
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
ExecStart = "${resticCmd} backup ${concatStringsSep " " backup.extraBackupArgs} ${concatStringsSep " " backup.paths}";
|
ExecStart = [ "${resticCmd} backup ${concatStringsSep " " backup.extraBackupArgs} ${concatStringsSep " " backup.paths}" ] ++ pruneCmd;
|
||||||
User = backup.user;
|
User = backup.user;
|
||||||
} // optionalAttrs (backup.s3CredentialsFile != null) {
|
} // optionalAttrs (backup.s3CredentialsFile != null) {
|
||||||
EnvironmentFile = backup.s3CredentialsFile;
|
EnvironmentFile = backup.s3CredentialsFile;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue