20 current 2025-10-07 00:49:35 25.05.20251001.5b5be50 6.12.49 *
This commit is contained in:
@@ -14,7 +14,7 @@ in
|
||||
};
|
||||
repo = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
default = "/backups";
|
||||
default = "/holocron/borg";
|
||||
description = "borg repository path";
|
||||
};
|
||||
passphraseFile = lib.mkOption {
|
||||
@@ -30,33 +30,40 @@ in
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
EnvironmentFile = config.modules.system.backups.passphraseFile;
|
||||
};
|
||||
script = ''
|
||||
set -eux
|
||||
export BORG_REPO=${config.modules.system.backups.repo}
|
||||
export BORG_PASSPHRASE="$(cat ${config.modules.system.backups.passphraseFile})"
|
||||
ExecStart = pkgs.writeShellScript "borg-backup" ''
|
||||
set -euo pipefail
|
||||
export BORG_PASSPHRASE="$(cat ${passwd_file})"
|
||||
export BORG_REPO="${cfg.repo}"
|
||||
|
||||
# Initialize repo if it doesn’t exist
|
||||
if ! ${borg} info "${repo}" >/dev/null 2>&1; then
|
||||
echo "Initializing new Borg repository at ${repo}"
|
||||
${borg} init --encryption=repokey "${repo}"
|
||||
# Initialize repo if it doesn't exist
|
||||
if ! borg info "$BORG_REPO" >/dev/null 2>&1; then
|
||||
echo "init borg repo at $BORG_REPO"
|
||||
borg init --encryption=repokey "$BORG_REPO"
|
||||
fi
|
||||
|
||||
timestamp=$(date +%Y-%m-%d_%H-%M-%S)
|
||||
|
||||
${borg} create \
|
||||
# Create backup
|
||||
echo "starting backup..."
|
||||
borg create \
|
||||
--verbose \
|
||||
--filter AME \
|
||||
--list \
|
||||
--stats \
|
||||
--compression zstd,3 \
|
||||
::${timestamp} \
|
||||
${lib.concatStringsSep " " backup_paths}
|
||||
--show-rc \
|
||||
--compression lz4 \
|
||||
"$BORG_REPO::$(hostname)-$(date +'%Y-%m-%dT%H:%M:%S')" \
|
||||
${lib.concatStringsSep " " cfg.paths}
|
||||
|
||||
# Retention policy
|
||||
${borg} prune -v --list \
|
||||
# Prune old backups according to retention policy
|
||||
echo "Pruning old backups..."
|
||||
borg prune -v --list "$BORG_REPO" \
|
||||
--keep-daily=7 \
|
||||
--keep-weekly=52 \
|
||||
--keep-monthly=-1
|
||||
|
||||
echo "Backup completed successfully."
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
systemd.timers.borg-backup = {
|
||||
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> ];
|
||||
|
||||
Reference in New Issue
Block a user