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