diff --git a/modules/filesystem/btrfs/btrbk.lib b/modules/filesystem/btrfs/btrbk.lib index 39add74..64487ce 100644 --- a/modules/filesystem/btrfs/btrbk.lib +++ b/modules/filesystem/btrfs/btrbk.lib @@ -49,6 +49,55 @@ dests+=" $(sudo btrbk -c $file list target --format col:h:target_path)" echo $dests } +btrbk_latest() { + +local file=$(btrbk_conf $1) +[[ ! $file ]] && echo unable to find conf file for ${1:-btrbk.conf} && return 1 +shift + +local latest=$(sudo btrbk -c $file list latest --format col:h:snapshot_subvolume | xargs -I % sh -c 'basename %' | sed '$!N; /^\(.*\)\n\1$/!P; D') +echo $latest + +} + +btrbk_latest_snap () { + +local dry_run="echo" +[[ $1 == "-e" ]] && dry_run="" && shift + +local file=$(btrbk_conf $1) +[[ ! $file ]] && echo unable to find conf file for ${1:-btrbk.conf} && return 1 +shift + +local ext=${1-sav}.$(date "+%Y%m%d") + +local latest=$(sudo btrbk -c $file list latest --format col:h:snapshot_subvolume | xargs -I % sh -c 'basename %' | sed '$!N; /^\(.*\)\n\1$/!P; D') +[[ ( ! $latest ) || $latest == "-" ]] && echo "no latest snapshots so can't make .latest links" && return 3 +local dests=$(btrbk_dests $file) + +if [[ $dry_run ]]; then + echo dry run for latest snapshots for following destinations, NOTE: use -e to actually make them + echo $dests + echo "-------------------" +fi + +echo making snapshots in each destination +[[ $dry_run ]] && echo this is a dry run use -e to make snapshots +for dest in $dests; do +for snap in $latest; do +# [[ -e $dest/${snap%%.*}.latest ]] && $dry_run_echo sudo rm $dest/${snap%%.*}.latest +# TODO only do latest links for locally mounted +if [[ -d $dest/$snap ]]; then +local cmd="sudo btrfs subvolume snapshot $dest/$snap $dest/${snap%%.*}.${ext}" +echo $cmd +[[ ! $dry_run ]] && $cmd +fi +done +done + +} + + btrbk_latest_links () { local dry_run="echo" @@ -58,6 +107,8 @@ local file=$(btrbk_conf $1) [[ ! $file ]] && echo unable to find conf file for ${1:-btrbk.conf} && return 1 shift +local ext=${2:-latest} + local latest=$(sudo btrbk -c $file list latest --format col:h:snapshot_subvolume | xargs -I % sh -c 'basename %' | sed '$!N; /^\(.*\)\n\1$/!P; D') [[ ( ! $latest ) || $latest == "-" ]] && echo "no latest snapshots so can't make .latest links" && return 3 local dests=$(btrbk_dests $file) @@ -74,7 +125,7 @@ for snap in $latest; do # [[ -e $dest/${snap%%.*}.latest ]] && $dry_run_echo sudo rm $dest/${snap%%.*}.latest # TODO only do latest links for locally mounted if [[ -d $dest/$snap ]]; then -local cmd="sudo ln -srfn $dest/$snap $dest/${snap%%.*}.latest 2> /dev/null" +local cmd="sudo ln -srfn $dest/$snap $dest/${snap%%.*}.${ext}" echo $cmd [[ ! $dry_run ]] && $cmd fi diff --git a/modules/utility/find.lib b/modules/utility/find.lib index 1aa441b..cf7089a 100644 --- a/modules/utility/find.lib +++ b/modules/utility/find.lib @@ -30,7 +30,8 @@ local raw local mounted local usesudo -mounted="-mount" +# xdev is supported in busybox (alpine) +mounted="-xdev" declare OPTION declare OPTARG