fixes and qd for better source subvol error repo
[distro-setup] / btrbk-run
index 057ff79b6ed052617209726ef39c293a3743bccc..f8618809e859ddbbbf378b86a56624c00a70c7b4 100644 (file)
--- a/btrbk-run
+++ b/btrbk-run
@@ -90,7 +90,7 @@ targets=()
 early=false
 cron=false
 fast=false
-kd_spread_maybe=false
+kd_spread=false
 orig_args=("$@")
 temp=$(getopt -l cron,fast,pull-reexec,help 23cefikl:m:npqrs:t:vh "$@") || usage 1
 eval set -- "$temp"
@@ -116,15 +116,15 @@ while true; do
     # switch mail-host, no need to repeat the same checks again.
     --fast) fast=true ;;
     -i) incremental_strict=true ;;
-    # note this implies resume
-    -k) kd_spread_maybe=true ;;
+    # note this implies resume, cron and -p
+    -k) kd_spread=true ;;
     # bytes per second, suffix k m g
     -l) rate_limit=$2; shift ;;
     # Comma separated mountpoints to backup. This has defaults set below.
     -m) IFS=, mountpoints=($2); unset IFS; shift ;;
     -n) dry_run=true ;;
-    # hide progress
-    -p) progress_arg= ;;
+    # preserve existing snapshots and backups
+    -p) preserve_arg=-p ;;
     # internal option for rerunning under newer SOURCE_HOST version.
     --pull-reexec) pull_reexec=true;;
     # quiet
@@ -152,11 +152,16 @@ done
 
 cmd_arg="$1"
 
-if $kd_spread_maybe; then
+if $kd_spread; then
   if [[ $cmd_arg && $cmd_arg != resume ]]; then
     die "dont pass -k without resume or empty run arg"
   fi
+  if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
+    die "something went wrong, -k not meant to be run on MAIL_HOST"
+  fi
   cmd_arg=resume
+  preserve_arg=-p
+  cron=true
 fi
 
 if [[ ! $cmd_arg ]]; then
@@ -214,41 +219,11 @@ fi
 # targets, plus any given on the command line.
 
 
-
-kd_spread=false
-if ! $cron && $kd_spread_maybe; then
-  kd_spread=true
-fi
 # set default targets
 if [[ ! -v targets && ! $source ]]; then
-  if $cron; then
-    if [[ $HOSTNAME != "$MAIL_HOST" ]]; then
-      if $kd_spread_maybe && [[ $HOSTNAME == kd && $MAIL_HOST == x3 ]]; then
-        if ping -q -c1 -w1 x3.office.fsf.org &>/dev/null; then
-          work_host=x3.office.fsf.org
-        elif ping -q -c1 -w1 x3wg.b8.nz &>/dev/null; then
-          work_host=x3wg.b8.nz
-        fi
-        if [[ $work_host ]]; then
-          source_state="$(ssh $work_host cat /a/bin/bash_unpublished/source-state)"
-          eval "$source_state"
-          if [[ $MAIL_HOST == x3 ]]; then
-            kd_spread=true
-          else
-            # x3 was the mail host, but it moved to some other machine
-            # without updating us yet.
-            echo "MAIL_HOST=$MAIL_HOST, nothing to do"
-            mexit 0
-          fi
-        else
-          echo "MAIL_HOST=$MAIL_HOST, nothing to do"
-          mexit 0
-        fi
-      else
-        echo "MAIL_HOST=$MAIL_HOST, nothing to do"
-        mexit 0
-      fi
-    fi
+  if $cron && ! $kd_spread && [[ $HOSTNAME != "$MAIL_HOST" ]]; then
+    echo "MAIL_HOST=$MAIL_HOST, nothing to do"
+    mexit 0
   fi
 
   at_work=false
@@ -290,22 +265,20 @@ if [[ ! -v targets && ! $source ]]; then
             targets+=(x3wg.b8.nz)
           fi
         fi
-        # temporarily disabled while doing recovery
-        #        for h in frodo kd; do
-        for h in kd; do
-          if [[ $HOSTNAME == "$h" ]]; then
-            continue
-          fi
-          targets+=($h.b8.nz)
-        done
-        for h in x2 sy; do
-          if [[ $HOSTNAME == "$h" ]]; then
-            continue
-          fi
-          if ping -q -c1 -w1 $h.b8.nz &>/dev/null; then
-            targets+=($h.b8.nz)
-          elif ping -q -c1 -w1 ${h}w.b8.nz &>/dev/null; then
-            targets+=(${h}w.b8.nz)
+        if [[ $HOSTNAME != kd ]]; then
+          targets+=(kd.b8.nz)
+        fi
+        wireless_home_hosts=(
+          x2
+          sy
+        )
+        for h in ${wireless_home_hosts[@]}; do
+          if [[ $HOSTNAME != "$h" ]]; then
+            if ping -q -c1 -w1 $h.b8.nz &>/dev/null; then
+              targets+=($h.b8.nz)
+            elif ping -q -c1 -w1 ${h}w.b8.nz &>/dev/null; then
+              targets+=(${h}w.b8.nz)
+            fi
           fi
         done
       elif $at_work; then
@@ -347,17 +320,17 @@ else
             prospective_mps+=(/o)
           fi
           if [[ $source_host == "$HOST2" ]]; then
-            prospective_mps+=(/a /ar /qr /q)
+            prospective_mps+=(/a /ar /qr /qd /q)
           fi
         else
           if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
             prospective_mps+=(/o)
           fi
           if [[ $HOSTNAME == "$HOST2" ]]; then
-            prospective_mps+=(/a /ar /qr /q)
+            prospective_mps+=(/a /ar /qr /qd /q)
           fi
           if $kd_spread; then
-            prospective_mps=(/a /ar /o /qr /q)
+            prospective_mps=(/a /ar /o /qr /qd /q)
           fi
         fi
         # note: put q last just in case its specific retention options were to
@@ -724,6 +697,9 @@ fi
 if [[ $ret == 0 ]]; then
   for tg in ${targets[@]}; do
     h=$(ssh $tg hostname)
+    if [[ $h == kd && $HOSTNAME == x3 && $HOSTNAME == "$MAIL_HOST" ]]; then
+      ssh root$tg systemctl --no-block start btrbk-spread
+    fi
     rsync -a -f"- */" -f"+ *" /var/log/btrbk/ root@$tg:/var/log/btrbk/$tg
     ssh root@$tg /usr/local/bin/mail-backup-clean
   done