- # Get last_snap by date.
- # when a btrbk bugfix makes it into the distro,
- # we might replace this with btrbk list latest /mnt/root/$vol | ...
- last_snap=$(
- for s in ${snaps[@]}; do
- f=${s##*/}
- unix_time=$(date -d $(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${f#$vol.}) +%s)
- printf "%s %s\n" $unix_time $s # part of the pipeline
- # sort will fail
- done | sort -r | head -n 1 | awk '{print $2}' || [[ ${PIPESTATUS[1]} == 141 || ${PIPESTATUS[0]} == 32 ]]
- )
- if [[ ! $last_snap ]]; then
- # should not happen.
- 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"
- echo "$0 assuming this host was just for receiving and latest snap is freshest"
- freshest_snap=$last_snap
- stale=true
- stale-file
- continue
- fi
-