From: Ian Kelling Date: Thu, 3 Oct 2024 03:29:00 +0000 (-0400) Subject: fix backup logic bug plus minor improvements X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=2a8b84aa4f3c8f52bc27c24a025f9c0436f90c03;p=distro-setup fix backup logic bug plus minor improvements --- diff --git a/filesystem/usr/local/bin/btrbk-run b/filesystem/usr/local/bin/btrbk-run index 8693406..36872fe 100755 --- a/filesystem/usr/local/bin/btrbk-run +++ b/filesystem/usr/local/bin/btrbk-run @@ -596,12 +596,12 @@ fi at_work=false at_home=false +set-location # set default targets if [[ ! -v targets && ! $source ]]; then exit-if-no-default-targets - set-location if $at_home; then if ! $kd_spread && [[ $HOSTNAME != x3 ]]; then add-x3-target @@ -651,7 +651,7 @@ else *) prospective_mps=() if [[ $source ]]; then - source_state="$(ssh $source 'cat /a/bin/bash_unpublished/source-state; echo source_host=$HOSTNAME')" + source_state="$(ssh root@$source 'cat /a/bin/bash_unpublished/source-state; echo source_host=$HOSTNAME')" eval "$source_state" # shellcheck disable=SC2154 # assigned in the above eval. if [[ $source_host == "$MAIL_HOST" ]]; then @@ -721,8 +721,8 @@ ssh_timeout="timeout -s 9 $(( 6 * wait_factor ))" # todo: this has a timing problem, since btrbk.timer could activate the service after this check. if ! $fast && [[ $source ]]; then - if [[ $(ssh $source ps --no-headers -o comm 1) == systemd ]]; then - status=$(ssh $source systemctl is-active btrbk.service) || : # normally returns 3 + if [[ $(ssh root@$source ps --no-headers -o comm 1) == systemd ]]; then + status=$(ssh root@$source systemctl is-active btrbk.service) || : # normally returns 3 case $status in inactive|failed) : ;; *) @@ -897,7 +897,7 @@ df --output=size,pcent / | tail -n1" locked=false # note Invalid MIT-MAGIC-COOKIE-1 keyxscreensaver-command: can't open display :0 is expected if # the system is locked by greeter. - if lock_info=$($ssh_timeout ssh $h DISPLAY=:0 xscreensaver-command -time); then + if lock_info=$($ssh_timeout ssh $h DISPLAY=:0 xscreensaver-command -time 2>/dev/null); then if [[ $lock_info != *non-blanked* ]]; then locked=true fi @@ -1003,8 +1003,11 @@ local_snaps=$(echo $snap_list_glob) if [[ $ret == 0 ]]; then for tg in ${targets[@]}; do # todo: get this in ssh_info, less sshing is faster. - h=$(ssh $tg hostname) - remote_snaps=$(ssh root@$tg "shopt -s nullglob; echo $snap_list_glob") + tmpstr=$(ssh root@$tg "shopt -s nullglob; hostname; echo $snap_list_glob") + { + read -r h + read -r remote_snaps + } <<<"$tmpstr" # a check like this will catch the situation we aim to prevent by running purge if [[ $local_snaps != "$remote_snaps" ]]; then localtmp=$(mktemp) @@ -1026,7 +1029,7 @@ EOF rm $localtmp $remotetmp ret=1 fi - if $laptop && ! $at_home && [[ $h == $d_host && $HOSTNAME == "$MAIL_HOST" ]]; then + if $laptop && ! $at_home && [[ $h == "$d_host" && $HOSTNAME == "$MAIL_HOST" ]]; then d ssh root@$tg 'btrbk-spread-wrap &>/dev/null