X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=check-subvol-stale;h=127718257ba1000ac95dbe65964d296b726b4584;hb=4f1b3daa120bbbf886af22bf15ee8b65b13d0eb8;hp=1451844f7c89298d2a9e100eeabba7f837874d24;hpb=f7cd81f49aa5d7a4581db63bed053e66e692972e;p=distro-setup diff --git a/check-subvol-stale b/check-subvol-stale index 1451844..1277182 100644 --- a/check-subvol-stale +++ b/check-subvol-stale @@ -13,8 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. - -# if latest subvols $@ are not mounted, exit 1, print message, and touch /nocow/btrfs-stale/$subvol +# usage: $0 SUBVOL_MOUNTPOINT... +# +# 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" "$@" @@ -31,7 +39,7 @@ ret=0 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 @@ -45,12 +53,17 @@ for d; do 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|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 @@ -72,4 +85,3 @@ for d; do fi done exit $ret -