From: Ian Kelling Date: Thu, 9 Oct 2025 01:21:25 +0000 (-0400) Subject: bug fix pull & simplify. avoid 2d array with spaces + lines X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=b96cba78aab4ebaabda453ddf90d52be388a9e7f;p=distro-setup bug fix pull & simplify. avoid 2d array with spaces + lines --- diff --git a/filesystem/usr/local/bin/btrbk-run b/filesystem/usr/local/bin/btrbk-run index 7f5ee3f..f7486e3 100755 --- a/filesystem/usr/local/bin/btrbk-run +++ b/filesystem/usr/local/bin/btrbk-run @@ -24,6 +24,10 @@ # field, and we won't mount it. Need to figure out a solution that will # fix this. +# todo: I took out qr because I moved it to a different disk at home, +# and dont feel like updating this script to deal with that. Make sure +# it is getting backed up, maybe having just a backup of qr on my +# desktop is good enough. [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" @@ -171,6 +175,8 @@ EOF write-config() { + local q_mp=false + local -a tmp_mps cat >/etc/btrbk$conf_suf.conf <>/etc/btrbk$conf_suf.conf < 1 && tg_snap_count == orphan_mp_count )) - if (( tmp )) ; then - if [[ $source ]]; then - tg_host=$HOSTNAME - else - tg_host=$tg + for mp_tg_snap in "${mp_tg_snaps[@]}"; do + if [[ ! ${source_snaps[$mp_tg_snap]} ]]; then + orphan_tg_snaps+=("$tg_snap") + mp_orphan_tg_snaps+=("$tg_snap") fi - die "something went wrong checking orphans on $tg_host: for mountpoint ${mountpoints[$i]}, $orphan_mp_count. tg_snaps:${tg_snaps[*]}, source_snaps: ${!source_snaps[*]}" - fi + + ## sanity checking + tmp=$(( ${#mp_tg_snaps[@]} >= 1 && ${#mp_orphan_tg_snaps[@]} == ${#mp_tg_snaps[@]} )) + if (( tmp )) ; then + if [[ $source ]]; then + tg_host=$HOSTNAME + else + tg_host=$tg + fi + die "something went wrong checking orphans on $tg_host: for mountpoint: $mp, mp_tg_snaps: ${mp_tg_snaps[*]}, +source_snaps: ${!source_snaps[*]}" + fi + done + done } @@ -350,10 +387,10 @@ del-orphan-snaps() { fi else # we have targets for tg in ${targets[@]}; do - tmp_str=$(ssh root@$tg "shopt -s nullglob; echo $snap_list_glob") - mapfile -t tg_snaps <<<"$tmp_str" + tmpstr=$(ssh root@$tg "shopt -s nullglob; echo $snap_list_glob") + IFS=" " read -r -a tg_snaps <<<"$tmpstr" get-orphan-tg-snaps - tmp=$(( ${#orphan_tg_snaps[*]} >= 1 )) + tmp=$(( ${#orphan_tg_snaps[@]} >= 1 )) if (( tmp )); then d ssh root@$tg "btrfs sub del ${orphan_tg_snaps[*]}" fi @@ -379,6 +416,7 @@ fi # note q is owned by root:1000 +good_path_regex='^[-a-zA-Z0-9/._]+$' snap_path_regex='[a-z]/btrbk/[a-z]+\.[0-9]{8}T[0-9]{6}-[0-9]{4}$' declare -A source_snaps mountpoints=() @@ -392,7 +430,7 @@ dry_run=false # mostly for testing rate_limit=no # -q and just using the syslog option seemed nice, # but it doesn't show when a send has a parent and when it doesn't. -verbose=true; verbose_arg="-l trace" +verbose=false; verbose_arg= force=false if [[ $PPID == 1 || $INVOCATION_ID || $SYSTEMD_EXEC_PID ]]; then # running as a service. we cant show progress in this case, @@ -441,7 +479,7 @@ while true; do -3) conf_suf=3 ;; -a) # all moiuntpoints - mountpoints=(/a /o /qr /q) + mountpoints=(/a /o /q) ;; # only creates the config file, does not run btrbk -c) conf_only=true ;; @@ -648,24 +686,24 @@ else prospective_mps+=(/o) fi if [[ $source_host == "$HOST2" ]]; then - prospective_mps+=(/a /qr /q) + prospective_mps+=(/a /q) fi else if [[ $HOSTNAME == "$MAIL_HOST" ]]; then prospective_mps+=(/o) fi if [[ $HOSTNAME == "$HOST2" ]]; then - prospective_mps+=(/a /qr /q) + prospective_mps+=(/a /q) fi if $kd_spread; then - prospective_mps=(/a /o /qr /q) + prospective_mps=(/a /o /q) fi fi # If the above conditions didnt add any mountpoints, and host # status is empty, then add all mointpoints. This is a case of # doing something like kd_spread manually. if [[ ! ${prospective_mps[0]} && $source_host != "$HOST2" && $source_host != "$MAIL_HOST" && $HOSTNAME != "$MAIL_HOST" && $HOSTNAME != "$HOST2" ]]; then - prospective_mps=(/a /o /qr /q) + prospective_mps=(/a /o /q) fi # note: put q last just in case its specific retention options were to