restic: add dynamicFilesFrom
This commit is contained in:
parent
c6994e90dc
commit
1c9684abd6
@ -120,6 +120,17 @@ in
|
||||
"--keep-yearly 75"
|
||||
];
|
||||
};
|
||||
|
||||
dynamicFilesFrom = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
description = ''
|
||||
A script that produces a list of files to back up. The
|
||||
results of this command are given to the '--files-from'
|
||||
option.
|
||||
'';
|
||||
example = "find /home/matt/git -type d -name .git";
|
||||
};
|
||||
};
|
||||
}));
|
||||
default = {};
|
||||
@ -151,6 +162,25 @@ in
|
||||
let
|
||||
extraOptions = concatMapStrings (arg: " -o ${arg}") backup.extraOptions;
|
||||
resticCmd = "${pkgs.restic}/bin/restic${extraOptions}";
|
||||
filesFromTmpFile = "/run/restic-backups-${name}/includes";
|
||||
preStartInit = if backup.initialize
|
||||
then "${resticCmd} snapshots || ${resticCmd} init"
|
||||
else "";
|
||||
dynamicFilesFromScript = pkgs.writeScript "dynamicFilesFromScript" backup.dynamicFilesFrom;
|
||||
preStartFiles = if backup.dynamicFilesFrom != null
|
||||
then "${dynamicFilesFromScript} > ${filesFromTmpFile}"
|
||||
else "";
|
||||
preStartAttr = if (backup.initialize || backup.dynamicFilesFrom != null)
|
||||
then {
|
||||
preStart = ''
|
||||
${preStartInit}
|
||||
${preStartFiles}
|
||||
'';
|
||||
}
|
||||
else {};
|
||||
backupPaths = if (backup.dynamicFilesFrom == null)
|
||||
then concatStringsSep " " backup.paths
|
||||
else "--files-from ${filesFromTmpFile}";
|
||||
pruneCmd = if (builtins.length backup.pruneOpts > 0)
|
||||
then [ ( resticCmd + " forget --prune " +
|
||||
(concatStringsSep " " backup.pruneOpts) )
|
||||
@ -167,14 +197,17 @@ in
|
||||
restartIfChanged = false;
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = [ "${resticCmd} backup ${concatStringsSep " " backup.extraBackupArgs} ${concatStringsSep " " backup.paths}" ] ++ pruneCmd;
|
||||
ExecStart = [ "${resticCmd} backup ${concatStringsSep " " backup.extraBackupArgs} ${backupPaths}" ] ++ pruneCmd;
|
||||
User = backup.user;
|
||||
RuntimeDirectory = "restic-backups-${name}";
|
||||
} // optionalAttrs (backup.s3CredentialsFile != null) {
|
||||
EnvironmentFile = backup.s3CredentialsFile;
|
||||
};
|
||||
} // optionalAttrs backup.initialize {
|
||||
preStart = ''
|
||||
${resticCmd} snapshots || ${resticCmd} init
|
||||
}
|
||||
// preStartAttr
|
||||
// optionalAttrs (backup.dynamicFilesFrom != null) {
|
||||
postStart = ''
|
||||
rm ${filesFromTmpFile}
|
||||
'';
|
||||
})
|
||||
) config.services.restic.backups;
|
||||
|
Loading…
Reference in New Issue
Block a user