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
}
- snap_list_cmds=()
local_snap_list_cmds=()
tg_snaps=()
source_snaps=()
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.*)
# 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
}
# 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
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 ))
#### end functions ####
+
+##### begin command line parsing ########
+
# latest $MAIL_HOST
if [[ -e /b/bash_unpublished/source-state ]]; then
source /b/bash_unpublished/source-state
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
# 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
## 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)