X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=check-subvol-stale;h=c585cea0169c2fb9bde14224380f252100f5067f;hb=8826440696abdfbfd6c7f5a40c95163bd489a1b1;hp=afa711f2efa6347a08967cbf3c371bacea2615f1;hpb=4c39892ef8fa3379ce36adbe870723324cb71cea;p=distro-setup diff --git a/check-subvol-stale b/check-subvol-stale index afa711f..c585cea 100644 --- a/check-subvol-stale +++ b/check-subvol-stale @@ -13,16 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# 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,6 +21,41 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR shopt -s nullglob +usage() { + cat </dev/null; then cgen=$(echo "$show" | sed -rn 's,^\s*Gen at creation:\s+([0-9]+).*,\1,p') - if [[ $cgen -gt $last_received_gen ]]; then + if [[ $cgen -gt $last_received_cgen ]]; then last_received_cgen=$cgen last_received=$f fi fi done + d last_received_cgen=$cgen + d last_received=$f # Get last_snap by date. # when a btrbk bugfix makes it into the distro, @@ -84,7 +122,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 +134,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 @@ -105,6 +146,7 @@ for d; do # if there is a last_received, we can assume stale or fresh if we are newer/older if [[ $last_received ]]; then svp_cgen=$(btrfs sub show $svp | sed -rn 's,^\s*Gen at creation:\s+([0-9]+).*,\1,p') + d svp_cgen=$svp_cgen if [[ $svp_cgen -ge $last_received_cgen ]]; then stale=false else @@ -116,6 +158,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,