20 current 2025-10-07 00:49:35 25.05.20251001.5b5be50 6.12.49 *

This commit is contained in:
2025-10-07 14:21:24 -05:00
parent eb98778b64
commit 03d62685eb

View File

@@ -14,7 +14,7 @@ in
}; };
repo = lib.mkOption { repo = lib.mkOption {
type = lib.types.path; type = lib.types.path;
default = "/backups"; default = "/holocron/borg";
description = "borg repository path"; description = "borg repository path";
}; };
passphraseFile = lib.mkOption { passphraseFile = lib.mkOption {
@@ -30,33 +30,40 @@ in
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
EnvironmentFile = config.modules.system.backups.passphraseFile; EnvironmentFile = config.modules.system.backups.passphraseFile;
}; ExecStart = pkgs.writeShellScript "borg-backup" ''
script = '' set -euo pipefail
set -eux export BORG_PASSPHRASE="$(cat ${passwd_file})"
export BORG_REPO=${config.modules.system.backups.repo} export BORG_REPO="${cfg.repo}"
export BORG_PASSPHRASE="$(cat ${config.modules.system.backups.passphraseFile})"
# Initialize repo if it doesnt exist # Initialize repo if it doesn't exist
if ! ${borg} info "${repo}" >/dev/null 2>&1; then if ! borg info "$BORG_REPO" >/dev/null 2>&1; then
echo "Initializing new Borg repository at ${repo}" echo "init borg repo at $BORG_REPO"
${borg} init --encryption=repokey "${repo}" borg init --encryption=repokey "$BORG_REPO"
fi fi
timestamp=$(date +%Y-%m-%d_%H-%M-%S) # Create backup
echo "starting backup..."
${borg} create \ borg create \
--verbose \
--filter AME \
--list \
--stats \ --stats \
--compression zstd,3 \ --show-rc \
::${timestamp} \ --compression lz4 \
${lib.concatStringsSep " " backup_paths} "$BORG_REPO::$(hostname)-$(date +'%Y-%m-%dT%H:%M:%S')" \
${lib.concatStringsSep " " cfg.paths}
# Retention policy # Prune old backups according to retention policy
${borg} prune -v --list \ echo "Pruning old backups..."
borg prune -v --list "$BORG_REPO" \
--keep-daily=7 \ --keep-daily=7 \
--keep-weekly=52 \ --keep-weekly=52 \
--keep-monthly=-1 --keep-monthly=-1
echo "Backup completed successfully."
''; '';
}; };
};
systemd.timers.borg-backup = { systemd.timers.borg-backup = {
description = "daily borg backup timer"; description = "daily borg backup timer";
@@ -71,5 +78,5 @@ in
}; };
} }
# add to module # add to modules
# modules.system.backups.paths = lib.mkIf cfg.backups [ <path> ]; # modules.system.backups.paths = lib.mkIf cfg.backups [ <path> ];