X-Git-Url: https://iankelling.org/git/?p=distro-setup;a=blobdiff_plain;f=unison-snapshot;h=154eed0702fe0c5930816bbe0d156e38e29545f4;hp=aa2a63b4520db30112eb3e8fc24a5db07557193c;hb=8a6b446c7e336596af614c853e1c6177e55a7983;hpb=474fb77f4aa8e79a4706aff9c511452e180fff64 diff --git a/unison-snapshot b/unison-snapshot index aa2a63b..154eed0 100755 --- a/unison-snapshot +++ b/unison-snapshot @@ -1,24 +1,25 @@ #!/bin/bash -l - set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -base=unison-$(date "+%Y:%m:%d") -for mountp in /mnt/root /mnt/iroot; do +sv() { echo "$@"; "$@"; } + +date=unison-$(date "+%Y:%m:%d") +for mountp in /mnt/root/q /mnt/iroot/i; do [[ -e $mountp ]] || continue - full_base=$mountp/$base - existing=( $full_base-* ) - if [[ -e ${existing[0]} ]]; then - snapshot=$full_base-$(( ${#existing[@]} + 1 )) + date_path=${mountp%/*}/$date + todays=( $date_path-* ) + IFS=$'\n' todays=($(sort -Vr <<<"${todays[*]}")); unset IFS + if [[ -e ${todays[0]} ]]; then + snapshot=$date_path-$(( ${todays[0]##*-} + 1 )) else - snapshot=$full_base-1 + snapshot=$date_path-1 fi - s btrfs subvolume snapshot -r $mountp $snapshot - existing=( $mountp/unison-* ) + sv s btrfs subvolume snapshot -r $mountp $snapshot + existing=( ${mountp%/*}/unison-* ) + IFS=$'\n' existing=($(sort -Vr <<<"${existing[*]}")); unset IFS # keep 10 unison snapshots around if (( ${#existing[@]} > 10 )); then - IFS=$'\n' existing=($(sort -Vr <<<"${existing[*]}")) - unset IFS - s btrfs subvolume delete ${existing[@]:10} + sv s btrfs subvolume delete ${existing[@]:10} fi done