From 97c57fc9d533818c47b97e9b46e20a1530eac54c Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Wed, 1 Mar 2023 09:57:42 -0500 Subject: [PATCH] fix critical bug, where last_snap got set to . and which seems to be the cause of data loss on frodo. --- check-subvol-stale | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/check-subvol-stale b/check-subvol-stale index 2d00cbb..cb49379 100644 --- a/check-subvol-stale +++ b/check-subvol-stale @@ -144,10 +144,13 @@ for d; do d "svp=$svp # subvolume path" fi - # Assumes we are in the 21st century. - ls -1dvrq $root_dir/btrbk/$subvol_dir.20* >$tmpf - mapfile -t snaps <$tmpf - if [[ ! ${snaps[*]} ]]; then + # note: relying on null glob + ls_args=($root_dir/btrbk/$subvol_dir.20*) + if (( ${#ls_args[@]} )); then + # Assumes we are in the 21st century. + ls -1dvrq $root_dir/btrbk/$subvol_dir.20* >$tmpf + mapfile -t snaps <$tmpf + else # no snapshots yet # TODO: make this an error and override with a cli flag echo "$0: warning: no snapshots found at $root_dir/btrbk/$subvol_dir.20*. this is expected for a brand new volume" @@ -156,6 +159,16 @@ for d; do # last_snap by date. last_snap="${snaps[0]}" + + case $last_snap in + $root_dir/btrbk/$subvol_dir.20*) : ;; + *) + echo "$0: error: unexpected last_snap:$last_snap" + exit 1 + ;; + esac + + d last_snap=$last_snap ## alternate slower alternative which would not rely on ls sorting: # last_snap=$( # for s in ${snaps[@]}; do @@ -170,7 +183,6 @@ for d; do # echo "$0: error: could not find latest snapshot for $svp among ${snaps[*]}" >&2 # exit 1 # fi - d last_snap=$last_snap if [[ ! -e $svp ]]; then echo "$0: warning: subvol does not exist: $svp" @@ -192,7 +204,7 @@ for d; do if [[ $cgen -gt $last_received_cgen ]]; then last_received_cgen=$cgen last_received=$f - elif [[ $last_received ]]; then + elif [[ $last_received ]]; then # optimization: we are looking in reverse order by date, so if # we find one that has a lesser cgen, assume the rest will all # be lesser. -- 2.30.2