nix-configs

Personal NixOS and home-manager configuration files
Log | Files | Refs

commit ea50fd6e765588bf3c2e1213b0f82841352c30fa
parent f49037f638ff0f45a0babca8cb56e71a55ab787d
Author: breadcat <breadcat@users.noreply.github.com>
Date:   Mon, 28 Jul 2025 13:05:11 +0100

Add local backup script

Cloud one comes next

Diffstat:
Ascripts/backup-local.nix | 29+++++++++++++++++++++++++++++
1 file changed, 29 insertions(+), 0 deletions(-)

diff --git a/scripts/backup-local.nix b/scripts/backup-local.nix @@ -0,0 +1,29 @@ +{ + pkgs, + domain, + ... +}: let + backup-local = pkgs.writeShellScriptBin "backup-local" '' + # variables + mount_points=("/mnt/" "/usb/") + report_file=("''${mount_points[1]}reports/$(date +"%Y-%m-%d_%H-%M").log") + # checks + for dir in "''${mount_points[@]}"; do + if ! findmnt -r "$dir" > /dev/null; then + echo "Error: $dir is not mounted. Exiting." >&2 + exit 1 + fi + done + if [ ! -w "''${mount_points[1]}" ]; then + echo "Error: No write permissions for destination. Exiting." >&2 + exit 1 + fi + printf "Mirroring from %s to %s.\n" "''${mount_points[0]}" "''${mount_points[1]}" + read -n1 -r -p "Press any key to begin..." key + # process + mkdir -p "$(dirname "$report_file")" + rsync -avhP --delete --exclude=lost+found/ --exclude=reports/ "''${mount_points[0]}" "''${mount_points[1]}" 2>&1 | tee "$report_file" + ''; +in { + environment.systemPackages = [backup-local]; +}