backup - fix toolBin and correct shellcheck warnings
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
readonly toolName=backup
|
||||
readonly toolBin=rsync
|
||||
# shellcheck disable=SC2001 # See if you can use ${variable//search/replace} instead.
|
||||
# It is more easy with sed to remove multiple trailing /
|
||||
|
||||
sq_toolBin=rsync
|
||||
sq_aptOpt=
|
||||
sq_config=0
|
||||
|
||||
@@ -30,7 +31,7 @@ step_1() {
|
||||
local buTarget="/backup"
|
||||
if (( ! sq_config )) ; then
|
||||
error -e "Cannot backup root without properly configured excludes"
|
||||
error -e " (expected config: ${seq_configFile})"
|
||||
error -e " (expected config: ${seq_configFile:?})"
|
||||
else
|
||||
buTarget="$BACKUP_TARGET"
|
||||
fi
|
||||
@@ -44,8 +45,8 @@ step_1() {
|
||||
step_3_info() {
|
||||
# Backup single directory recursively
|
||||
local opt=
|
||||
local dir=
|
||||
local tar=
|
||||
local dir='<SOURCE>'
|
||||
local tar='[TARGET]'
|
||||
local exc=
|
||||
shift
|
||||
if [ "${1:-}" == "-t" ] ; then
|
||||
@@ -55,14 +56,14 @@ step_3_info() {
|
||||
if [ -n "${1:-}" ] ; then
|
||||
dir="$1"
|
||||
shift
|
||||
if [ -z $opt ] && [ -n "$1" ] ; then
|
||||
if [ -z "$opt" ] && [ -n "$1" ] ; then
|
||||
tar="$1"
|
||||
shift
|
||||
else
|
||||
tar="$BACKUP_TARGET"
|
||||
fi
|
||||
if [ -n "${1:-}" ] ; then
|
||||
exc="$@"
|
||||
exc="$*"
|
||||
else
|
||||
exc="[NO EXCLUDES]"
|
||||
fi
|
||||
@@ -102,26 +103,26 @@ step_3() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
buLog=$(basename $1)
|
||||
buLog="$(basename -- "$1")"
|
||||
if [ "$buLog" == "/" ] ; then
|
||||
buLog="root"
|
||||
buSource="$1"
|
||||
else
|
||||
# remove trailing slashes
|
||||
buSource=$(echo "$1" | sed 's:/*$::')
|
||||
buSource="$(echo "$1" | sed 's:/*$::')"
|
||||
fi
|
||||
buLog="backup_${buLog}"
|
||||
shift
|
||||
|
||||
if [ $configTarget -ne 0 ] && (( sq_config )) ; then
|
||||
if (( configTarget )) && (( sq_config )) ; then
|
||||
# Taking target from config
|
||||
buTarget=$(echo "$BACKUP_TARGET" | sed 's:/*$::')
|
||||
buTarget="$(echo "$BACKUP_TARGET" | sed 's:/*$::')"
|
||||
else
|
||||
if [ -z "$1" ] ; then
|
||||
error -e "No valid target found"
|
||||
exit 1
|
||||
fi
|
||||
buTarget=$(echo "$1" | sed 's:/*$::')
|
||||
buTarget="$(echo "$1" | sed 's:/*$::')"
|
||||
shift
|
||||
fi
|
||||
if [ ! -d "${buTarget}" ] && [ ! -L "${buTarget}" ]
|
||||
@@ -136,11 +137,13 @@ step_3() {
|
||||
|
||||
info "Source : $buSource"
|
||||
info "Target : $buTarget"
|
||||
info "Excludes: $@"
|
||||
info "Excludes: $*"
|
||||
|
||||
#fix doubling trailing slash on verbose output when backing up root
|
||||
local tmpSource="$buSource/"
|
||||
local tmpTarget="${buTarget}/$(basename ${buSource})"
|
||||
local tmpTarget=
|
||||
|
||||
tmpTarget="${buTarget}/$(basename -- "${buSource}")"
|
||||
if [ "$buSource" == "/" ] ; then
|
||||
tmpSource="/"
|
||||
tmpTarget="${buTarget}/"
|
||||
@@ -159,26 +162,25 @@ step_3() {
|
||||
|
||||
checkInstalled
|
||||
exep "mv -f ${buTarget}/${buLog}0.log /tmp/${buLog}1.log 2>/dev/null"
|
||||
exep "$toolBin -avxHAX --delete --info=stats2 ${buExcludes[*]} ${tmpSource} ${tmpTarget} > /tmp/${buLog}0.log"
|
||||
exep "${sq_toolBin} -avxHAX --delete --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
|
||||
exep "mount -o ro,remount '${buTarget}' >>/dev/null 2>&1"
|
||||
}
|
||||
|
||||
step_100_info() { echo "Install $toolBin"; }
|
||||
step_100_info() { echo "Install ${sq_toolBin}"; }
|
||||
step_100_alias() { echo "install"; }
|
||||
step_100() {
|
||||
exe apt update
|
||||
exe apt install $toolBin ${sq_aptOpt}
|
||||
exe apt install ${sq_toolBin} ${sq_aptOpt}
|
||||
}
|
||||
|
||||
checkInstalled() {
|
||||
command -v $toolBin >>/dev/null
|
||||
if [ $? -ne 0 ] ; then
|
||||
if ! command -v ${sq_toolBin} >>/dev/null ; then
|
||||
step install
|
||||
fi
|
||||
toolBin="$(command -v $toolBin)"
|
||||
sq_toolBin="$(command -v ${sq_toolBin})"
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2034 # Appears unused
|
||||
|
Reference in New Issue
Block a user