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
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
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
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,