From: Ian Kelling Date: Fri, 26 Jul 2024 13:50:50 +0000 (-0400) Subject: btrbk fix X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=26f0f9f6c69f420413f7e54ad221dea950a4f8a1;p=distro-setup btrbk fix --- diff --git a/btrbk-run b/btrbk-run index f7a7c4a..155ee16 100644 --- a/btrbk-run +++ b/btrbk-run @@ -44,7 +44,7 @@ install-my-scripts. EOF echo "top of script file:" - sed -n '1,/^[# ]*end command line/{p;b};q' "$0" + sed -n '/^[# ]*begin command line/,/^[# ]*end command line/{p;b};q' "$0" exit $1 } @@ -229,7 +229,6 @@ EOF - snap_list_cmds=() local_snap_list_cmds=() tg_snaps=() source_snaps=() @@ -245,8 +244,7 @@ EOF esac sub=${m#/} - snap_list_cmds+=("echo $vol/btrbk/$sub.*;") - local_snap_list_cmds+=("echo $vol/btrbk/$sub.*") + snap_list_glob+=" $vol/btrbk/$sub.*" if [[ $source ]]; then tmp_a=($vol/btrbk/$sub.*) @@ -304,7 +302,12 @@ get-orphan-tg-snaps() { # sanity checking tmp=$(( tg_snap_count > 1 && tg_snap_count == orphan_mp_count )) if (( tmp )) ; then - die "something went wrong checking orphans on $tg: for mountpoint ${mountpoints[$i]}, $orphan_mp_count" + if [[ $source ]]; then + tg_host=$HOSTNAME + else + tg_host=$tg + 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 done } @@ -319,11 +322,15 @@ get-orphan-tg-snaps() { # a missing source subvol error, so lets avoid it. del-orphan-snaps() { if [[ $source ]]; then - tmpstr=$(ssh root@$source "shopt -s nullglob; ${snap_list_cmds[*]}") + tmpstr=$(ssh root@$source "shopt -s nullglob; echo $snap_list_glob") + if [[ ! $tmpstr ]]; then + die "got empty string when listing source subvolumes" + fi IFS=" " read -r -a source_snap_list <<<"$tmpstr" for snap in "${source_snap_list[@]}"; do source_snaps[$snap]=t done + # tg_snaps was set earlier get-orphan-tg-snaps tmp=$(( ${#orphan_tg_snaps[*]} >= 1 )) if (( tmp )); then @@ -331,7 +338,7 @@ del-orphan-snaps() { fi else # we have targets for tg in ${targets[@]}; do - tmp_str=$(ssh root@$tg "shopt -s nullglob; ${snap_list_cmds[*]}") + tmp_str=$(ssh root@$tg "shopt -s nullglob; echo $snap_list_glob") mapfile -t tg_snaps <<<"$tmp_str" get-orphan-tg-snaps tmp=$(( ${#orphan_tg_snaps[*]} >= 1 )) @@ -344,6 +351,9 @@ del-orphan-snaps() { #### end functions #### + +##### begin command line parsing ######## + # latest $MAIL_HOST if [[ -e /b/bash_unpublished/source-state ]]; then source /b/bash_unpublished/source-state @@ -580,8 +590,10 @@ if [[ ! -v targets && ! $source ]]; then targets+=(kd.b8.nz) fi wireless_home_hosts=( - x2 - sy + # out of comission for now + #x2 + # sy is so temp + #sy so ) for h in ${wireless_home_hosts[@]}; do @@ -719,10 +731,10 @@ fi # print some non-default opts if $verbose; then opts_show=() - if ! $conf_only; then + if $conf_only; then opts_show+=(conf_only=true) fi - if ! $dry_run; then + if $dry_run; then opts_show+=(dry_run=true) fi if [[ $rate_limit != no ]]; then @@ -954,11 +966,11 @@ fi ## run extra commands on targets -local_snaps=$(${local_snap_list_cmds[*]}) +local_snaps=$(echo $snap_list_glob) if [[ $ret == 0 ]]; then for tg in ${targets[@]}; do h=$(ssh $tg hostname) - remote_snaps=$(ssh root@$tg "shopt -s nullglob; ${snap_list_cmds[*]}") + remote_snaps=$(ssh root@$tg "shopt -s nullglob; echo $snap_list_glob") # a check like this will catch the situation we aim to prevent by running purge if [[ $local_snaps != "$remote_snaps" ]]; then localtmp=$(mktemp)