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