restic: Add restic-backup-all and restic-restore-all scripts

This commit is contained in:
SebastianStork 2026-02-02 23:43:04 +01:00
parent a322ebb623
commit fe94d7f146
Signed by: SebastianStork
SSH key fingerprint: SHA256:tRrGdjYOwgHxpSc/wTOZQZEjxcb15P0tyXRsbAfd+2Q
2 changed files with 46 additions and 20 deletions

View file

@ -33,24 +33,34 @@ in
config = {
environment.systemPackages =
backupsWithRestoreCommand
|> lib.map (
backup:
let
inherit (backup) name conflictingService;
inherit (backup.restoreCommand) preRestore postRestore;
hasConflictingService = conflictingService != null;
in
pkgs.writeShellApplication {
name = "restic-restore-${name}";
text = ''
${lib.optionalString hasConflictingService "systemctl stop ${conflictingService}"}
${preRestore}
restic-${name} restore latest --target /
${postRestore}
${lib.optionalString hasConflictingService "systemctl start ${conflictingService}"}
'';
}
);
let
restoreScripts =
backupsWithRestoreCommand
|> lib.map (
backup:
let
inherit (backup) name conflictingService;
inherit (backup.restoreCommand) preRestore postRestore;
hasConflictingService = conflictingService != null;
in
pkgs.writeShellApplication {
name = "restic-restore-${name}";
text = ''
${lib.optionalString hasConflictingService "systemctl stop ${conflictingService}"}
${preRestore}
restic-${name} restore latest --target /
${postRestore}
${lib.optionalString hasConflictingService "systemctl start ${conflictingService}"}
'';
}
);
restoreAllScript = pkgs.writeShellApplication {
name = "restic-restore-all";
text =
backupsWithRestoreCommand |> lib.map (backup: "restic-restore-${backup.name}") |> lib.concatLines;
};
in
restoreScripts ++ [ restoreAllScript ];
};
}