backup - enhanced seq budir to support custom rsync flags (default is the same)
This commit is contained in:
@@ -44,61 +44,84 @@ step_1() {
|
||||
|
||||
step_3_info() {
|
||||
# Backup single directory recursively
|
||||
local opt=
|
||||
local opt=()
|
||||
local dir='<SOURCE>'
|
||||
local tar='[TARGET]'
|
||||
local exc=
|
||||
local tarOpt=0
|
||||
local exc=()
|
||||
shift
|
||||
if [ "${1:-}" == "-t" ] ; then
|
||||
opt=" -t "
|
||||
shift
|
||||
fi
|
||||
while [[ "${1:-}" =~ ^- ]] ; do
|
||||
case "${1}" in
|
||||
--)
|
||||
shift && break;;
|
||||
-f)
|
||||
opt+=("${1:-}" "'${2:-}'")
|
||||
shift 2;;
|
||||
-t)
|
||||
tarOpt=1
|
||||
shift;;
|
||||
-*)
|
||||
opt+=("${1}")
|
||||
shift ;;
|
||||
esac
|
||||
done
|
||||
if [ -n "${1:-}" ] ; then
|
||||
dir="$1"
|
||||
shift
|
||||
if [ -z "$opt" ] && [ -n "$1" ] ; then
|
||||
tar="$1"
|
||||
shift
|
||||
else
|
||||
if (( tarOpt )) ; then
|
||||
tar="$BACKUP_TARGET"
|
||||
fi
|
||||
if [ -n "${1:-}" ] ; then
|
||||
exc="$*"
|
||||
else
|
||||
exc="[NO EXCLUDES]"
|
||||
tar="${1:-}"
|
||||
shift
|
||||
fi
|
||||
for arg in "$@" ; do
|
||||
exc+=("'$arg'")
|
||||
done
|
||||
(( ${#exc[@]} )) || exc=("[NO EXCLUDES]")
|
||||
fi
|
||||
echo "Backup $opt $dir $tar $exc"
|
||||
echo "Backup ${opt[*]} '$dir' '$tar' ${exc[*]}"
|
||||
echoinfo " -f : Replace default flags (can be used multiple times)"
|
||||
echoinfo " (default: ${sq_rsyncFlags[*]})"
|
||||
echoinfo " -n : No remount to rw"
|
||||
echoinfo " -t : Using configuration value as TARGET"
|
||||
echoinfo " <DIRECTORY> [EXCLUDES...]"
|
||||
echoinfo "EXCLUDES path notation starts within $dir"
|
||||
echoinfo " e.g. to exclude $dir/a:"
|
||||
echoinfo " $0 budir $dir $tar /a"
|
||||
}
|
||||
sq_rsyncFlags=("-avxHAX" "--delete")
|
||||
step_3_options() { echo "[OPTION] <DIRECTORY> [TARGET] [EXCLUDES...]"; }
|
||||
step_3_alias() { echo "budir"; }
|
||||
step_3() {
|
||||
local configTarget=0
|
||||
local noRemount=0
|
||||
local remount=1
|
||||
local buSource=
|
||||
local buTarget=
|
||||
local buExcludes=
|
||||
local buLog=
|
||||
local customFlags=()
|
||||
# don't use step number
|
||||
shift
|
||||
|
||||
for _ in "$@"; do
|
||||
case "$1" in
|
||||
--)
|
||||
shift && break;;
|
||||
-t)
|
||||
configTarget=1
|
||||
shift;;
|
||||
-n)
|
||||
noRemount=1
|
||||
remount=0
|
||||
shift;;
|
||||
-f)
|
||||
shift
|
||||
customFlags+=("${1:-}")
|
||||
shift;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$1" ] ; then
|
||||
(( "${#customFlags[@]}" )) || customFlags=("${sq_rsyncFlags[@]}")
|
||||
if [ -z "${1:-}" ] ; then
|
||||
error -e "Nothing found to backup $1"
|
||||
exit 1
|
||||
fi
|
||||
@@ -149,7 +172,7 @@ step_3() {
|
||||
tmpTarget="${buTarget}/"
|
||||
fi
|
||||
|
||||
if [ $noRemount -eq 0 ]; then
|
||||
if (( remount )) ; then
|
||||
# remount target to be writable
|
||||
exep "mount -o rw,remount '${buTarget}' >>/dev/null 2>&1"
|
||||
endReturn "Remount (${buTarget}) to be writable failed"
|
||||
@@ -161,12 +184,14 @@ step_3() {
|
||||
fi
|
||||
|
||||
checkInstalled
|
||||
exep "mv -f ${buTarget}/${buLog}0.log /tmp/${buLog}1.log 2>/dev/null"
|
||||
exep "${sq_toolBin} -avxHAX --delete --info=stats2 ${buExcludes[*]} ${tmpSource} ${tmpTarget} > /tmp/${buLog}0.log"
|
||||
exep "mv -f '${buTarget}/${buLog}0.log' '/tmp/${buLog}1.log' 2>/dev/null"
|
||||
exep "'${sq_toolBin}' ${customFlags[*]} --info=stats2 ${buExcludes[*]} '${tmpSource}' '${tmpTarget}' > '/tmp/${buLog}0.log'"
|
||||
|
||||
exe mv -f /tmp/"${buLog}"*.log "${buTarget}"
|
||||
exe sync
|
||||
exep "mount -o ro,remount '${buTarget}' >>/dev/null 2>&1"
|
||||
if (( remount )) ; then
|
||||
exep "mount -o ro,remount '${buTarget}' >>/dev/null 2>&1"
|
||||
fi
|
||||
}
|
||||
|
||||
step_100_info() { echo "Install ${sq_toolBin}"; }
|
||||
|
Reference in New Issue
Block a user