From e5d6add5e592902c4d77405c0189315e863f3486 Mon Sep 17 00:00:00 2001 From: Enno Richter Date: Mon, 30 Dec 2024 11:14:15 +0100 Subject: [PATCH] mb4: update borgbackup cfg --- modules/home/borgbackup.nix | 63 +++++++++++++++++++------------ modules/home/macos-enno.nix | 75 +++++++++++++++++-------------------- 2 files changed, 74 insertions(+), 64 deletions(-) diff --git a/modules/home/borgbackup.nix b/modules/home/borgbackup.nix index 67255ca8..23d0aa82 100644 --- a/modules/home/borgbackup.nix +++ b/modules/home/borgbackup.nix @@ -12,6 +12,12 @@ let # Write each exclude pattern to a new line pkgs.writeText "excludefile" (concatStringsSep "\n" cfg.exclude); + mkKeepArgs = + cfg: + # If cfg.prune.keep e.g. has a yearly attribute, + # its content is passed on as --keep-yearly + lib.concatStringsSep " " (lib.mapAttrsToList (x: y: "--keep-${x}=${toString y}") cfg.prune.keep); + mkBackupScript = cfg: '' @@ -97,9 +103,12 @@ let mkWrapperDrv { original = "${pkgs.borgbackup}/bin/borg"; name = "borg-job-${name}"; - set = { - BORG_REPO = cfg.repo; - } // (mkPassEnv cfg) // cfg.environment; + set = + { + BORG_REPO = cfg.repo; + } + // (mkPassEnv cfg) + // cfg.environment; }; mkBackupLaunchdAgent = @@ -107,23 +116,26 @@ let nameValuePair "borgbackup-job-${name}" { enable = true; config = { - EnvironmentVariables = { - BORG_REPO = cfg.repo; - PATH = lib.makeBinPath ( - with pkgs; - [ - coreutils - borgbackup - openssh - ] - ); - inherit (cfg) - extraArgs - extraInitArgs - extraCreateArgs - extraPruneArgs - ; - } // (mkPassEnv cfg) // cfg.environment; + EnvironmentVariables = + { + BORG_REPO = cfg.repo; + PATH = lib.makeBinPath ( + with pkgs; + [ + coreutils + borgbackup + openssh + ] + ); + inherit (cfg) + extraArgs + extraInitArgs + extraCreateArgs + extraPruneArgs + ; + } + // (mkPassEnv cfg) + // cfg.environment; LowPriorityBackgroundIO = true; ProcessType = "Background"; Program = toString (pkgs.writeShellScript "borgbackup-script-${name}" (mkBackupScript cfg)); @@ -155,7 +167,7 @@ let (mkPassEnv cfg) // cfg.environment ) )} - ${mkBackupScript cfg} + ${mkBackupScript cfg} "$@" ''; in { @@ -448,9 +460,12 @@ in with config.ptsd.borgbackup; { - home.packages = [ - pkgs.borgbackup - ] ++ (mapAttrsToList mkBorgWrapper jobs) ++ (mapAttrsToList mkManualBackupScript jobs); + home.packages = + [ + pkgs.borgbackup + ] + ++ (mapAttrsToList mkBorgWrapper jobs) + ++ (mapAttrsToList mkManualBackupScript jobs); launchd.agents = mapAttrs' mkBackupLaunchdAgent jobs; diff --git a/modules/home/macos-enno.nix b/modules/home/macos-enno.nix index 56e3262c..019a64db 100644 --- a/modules/home/macos-enno.nix +++ b/modules/home/macos-enno.nix @@ -64,7 +64,7 @@ in kubectl kubernetes-helm mkcert - ncdu_1 + ncdu nix-melt nix-top nix-tree @@ -150,53 +150,40 @@ in BORG_RELOCATED_REPO_ACCESS_IS_OK = "yes"; BORG_RSH = "ssh -i ${homeDirectory}/.ssh/nwbackup.id_ed25519"; }; - exclude = [ - "${homeDirectory}/.Trash" - "${homeDirectory}/.cache" - "${homeDirectory}/.diffusionbee" - "${homeDirectory}/.flair" - "${homeDirectory}/.ollama/models" - "${homeDirectory}/.orbstack" - "${homeDirectory}/Applications" - "${homeDirectory}/Downloads" - "${homeDirectory}/Downloads-Keep" - "${homeDirectory}/Library" - "${homeDirectory}/OrbStack" - "${homeDirectory}/Pictures/Photos Library.photoslibrary" - "${homeDirectory}/Sync/rpi4-dl" # no backup - "${homeDirectory}/repos/convexio/.minio" - "${homeDirectory}/repos/convexio/.minio-prod" - "${homeDirectory}/repos/flutter/bin/cache" - "${homeDirectory}/repos/llama.cpp/models" - "${homeDirectory}/repos/stable-vicuna-13b-delta" - "${homeDirectory}/repos/stable-vicuna-13b-delta/*.bin" - "${homeDirectory}/repos/tauri-app/src-tauri/target" - "${homeDirectory}/repos/whisper.cpp/models" - "${homeDirectory}/roms" # no backup - "*.pyc" - "*.qcow2" - "sh:${homeDirectory}/**/.cache" - "sh:${homeDirectory}/**/node_modules" - #"${homeDirectory}/Library/Caches" - #"${homeDirectory}/Library/Trial" - #"sh:${homeDirectory}/Library/Containers/*/Data/Library/Caches" - ]; + prune = { + keep = { + within = "1d"; # Keep all archives from the last day + daily = 7; + weekly = 4; + monthly = -1; # Keep at least one archive for each month + }; + }; in { hetzner = { - inherit encryption environment exclude; - paths = [ "${homeDirectory}" ]; + inherit encryption environment prune; + paths = [ + "${homeDirectory}/.config" + "${homeDirectory}/Desktop" + "${homeDirectory}/Documents" + "${homeDirectory}/Maildir" + "${homeDirectory}/Movies" + "${homeDirectory}/Music" + "${homeDirectory}/Pictures" + "${homeDirectory}/Recordings" + "${homeDirectory}/Sync" + "${homeDirectory}/Templates" + ]; repo = "ssh://u267169-sub2@u267169.your-storagebox.de:23/./borg"; compression = "zstd,3"; postCreate = ''${pkgs.borg2prom}/bin/borg2prom --archive-name "$archiveName" --job-name hetzner --push''; }; hetzner-documents = { - inherit encryption environment; + inherit encryption environment prune; paths = [ "${config.xdg.dataHome}/paperless" "${homeDirectory}/Documents" - "${homeDirectory}/Documents-Luisa" "${homeDirectory}/Sync/Scans-Enno" "${homeDirectory}/Sync/Scans-Laiyer" "${homeDirectory}/Sync/Scans-Luisa" @@ -208,11 +195,19 @@ in }; rpi4 = { - inherit encryption environment; - exclude = exclude ++ [ - "${homeDirectory}/Sync" # backed up via syncthing + inherit encryption environment prune; + paths = [ + "${homeDirectory}/.config" + "${homeDirectory}/Desktop" + "${homeDirectory}/Documents" + "${homeDirectory}/Maildir" + "${homeDirectory}/Movies" + "${homeDirectory}/Music" + "${homeDirectory}/Pictures" + "${homeDirectory}/Recordings" + "${homeDirectory}/Sync" + "${homeDirectory}/Templates" ]; - paths = [ "${homeDirectory}" ]; repo = "ssh://borg-mb4@rpi4.pug-coho.ts.net/./"; # repo = "ssh://borg-mb4@rpi4.fritz.box/./"; compression = "zstd,3";