Skip to content

Commit

Permalink
mb4: update borgbackup cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
elohmeier committed Dec 30, 2024
1 parent c609e6d commit e5d6add
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 64 deletions.
63 changes: 39 additions & 24 deletions modules/home/borgbackup.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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:
''
Expand Down Expand Up @@ -97,33 +103,39 @@ 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 =
name: cfg:
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));
Expand Down Expand Up @@ -155,7 +167,7 @@ let
(mkPassEnv cfg) // cfg.environment
)
)}
${mkBackupScript cfg}
${mkBackupScript cfg} "$@"
'';
in
{
Expand Down Expand Up @@ -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;

Expand Down
75 changes: 35 additions & 40 deletions modules/home/macos-enno.nix
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ in
kubectl
kubernetes-helm
mkcert
ncdu_1
ncdu
nix-melt
nix-top
nix-tree
Expand Down Expand Up @@ -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://[email protected]: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"
Expand All @@ -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://[email protected]/./";
# repo = "ssh://[email protected]/./";
compression = "zstd,3";
Expand Down

0 comments on commit e5d6add

Please sign in to comment.