btrbk fixes
authorIan Kelling <ian@iankelling.org>
Wed, 17 Feb 2021 06:30:11 +0000 (01:30 -0500)
committerIan Kelling <ian@iankelling.org>
Wed, 17 Feb 2021 06:36:50 +0000 (01:36 -0500)
btrbk-run
mount-latest-subvol

index 9587ce967d9d21229d9ee576cb6d5f18246c3aca..2b21e82608fee2cdcfe9fb2795ee1cd36e81490f 100644 (file)
--- a/btrbk-run
+++ b/btrbk-run
@@ -164,6 +164,7 @@ if [[ ! -v targets && ! $source ]]; then
 
   at_work=false
 
+  targets=(frodo.b8.nz)
   case $HOSTNAME in
     kw)
       at_work=true
@@ -182,21 +183,21 @@ if [[ ! -v targets && ! $source ]]; then
       fi
       ;;&
     kw)
-      targets=($home x3)
+      targets+=($home x3)
       ;;
     x2|x3)
-      targets=($home kw.office.fsf.org)
+      targets+=($home kw.office.fsf.org)
       ;;
     kd)
-      # todo: add frodo when it comes back online
-      targets=(x2.b8.nz frodo.b8.nz)
+      targets+=(x2.b8.nz)
       # might not be connected to the vpn
       if timeout -s 9 6 ssh kw.office.fsf.org :; then
         targets+=(kw.office.fsf.org)
       fi
       ;;
     frodo)
-      : # no targets
+      # no targets
+      targets=()
       ;;
     *)
       die "error: no default targets for this host, use -t"
@@ -266,7 +267,7 @@ echo "mountpoints: ${mountpoints[*]}"
 ##### end command line parsing ########
 
 if [[ $source ]]; then
-  if [[ $(ssh $source systemctl is-active btrbk.service) != inactive ]]; then
+  if [[ $(ssh $source ps --no-headers -o comm 1) == systemd && $(ssh $source systemctl is-active btrbk.service) != inactive ]]; then
     echo "$0: error: cron btrbk is running on source. exiting out of caution"
     mexit 1
   fi
@@ -425,15 +426,15 @@ EOF
   fi
 done
 
-if $amy; then
-  # to manually backup amy,
-  # bbk -e -s amy -m root_ubuntubionic
-  cat >>/etc/btrbk.conf <<'EOF'
-volume ssh://amy/mnt/root
-subvolume root_ubuntubionic
-target send-receive /mnt/root/btrbk
-EOF
-fi
+if $amy; then
+  # to manually backup amy,
+  # bbk -e -s amy -m root_ubuntubionic
+  cat >>/etc/btrbk.conf <<'EOF'
+volume ssh://amy/mnt/root
+subvolume root_ubuntubionic
+target send-receive /mnt/root/btrbk
+EOF
+fi
 
 # todo: umount first to ensure we don't have any errors
 # todo: do some kill fuser stuff to make umount more reliable
index 04cca814727f80a54c2d4f5a84f504d830d3be41..64e22f19c5bb1c1915c77fa948f7fd1cd2049ceb 100644 (file)
@@ -335,13 +335,17 @@ for vol in q a o i; do
 
     ## begin expire leaf vols ##
     leaf_vols=($vol.leaf.*)
-    count=1
+    count=${#leaf_vols[@]}
+    leaf_limit_time=$(( $(date +%s) - 60*60*24*60 )) # 60 days
+    leaf_new_limit_time=$(( $(date +%s) - 60*60*24 )) # 1 day
+    # this goes backwards from oldest. leaf_new_limit_time is just in case
+    # the order gets screwed up or something.
     for leaf in ${leaf_vols[@]}; do
-      leaf_secs=$(date -d ${leaf#$vol.leaf.} +%s)
-      if (( $(date +%s) - 60*60*24*60 > leaf_secs || count > 100 )); then # 60 days
+      leaf_time=$(date -d ${leaf#$vol.leaf.} +%s)
+      if (( leaf_limit_time > leaf_time || ( leaf_new_limit_time > leaf_time && count > 100 ) )); then
         x btrfs sub del $leaf
       fi
-      count=$((count+1))
+      count=$((count-1))
     done
     ## end expire leaf vols ##
   fi