286 current 2025-10-11 09:36:17 25.05.20251006.20c4598 6.12.50 *

This commit is contained in:
2025-10-11 09:51:41 -05:00
parent 8d5743c0bc
commit d258d95057

View File

@@ -5,6 +5,11 @@ let
borg = "${pkgs.borgbackup}/bin/borg";
backup_paths = lib.unique config.modules.system.backups.paths;
passwd_file = config.sops.secrets."borg_passwd".path;
jobs = {
sungger = { paths = [ "/var/lib/radarr" "/var/lib/sonarr" ]; };
hoass = { paths = [ "/var/lib/zigbee2mqtt" "/var/lib/hass" "/var/lib/mosquitto" ]; };
huh = { paths = [ "/home/blake/.nix" ]; };
};
in
{
options.modules.system.backups = {
@@ -15,16 +20,14 @@ in
description = "list of directories to back up";
};
jobs = lib.mkOption {
type = lib.types.attrsOf ( # the set up backup jobs
lib.types.attrsOf ( # the set of paths
lib.types.listOf lib.types.path # the paths
type = lib.types.nullOr (
lib.types.attrsOf ( # the set up backup jobs
lib.types.attrsOf ( # the set of paths
lib.types.listOf lib.types.path # the paths
)
)
);
default = {
sungger = { paths = [ "/var/lib/radarr" "/var/lib/sonarr" ]; };
hoass = { paths = [ "/var/lib/zigbee2mqtt" "/var/lib/hass" "/var/lib/mosquitto" ]; };
huh = { paths = [ "/home/blake/.nix" ]; };
};
default = null;
description = "Borg backup jobs; each job has a list of paths.";
};
repo = lib.mkOption {
@@ -41,6 +44,10 @@ in
config = lib.mkIf (cfg.enable && backup_paths != []) {
# systemd.tmpfiles.rules = [
# "d ${cfg.repo} 0755 root root"
# ];
systemd.services.backups = {
description = "backup service with borg!";
path = [ pkgs.borgbackup ];
@@ -59,14 +66,14 @@ in
borg init --encryption=repokey "$BORG_REPO"
fi
echo "starting backup run at $timestamp"
echo "Starting backup run at $timestamp"
# Loop over all jobs (attribute set keys)
${lib.concatStringsSep "\n\n" (lib.mapAttrsToList (bak_name: bak_paths:
${lib.concatStringsSep "\n\n" (lib.mapAttrsToList (jobName: jobCfg:
''
echo "------------- Backing up ${bak_name} -------------"
archive="${bak_name}-$timestamp"
echo "backing up paths: ${lib.concatStringsSep " " bak_paths.paths} $archive"
echo "=== Backing up ${jobName} ==="
archive="${jobName}-$timestamp"
echo "Backing up paths: ${lib.concatStringsSep " " jobCfg.paths} $archive"
borg create \
--verbose \
--filter AME \
@@ -75,18 +82,18 @@ in
--show-rc \
--compression lzma,9 \
"$BORG_REPO::$archive" \
${lib.concatStringsSep " " bak_paths.paths}
${lib.concatStringsSep " " jobCfg.paths}
echo "pruning old backups for ${bak_name}..."
echo "Pruning old backups for ${jobName}..."
borg prune -v --list "$BORG_REPO" \
--prefix "${bak_name}-" \
--prefix "${jobName}-" \
--keep-daily=7 \
--keep-weekly=52 \
--keep-monthly=-1
''
) cfg.jobs)}
) jobs)}
echo "finshed backup at \"$BORG_REPO::$archive\""
echo "Backup run complete at $timestamp."
'';
};
};