mirror of
https://github.com/deajan/obackup.git
synced 2025-01-12 23:23:53 +01:00
Moved rsync patterns from obackup to ofunctions
This commit is contained in:
parent
42a86c116d
commit
6712fc6cc7
@ -1,4 +1,4 @@
|
|||||||
## FUNC_BUILD=2016021802
|
## FUNC_BUILD=2016021803
|
||||||
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
||||||
|
|
||||||
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
|
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
|
||||||
@ -733,39 +733,80 @@ function __CheckArguments {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#__END_WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
function old__CheckArguments {
|
function RsyncPatternsAdd {
|
||||||
# Checks the number of arguments and raises an error if some are missing
|
local pattern="${1}"
|
||||||
if [ "$_DEBUG" == "yes" ]; then
|
local pattern_type="${2}" # exclude or include
|
||||||
|
__CheckArguments 2 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
local number_of_arguments="${1}" # Number of arguments a function should have
|
local rest=
|
||||||
local number_of_given_arguments="${2}" # Number of arguments that have been passed
|
|
||||||
local function_name="${3}" # Function name that called __CheckArguments
|
|
||||||
local arguments="${4}" # All other arguments
|
|
||||||
|
|
||||||
if [ "$_PARANOIA_DEBUG" == "yes" ]; then
|
# Disable globbing so wildcards from exclusions do not get expanded
|
||||||
Logger "Entering function [$function_name]." "DEBUG"
|
set -f
|
||||||
|
rest="$pattern"
|
||||||
# Paranoia check... Can help finding empty arguments. __CheckArguments should be grepped out in production builds.
|
while [ -n "$rest" ]
|
||||||
local count=-3 # Number of arguments minus the function calls for __CheckArguments
|
do
|
||||||
for i in $@; do
|
# Take the string until first occurence until $PATH_SEPARATOR_CHAR
|
||||||
count=$((count + 1))
|
str=${rest%%;*}
|
||||||
|
# Handle the last case
|
||||||
|
if [ "$rest" = "${rest/$PATH_SEPARATOR_CHAR/}" ]; then
|
||||||
|
rest=
|
||||||
|
else
|
||||||
|
# Cut everything before the first occurence of $PATH_SEPARATOR_CHAR
|
||||||
|
rest=${rest#*$PATH_SEPARATOR_CHAR}
|
||||||
|
fi
|
||||||
|
if [ "$RSYNC_PATTERNS" == "" ]; then
|
||||||
|
RSYNC_PATTERNS="--"$pattern_type"=\"$str\""
|
||||||
|
else
|
||||||
|
RSYNC_PATTERNS="$RSYNC_PATTERNS --"$pattern_type"=\"$str\""
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
if [ $count -ne $1 ]; then
|
set +f
|
||||||
Logger "Function $function_name may have inconsistent number of arguments. Expected: $number_of_arguments, count: $count, see log file." "WARN"
|
}
|
||||||
echo "Argument list (including checks): $*" >> "$LOG_FILE"
|
|
||||||
fi
|
function RsyncPatternsFromAdd {
|
||||||
fi
|
local pattern_from="${1}"
|
||||||
|
local pattern_type="${2}"
|
||||||
if [ $number_of_arguments -ne $number_of_given_arguments ]; then
|
__CheckArguments 2 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
Logger "Inconsistnent number of arguments in $function_name. Should have $number_of_arguments arguments, has $number_of_given_arguments arguments, see log file." "CRITICAL"
|
|
||||||
# Cannot user Logger here because $@ is a list of arguments
|
local pattern_from=
|
||||||
echo "Argumnt list: $4" >> "$LOG_FILE"
|
|
||||||
|
## Check if the exclude list has a full path, and if not, add the config file path if there is one
|
||||||
|
if [ "$(basename $pattern_from)" == "$pattern_from" ]; then
|
||||||
|
pattern_from="$(dirname $CONFIG_FILE)/$pattern_from"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -e "$pattern_from" ]; then
|
||||||
|
RSYNC_PATTERNS="$RSYNC_PATTERNS --"$pattern_type"-from=\"$pattern_from\""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function RsyncPatterns {
|
||||||
|
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
|
if [ "$RSYNC_PATTERN_FIRST" == "exclude" ]; then
|
||||||
|
RsyncPatternsAdd "$RSYNC_EXCLUDE_PATTERN" "exclude"
|
||||||
|
if [ "$RSYNC_EXCLUDE_FROM" != "" ]; then
|
||||||
|
RsyncPatternsFromAdd "$RSYNC_EXCLUDE_FROM" "exclude"
|
||||||
|
fi
|
||||||
|
RsyncPatternsAdd "$RSYNC_INCLUDE_PATTERN" "include"
|
||||||
|
if [ "$RSYNC_INCLUDE_FROM" != "" ]; then
|
||||||
|
RsyncPatternsFromAdd "$RSYNC_INCLUDE_FROM" "include"
|
||||||
|
fi
|
||||||
|
elif [ "$RSYNC_PATTERN_FIRST" == "include" ]; then
|
||||||
|
RsyncPatternsAdd "$RSYNC_INCLUDE_PATTERN" "include"
|
||||||
|
if [ "$RSYNC_INCLUDE_FROM" != "" ]; then
|
||||||
|
RsyncPatternsFromAdd "$RSYNC_INCLUDE_FROM" "include"
|
||||||
|
fi
|
||||||
|
RsyncPatternsAdd "$RSYNC_EXCLUDE_PATTERN" "exclude"
|
||||||
|
if [ "$RSYNC_EXCLUDE_FROM" != "" ]; then
|
||||||
|
RsyncPatternsFromAdd "$RSYNC_EXCLUDE_FROM" "exclude"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
Logger "Bogus RSYNC_PATTERN_FIRST value in config file. Will not use rsync patterns." "WARN"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
#__END_WITH_PARANOIA_DEBUG
|
|
||||||
|
|
||||||
function PreInit {
|
function PreInit {
|
||||||
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
Loading…
Reference in New Issue
Block a user