fix btrbk service
[distro-setup] / unison-snapshot
index aa2a63b4520db30112eb3e8fc24a5db07557193c..154eed0702fe0c5930816bbe0d156e38e29545f4 100755 (executable)
@@ -1,24 +1,25 @@
 #!/bin/bash -l
-
 set -eE -o pipefail
 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
-base=unison-$(date "+%Y:%m:%d")
-for mountp in /mnt/root /mnt/iroot; do
+sv() { echo "$@"; "$@"; }
+
+date=unison-$(date "+%Y:%m:%d")
+for mountp in /mnt/root/q /mnt/iroot/i; do
     [[ -e $mountp ]] || continue
-    full_base=$mountp/$base
-    existing=( $full_base-* )
-    if [[ -e ${existing[0]} ]]; then
-        snapshot=$full_base-$(( ${#existing[@]} + 1 ))
+    date_path=${mountp%/*}/$date
+    todays=( $date_path-* )
+    IFS=$'\n' todays=($(sort -Vr <<<"${todays[*]}")); unset IFS
+    if [[ -e ${todays[0]} ]]; then
+        snapshot=$date_path-$(( ${todays[0]##*-} + 1 ))
     else
-        snapshot=$full_base-1
+        snapshot=$date_path-1
     fi
-    s btrfs subvolume snapshot -r $mountp $snapshot
-    existing=( $mountp/unison-* )
+    sv s btrfs subvolume snapshot -r $mountp $snapshot
+    existing=( ${mountp%/*}/unison-* )
+    IFS=$'\n' existing=($(sort -Vr <<<"${existing[*]}")); unset IFS
     # keep 10 unison snapshots around
     if (( ${#existing[@]} > 10 )); then
-        IFS=$'\n' existing=($(sort -Vr <<<"${existing[*]}"))
-        unset IFS
-        s btrfs subvolume delete ${existing[@]:10}
+        sv s btrfs subvolume delete ${existing[@]:10}
     fi
 done