284 current 2025-10-11 08:13:32 25.05.20251006.20c4598 6.12.50 *
This commit is contained in:
@@ -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: 283 current 2025-10-11 06:19:49 25.05.20251006.20c4598 6.12.50 *
|
# generation: 284 current 2025-10-11 08:13:32 25.05.20251006.20c4598 6.12.50 *
|
||||||
{
|
{
|
||||||
description = "blakes nix config";
|
description = "blakes nix config";
|
||||||
inputs = {
|
inputs = {
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ let
|
|||||||
borg = "${pkgs.borgbackup}/bin/borg";
|
borg = "${pkgs.borgbackup}/bin/borg";
|
||||||
backup_paths = lib.unique config.modules.system.backups.paths;
|
backup_paths = lib.unique config.modules.system.backups.paths;
|
||||||
passwd_file = config.sops.secrets."borg_passwd".path;
|
passwd_file = config.sops.secrets."borg_passwd".path;
|
||||||
|
jobs = {
|
||||||
|
sungger = { paths = [ "/var/lib/radarr" "/var/lib/sonarr" ]; };
|
||||||
|
hoass = { paths = [ "/var/lib/zigbee2mqtt" "/var/lib/hass" "/var/lib/mosquitto" ]; };
|
||||||
|
huh = { paths = [ "/home/blake/.nix" ]; };
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.modules.system.backups = {
|
options.modules.system.backups = {
|
||||||
@@ -37,7 +42,6 @@ in
|
|||||||
path = [ pkgs.borgbackup ];
|
path = [ pkgs.borgbackup ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
EnvironmentFile = config.modules.system.backups.passphraseFile;
|
|
||||||
# the actual script borg is using
|
# the actual script borg is using
|
||||||
ExecStart = pkgs.writeShellScript "borg-backup" ''
|
ExecStart = pkgs.writeShellScript "borg-backup" ''
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@@ -47,30 +51,38 @@ in
|
|||||||
|
|
||||||
# Initialize repo if it doesn't exist
|
# Initialize repo if it doesn't exist
|
||||||
if ! borg info "$BORG_REPO" >/dev/null 2>&1; then
|
if ! borg info "$BORG_REPO" >/dev/null 2>&1; then
|
||||||
echo "init borg repo at $BORG_REPO"
|
echo "Initializing Borg repo at $BORG_REPO"
|
||||||
borg init --encryption=repokey "$BORG_REPO"
|
borg init --encryption=repokey "$BORG_REPO"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create backup
|
echo "Starting backup run at $timestamp"
|
||||||
echo "starting backup..."
|
|
||||||
borg create \
|
|
||||||
--verbose \
|
|
||||||
--filter AME \
|
|
||||||
--list \
|
|
||||||
--stats \
|
|
||||||
--show-rc \
|
|
||||||
--compression lzma,9 \
|
|
||||||
"$BORG_REPO::${toString config.networking.hostName}-$timestamp" \
|
|
||||||
${lib.concatStringsSep " " cfg.paths}
|
|
||||||
|
|
||||||
# Prune old backups according to retention policy
|
# Loop over all jobs (attribute set keys)
|
||||||
echo "Pruning old backups..."
|
${lib.concatStringsSep "\n\n" (lib.mapAttrsToList (jobName: jobCfg:
|
||||||
borg prune -v --list "$BORG_REPO" \
|
''
|
||||||
--keep-daily=7 \
|
echo "=== Backing up ${jobName} ==="
|
||||||
--keep-weekly=52 \
|
archive="${jobName}-$timestamp"
|
||||||
--keep-monthly=-1
|
echo "Backing up paths: ${lib.concatStringsSep " " jobCfg.paths} → $archive"
|
||||||
|
borg create \
|
||||||
|
--verbose \
|
||||||
|
--filter AME \
|
||||||
|
--list \
|
||||||
|
--stats \
|
||||||
|
--show-rc \
|
||||||
|
--compression lzma,9 \
|
||||||
|
"$BORG_REPO::$archive" \
|
||||||
|
${lib.concatStringsSep " " jobCfg.paths}
|
||||||
|
|
||||||
echo "$timestamp - backup completed successfully."
|
echo "Pruning old backups for ${jobName}..."
|
||||||
|
borg prune -v --list "$BORG_REPO" \
|
||||||
|
--prefix "${jobName}-" \
|
||||||
|
--keep-daily=7 \
|
||||||
|
--keep-weekly=52 \
|
||||||
|
--keep-monthly=-1
|
||||||
|
''
|
||||||
|
) jobs)}
|
||||||
|
|
||||||
|
echo "Backup run complete at $timestamp."
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,13 +28,14 @@ map ] half-down
|
|||||||
# files & archives
|
# files & archives
|
||||||
map ad mkdir
|
map ad mkdir
|
||||||
map af mkfile
|
map af mkfile
|
||||||
|
map ab mkbak
|
||||||
map ae extract
|
map ae extract
|
||||||
map aa archive
|
map aa archive
|
||||||
|
|
||||||
# trash
|
# trash
|
||||||
map gt cd ~/.local/share/Trash/files
|
map gt cd ~/.local/share/Trash/files
|
||||||
map <delete> trash
|
map <delete> trash
|
||||||
map <s-delete> $trash-restore
|
map <s-delete> $trash restore
|
||||||
|
|
||||||
# --- functions ---
|
# --- functions ---
|
||||||
|
|
||||||
@@ -78,7 +79,7 @@ cmd archive %{{
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
# move files to trash
|
# move files to trash
|
||||||
cmd trash %IFS="$(printf '\n\t')"; trash-put $fx
|
cmd trash %IFS="$(printf '\n\t')"; trash put $fx
|
||||||
|
|
||||||
# make a directory
|
# make a directory
|
||||||
cmd mkdir %{{
|
cmd mkdir %{{
|
||||||
@@ -100,4 +101,10 @@ cmd mkfile %{{
|
|||||||
fi
|
fi
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
# make backup
|
||||||
|
cmd mkbak %{{
|
||||||
|
for x in $fx; do
|
||||||
|
cp $x $x.bak
|
||||||
|
done
|
||||||
|
|
||||||
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user