fix backup script to fucking work bro exit 0 my ass and add mode selector

This commit is contained in:
2025-10-12 19:19:23 -05:00
parent 39c108b3ee
commit 758ab5beb1
2 changed files with 9 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
# flake for blakes nixos config # flake for blakes nixos config
# define new devices in outputs # define new devices in outputs
# generation: 374, timestamp: 2025-10-12 18:59:25 # generation: 375, timestamp: 2025-10-12 19:19:04
{ {
description = "blakes nix config"; description = "blakes nix config";
inputs = { inputs = {

View File

@@ -27,9 +27,6 @@ in
default = {}; default = {};
description = "backup jobs, nested attribute sets should be <bak_name> = paths [<list_of_paths>]"; description = "backup jobs, nested attribute sets should be <bak_name> = paths [<list_of_paths>]";
}; };
paths = lib.mkOption {
type = lib.types.list;
};
repo = lib.mkOption { repo = lib.mkOption {
type = lib.types.path; type = lib.types.path;
default = "/holocron/borg"; default = "/holocron/borg";
@@ -40,6 +37,11 @@ in
default = sec."borg_passwd".path; default = sec."borg_passwd".path;
description = "borg repository passphrase file"; description = "borg repository passphrase file";
}; };
mode = lib.mkOption {
type = lib.types.string;
default = "split"; # "all"
description = "choice between creating one archive of all paths or one archive per service";
};
}; };
config = lib.mkIf (cfg.enable && cfg.baks != {}) { config = lib.mkIf (cfg.enable && cfg.baks != {}) {
@@ -56,7 +58,7 @@ in
export BORG_PASSPHRASE="$(cat ${cfg.passwd_file})" export BORG_PASSPHRASE="$(cat ${cfg.passwd_file})"
export BORG_REPO="${cfg.repo}" export BORG_REPO="${cfg.repo}"
timestamp="$(date +'%Y-%m-%d_%H:%M:%S')" timestamp="$(date +'%Y-%m-%d_%H:%M:%S')"
mode=sep mode=${cfg.mode}
# init repo in needed # init repo in needed
if ! borg info "$BORG_REPO" >/dev/null 2>&1; then if ! borg info "$BORG_REPO" >/dev/null 2>&1; then
@@ -68,7 +70,7 @@ in
echo "starting backup at $timestamp" echo "starting backup at $timestamp"
if [ "$mode" = "sep" ]; then if [ "$mode" = "split" ]; then
# loop for each backup # loop for each backup
${lib.concatStringsSep "\n\n" (lib.mapAttrsToList (bak_name: bak_paths: ${lib.concatStringsSep "\n\n" (lib.mapAttrsToList (bak_name: bak_paths:
'' ''
@@ -91,9 +93,9 @@ in
--keep-weekly=52 \ --keep-weekly=52 \
--keep-monthly=-1 --keep-monthly=-1
echo "backup run complete at \"$BORG_REPO::$archive\"" echo "backup run complete at \"$BORG_REPO::$archive\""
exit 0
'' ''
) cfg.baks)} ) cfg.baks)}
exit 0
else else
# flatten all paths from cfg.baks into one big list # flatten all paths from cfg.baks into one big list
all_paths="${ all_paths="${