backup-local.nix (957B)
1 { 2 pkgs, 3 domain, 4 ... 5 }: let 6 backup-local = pkgs.writeShellScriptBin "backup-local" '' 7 # variables 8 mount_points=("/mnt/" "/usb/") 9 report_file=("''${mount_points[1]}reports/$(date +"%Y-%m-%d_%H-%M").log") 10 # checks 11 for dir in "''${mount_points[@]}"; do 12 if ! findmnt -r "$dir" > /dev/null; then 13 echo "Error: $dir is not mounted. Exiting." >&2 14 exit 1 15 fi 16 done 17 if [ ! -w "''${mount_points[1]}" ]; then 18 echo "Error: No write permissions for destination. Exiting." >&2 19 exit 1 20 fi 21 printf "Mirroring from %s to %s.\n" "''${mount_points[0]}" "''${mount_points[1]}" 22 read -n1 -r -p "Press any key to begin..." key 23 # process 24 mkdir -p "$(dirname "$report_file")" 25 ${pkgs.rsync}/bin/rsync -avhP --delete --exclude=lost+found/ --exclude=reports/ "''${mount_points[0]}" "''${mount_points[1]}" 2>&1 | tee "$report_file" 26 ''; 27 in { 28 environment.systemPackages = [backup-local]; 29 }