X-Git-Url: https://iankelling.org/git/?p=distro-setup;a=blobdiff_plain;f=check-subvol-stale;h=bdb47492ef07b132914b21ec6773014675dca38f;hp=afa711f2efa6347a08967cbf3c371bacea2615f1;hb=65351382939fa95fb1e05d7d83eb58d27c3c6133;hpb=4c39892ef8fa3379ce36adbe870723324cb71cea diff --git a/check-subvol-stale b/check-subvol-stale index afa711f..bdb4749 100644 --- a/check-subvol-stale +++ b/check-subvol-stale @@ -53,11 +53,14 @@ for d; do vol=${d##*/} dev=$(sed -rn "s,^\s*([^#]\S*)\s+$d\s.*,\1,p" /etc/fstab|head -n1) subvol_dir=$(sed -rn "s,^\s*[^#]\S*\s+$d\s.*\bsubvol=([a-zA-A/]+).*,\1,p" /etc/fstab|head -n1) - root_dir=$(sed -rn "s,^\s*$dev\s+(\S+).*\bsubvolid=0\b.*,\1,p" /etc/fstab|head -n1) + # note, we need $dev because $d might not be mounted, and we do this loop + # because the device in fstab for the rootfs can be different. + for devx in $(btrfs fi show $dev| sed -rn 's#.*path (/\S+)$#\1#p'); do + root_dir=$(sed -rn "s,^\s*$devx\s+(\S+).*\bsubvolid=0\b.*,\1,p" /etc/fstab|head -n1) + if [[ $root_dir ]]; then break; fi + done svp=$root_dir/$subvol_dir # subvolume path - - snaps=($root_dir/btrbk/$subvol_dir.20*) # Assumes we are in the 21st century. if [[ ! $snaps ]]; then # no snapshots yet @@ -84,7 +87,8 @@ for d; do last_snap=$( for s in ${snaps[@]}; do f=${s##*/} - printf "%s %s\n" $(date -d $(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${f#$vol.}) +%s) $f + unix_time=$(date -d $(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${f#$vol.}) +%s) + printf "%s %s\n" $unix_time $s done | sort -r | head -n 1 | awk '{print $2}' ) if [[ ! $last_snap ]]; then @@ -95,8 +99,10 @@ for d; do fi if [[ ! -e $svp ]]; then - echo "$0: warning: subvol we want to check does not exist: $svp" - stale-file=$last_snap + echo "$0: warning: subvol does not exist: $svp" + echo "$0 assuming this host was just for receiving and latest snap is freshest" + freshest_snap=$last_snap + stale=true stale-file continue fi @@ -116,6 +122,7 @@ for d; do continue fi + # fallback to using last_snap as the freshest freshest_snap=$last_snap stale=true # fresh if $svp has $last_snap as a snapshot,