# limitations under the License.
# usage: $0 SUBVOL_MOUNTPOINT...
-# if latest subvols $@ are not mounted, exit 1, print message, and touch /nocow/btrfs-stale/$subvol
+#
+# In git, this is not not executable because it's meant to be installed
+# using ./install-my-scripts
+#
+# If latest subvols $@ are not mounted, exit 1, print message, and touch
+# /nocow/btrfs-stale/$subvol
+#
+# Either SUBVOL_MOUNTPOINT is a snapshot of the latest, or
+# the latest snapshot is snapshot of SUBVOL_MOUNTPOINT.
[[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@"
for d; do
vol=${d##*/}
cd /mnt/root/btrbk
- snaps=($vol.20*)
+ snaps=($vol.20*) # Assumes we are in the 21st century.
if [[ ! $snaps ]]; then
# no snapshots yet
continue
done | sort -r | head -n 1 | awk '{print $2}'
)
if [[ ! $last_snap ]]; then
- echo "$d stale"
+ # should not happen.
+ echo "$0: error: could not find latest snapshot for $d among ${snaps[@]}"
ret=1
continue
fi
stale=true
- if btrfs sub show $d 2>/dev/null | sed '0,/^\t*Snapshot(s):/d;s/^\s*//' | \
+ # check that $d has $last_snap as a snapshot,
+ # or else $d is a snapshot of $last_snap. In the second
+ # case, we use a uuid comparison, which if I remember from the
+ # docs, is a bit more robust, perhaps to renames.
+ if btrfs sub show $d 2>/dev/null | sed '0,/^\s*Snapshot(s):/d;s/^\s*//' | \
grep -xF btrbk/$last_snap &>/dev/null; then
stale=false
else
fi
done
exit $ret
-