modules/backup: add command for backup management
This commit is contained in:
parent
25677a9e03
commit
06ef7a4d80
@ -67,6 +67,31 @@ let
|
|||||||
}
|
}
|
||||||
) jobTargetPairs);
|
) jobTargetPairs);
|
||||||
|
|
||||||
|
backupCommands = map ({jobName, jobOptions, targetName, targetOptions}: let
|
||||||
|
jobPasswordFile = if jobOptions.passwordFile == null then config.age.secrets."clerie-backup-job-${jobName}".path else jobOptions.passwordFile;
|
||||||
|
repoPath = if jobOptions.repoPath == null then "/${config.networking.hostName}/${jobName}" else jobOptions.repoPath;
|
||||||
|
targetPasswordFile = if targetOptions.passwordFile == null then config.age.secrets."clerie-backup-target-${targetName}".path else targetOptions.passwordFile;
|
||||||
|
targetUsername = if targetOptions.username == null then config.networking.hostName else targetOptions.username;
|
||||||
|
in pkgs.writeShellApplication {
|
||||||
|
name = "clerie-backup-${jobName}-${targetName}";
|
||||||
|
|
||||||
|
runtimeInputs = [ pkgs.restic ];
|
||||||
|
|
||||||
|
text = ''
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
export RESTIC_PASSWORD_FILE=${jobPasswordFile}
|
||||||
|
export RESTIC_REPOSITORY="rest:https://${targetUsername}:$(cat ${targetPasswordFile})@${targetOptions.serverName}${repoPath}"
|
||||||
|
export RESTIC_PROGRESS_FPS=0.1
|
||||||
|
export RESTIC_CACHE_DIR=/var/cache/restic
|
||||||
|
|
||||||
|
restic "$@"
|
||||||
|
'';
|
||||||
|
|
||||||
|
checkPhase = "";
|
||||||
|
}
|
||||||
|
) jobTargetPairs;
|
||||||
|
|
||||||
targetOptions = { ... }: {
|
targetOptions = { ... }: {
|
||||||
options = {
|
options = {
|
||||||
passwordFile = mkOption {
|
passwordFile = mkOption {
|
||||||
@ -129,5 +154,6 @@ in
|
|||||||
systemd.tmpfiles.rules = [
|
systemd.tmpfiles.rules = [
|
||||||
"d /var/cache/restic - - - - -"
|
"d /var/cache/restic - - - - -"
|
||||||
];
|
];
|
||||||
|
environment.systemPackages = backupCommands;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user