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

@ -1,4 +1,9 @@
{ config, lib, ... }: {
config,
pkgs,
lib,
...
}:
let let
backups = backups =
config.custom.services.restic.backups |> lib.attrValues |> lib.filter (backup: backup.enable); config.custom.services.restic.backups |> lib.attrValues |> lib.filter (backup: backup.enable);
@ -92,5 +97,16 @@ in
}; };
}) })
|> lib.listToAttrs; |> lib.listToAttrs;
environment.systemPackages =
let
backupAllScript = pkgs.writeShellApplication {
name = "restic-backup-all";
text = "systemctl start restic-backups-{${
backups |> lib.map (backup: backup.name) |> lib.concatStringsSep ","
}}";
};
in
[ backupAllScript ];
}; };
} }

View file

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