harmonize vpn, lan, and transmission ips
[distro-setup] / btrbk-run
index 014d85bbf92415d34b46da0eeb387c40e5e8fccc..057ff79b6ed052617209726ef39c293a3743bccc 100644 (file)
--- a/btrbk-run
+++ b/btrbk-run
@@ -65,6 +65,7 @@ conf_only=false
 dry_run=false # mostly for testing
 rate_limit=no
 verbose=true; verbose_arg=-v
+force=false
 if [[ $INVOCATION_ID ]]; then
   # INVOCATION_ID means running as a systemd service. we cant show progress in this case,
   # but if we pass the arg, it will insert mbuffer into the command.
@@ -91,7 +92,7 @@ cron=false
 fast=false
 kd_spread_maybe=false
 orig_args=("$@")
-temp=$(getopt -l cron,fast,pull-reexec,help 23ceikl:m:npqrs:t:vh "$@") || usage 1
+temp=$(getopt -l cron,fast,pull-reexec,help 23cefikl:m:npqrs:t:vh "$@") || usage 1
 eval set -- "$temp"
 while true; do
   case $1 in
@@ -110,6 +111,7 @@ while true; do
     -c) conf_only=true ;;
     # quit early, just btrbk, no extra remounting etc.
     -e) early=true ;;
+    -f) force=true ;;
     # skip various checks. when we run twice in a row for
     # switch mail-host, no need to repeat the same checks again.
     --fast) fast=true ;;
@@ -214,6 +216,9 @@ fi
 
 
 kd_spread=false
+if ! $cron && $kd_spread_maybe; then
+  kd_spread=true
+fi
 # set default targets
 if [[ ! -v targets && ! $source ]]; then
   if $cron; then
@@ -405,7 +410,7 @@ mkdir -p /var/log/btrbk
 # fine if they go back years.
 log_path=/var/log/btrbk/$(date +%F_%T%:::z).log
 echo copying output to $log_path
-exec &> >(tee -a $log_path)
+exec &> >(ts "%F %T" | tee -a $log_path)
 
 
 if $verbose; then
@@ -517,7 +522,7 @@ else
     # which is good enough.
     #
     # This is a separate ssh because the command can fail and thatis ok.
-    if $cron; then
+    if $cron && ! $force; then
       locked=false
       if lock_info=$(timeout -s 9 6 ssh $h DISPLAY=:0 xscreensaver-command -time); then
         if [[ $lock_info != *non-blanked* ]]; then
@@ -718,8 +723,13 @@ fi
 
 if [[ $ret == 0 ]]; then
   for tg in ${targets[@]}; do
+    h=$(ssh $tg hostname)
+    rsync -a -f"- */" -f"+ *" /var/log/btrbk/ root@$tg:/var/log/btrbk/$tg
     ssh root@$tg /usr/local/bin/mail-backup-clean
   done
+  if [[ $source ]]; then
+    rsync -a -f"- */" -f"+ *" $source:/var/log/btrbk/ /var/log/btrbk/$source
+  fi
 fi
 
 mexit $ret