snapshot /home also hourly

This commit is contained in:
Motiejus Jakštys 2024-07-29 16:31:32 +03:00
parent 7970c36801
commit 9e301158fa
2 changed files with 45 additions and 25 deletions

View File

@ -81,18 +81,20 @@ in
btrfssnapshot = {
enable = true;
subvolumes = {
"/home" = {
subvolumes = [
{
subvolume = "/home";
label = "5minutely";
keep = 12;
refreshInterval = "*:0/5";
};
#"/home" = {
# label = "hourly";
# keep = 24;
# refreshInterval = "*:00:00";
#};
};
}
{
subvolume = "/home";
label = "hourly";
keep = 24;
refreshInterval = "*:00:00";
}
];
};
wifibackup = {

View File

@ -6,6 +6,9 @@
}:
let
cfg = config.mj.services.btrfssnapshot;
svcName =
subvol: label:
"btrfs-snapshot-${lib.strings.sanitizeDerivationName subvol}-${lib.strings.sanitizeDerivationName label}";
in
{
options.mj.services.btrfssnapshot = {
@ -15,8 +18,9 @@ in
default = { };
type =
with lib.types;
attrsOf (submodule {
listOf (submodule {
options = {
subvolume = lib.mkOption { type = str; };
label = lib.mkOption { type = str; };
keep = lib.mkOption { type = int; };
refreshInterval = lib.mkOption { type = str; };
@ -27,22 +31,36 @@ in
config = lib.mkIf cfg.enable {
systemd = {
services = lib.mapAttrs' (
subvolume: params:
lib.nameValuePair "btrfs-snapshot-${lib.strings.sanitizeDerivationName subvolume}" {
description = "${params.label} btrfs snapshot for ${subvolume} (keep ${builtins.toString params.keep})";
serviceConfig.ExecStart = "${pkgs.btrfs-auto-snapshot}/bin/btrfs-auto-snapshot --verbose --label=${params.label} --keep=${builtins.toString params.keep} ${subvolume}";
}
) cfg.subvolumes;
timers = lib.mapAttrs' (
subvolume: params:
lib.nameValuePair "btrfs-snapshot-${lib.strings.sanitizeDerivationName subvolume}" {
description = "${params.label} btrfs snapshot for ${subvolume}";
timers = lib.listToAttrs (
map (
params:
lib.nameValuePair (svcName params.subvolume params.label) {
description = "${params.label} btrfs snapshot for ${params.subvolume}";
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = params.refreshInterval;
}
) cfg.subvolumes;
) cfg.subvolumes
);
services = lib.listToAttrs (
map (
params:
lib.nameValuePair (svcName params.subvolume params.label) {
description = "${params.label} btrfs snapshot for ${params.subvolume} (keep ${builtins.toString params.keep})";
serviceConfig = {
Type = "oneshot";
ExecStart = ''
${pkgs.btrfs-auto-snapshot}/bin/btrfs-auto-snapshot \
--verbose \
--label=${params.label} \
--keep=${builtins.toString params.keep} \
${params.subvolume}'';
};
}
) cfg.subvolumes
);
};
};
}