use -xdev and not -mount for linux find as it works for busybox and -mount is deprecated

add latest functions to btrbk library
master
David Kebler 2024-09-15 18:21:32 -07:00
parent 9c51109d2e
commit 9f677a3303
2 changed files with 54 additions and 2 deletions

View File

@ -49,6 +49,55 @@ dests+=" $(sudo btrbk -c $file list target --format col:h:target_path)"
echo $dests 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 () { btrbk_latest_links () {
local dry_run="echo" 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 [[ ! $file ]] && echo unable to find conf file for ${1:-btrbk.conf} && return 1
shift 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') 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 [[ ( ! $latest ) || $latest == "-" ]] && echo "no latest snapshots so can't make .latest links" && return 3
local dests=$(btrbk_dests $file) 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 # [[ -e $dest/${snap%%.*}.latest ]] && $dry_run_echo sudo rm $dest/${snap%%.*}.latest
# TODO only do latest links for locally mounted # TODO only do latest links for locally mounted
if [[ -d $dest/$snap ]]; then 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 echo $cmd
[[ ! $dry_run ]] && $cmd [[ ! $dry_run ]] && $cmd
fi fi

View File

@ -30,7 +30,8 @@ local raw
local mounted local mounted
local usesudo local usesudo
mounted="-mount" # xdev is supported in busybox (alpine)
mounted="-xdev"
declare OPTION declare OPTION
declare OPTARG declare OPTARG