Rebuilt target
This commit is contained in:
parent
216ee8adf7
commit
ca7be5d945
100
osync-batch.sh
100
osync-batch.sh
|
@ -3,19 +3,24 @@ SUBPROGRAM=osync
|
||||||
PROGRAM="$SUBPROGRAM-batch" # Batch program to run osync / obackup instances sequentially and rerun failed ones
|
PROGRAM="$SUBPROGRAM-batch" # Batch program to run osync / obackup instances sequentially and rerun failed ones
|
||||||
AUTHOR="(L) 2013-2016 by Orsiris de Jong"
|
AUTHOR="(L) 2013-2016 by Orsiris de Jong"
|
||||||
CONTACT="http://www.netpower.fr - ozy@netpower.fr"
|
CONTACT="http://www.netpower.fr - ozy@netpower.fr"
|
||||||
PROGRAM_BUILD=2016052501
|
PROGRAM_BUILD=2016081704
|
||||||
|
|
||||||
## Runs an osync /obackup instance for every conf file found
|
## Runs an osync /obackup instance for every conf file found
|
||||||
## If an instance fails, run it again if time permits
|
## If an instance fails, run it again if time permits
|
||||||
|
|
||||||
|
if ! type "$BASH" > /dev/null; then
|
||||||
|
echo "Please run this script only with bash shell. Tested on bash >= 3.2"
|
||||||
|
exit 127
|
||||||
|
fi
|
||||||
|
|
||||||
## Configuration file path. The path where all the osync / obackup conf files are, usually /etc/osync or /etc/obackup
|
## Configuration file path. The path where all the osync / obackup conf files are, usually /etc/osync or /etc/obackup
|
||||||
CONF_FILE_PATH=/etc/$SUBPROGRAM
|
CONF_FILE_PATH=/etc/$SUBPROGRAM
|
||||||
|
|
||||||
## If maximum execution time is not reached, failed instances will be rerun. Max exec time is in seconds. Example is set to 10 hours.
|
## If maximum execution time is not reached, failed instances will be rerun. Max exec time is in seconds. Example is set to 10 hours.
|
||||||
MAX_EXECUTION_TIME=36000
|
MAX_EXECUTION_TIME=36000
|
||||||
|
|
||||||
## Specifies the number of reruns an instance may get
|
## Specifies the number of total runs an instance may get
|
||||||
MAX_RERUNS=3
|
MAX_RUNS=3
|
||||||
|
|
||||||
## Log file path
|
## Log file path
|
||||||
if [ -w /var/log ]; then
|
if [ -w /var/log ]; then
|
||||||
|
@ -69,47 +74,64 @@ function CheckEnvironment {
|
||||||
else
|
else
|
||||||
SUBPROGRAM_EXECUTABLE=$(type -p $SUBPROGRAM.sh)
|
SUBPROGRAM_EXECUTABLE=$(type -p $SUBPROGRAM.sh)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Check for CONF_FILE_PATH
|
|
||||||
if [ ! -d "$CONF_FILE_PATH" ]; then
|
|
||||||
Logger "Cannot find conf file path $CONF_FILE_PATH" "CRITICAL"
|
|
||||||
Usage
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Batch {
|
function Batch {
|
||||||
## Get list of .conf files
|
local runs=0 # Number of batch runs
|
||||||
for i in $CONF_FILE_PATH/*.conf
|
local runList # Actual conf file list to run
|
||||||
do
|
local runAgainList # List of failed conf files sto run again
|
||||||
if [ "$RUN" == "" ]; then
|
|
||||||
RUN="$i"
|
|
||||||
else
|
|
||||||
RUN=$RUN" $i"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
RERUNS=0
|
local confFile
|
||||||
while ([ $MAX_EXECUTION_TIME -gt $SECONDS ] || [ $MAX_EXECUTION_TIME -eq 0 ]) && [ "$RUN" != "" ] && [ $MAX_RERUNS -gt $RERUNS ]
|
local result
|
||||||
|
|
||||||
|
## Check for CONF_FILE_PATH
|
||||||
|
if [ -d "$CONF_FILE_PATH" ]; then
|
||||||
|
## Get list of .conf files
|
||||||
|
for confFile in $CONF_FILE_PATH/*.conf
|
||||||
do
|
do
|
||||||
Logger "$SUBPROGRAM instances will be run for: $RUN" "NOTICE"
|
if [ -f "$confFile" ]; then
|
||||||
for i in $RUN
|
if [ "$runList" == "" ]; then
|
||||||
do
|
runList="$confFile"
|
||||||
$SUBPROGRAM_EXECUTABLE "$i" $opts &
|
|
||||||
wait $!
|
|
||||||
if [ $? != 0 ]; then
|
|
||||||
Logger "Run instance $(basename $i) failed" "ERROR"
|
|
||||||
if [ "$RUN_AGAIN" == "" ]; then
|
|
||||||
RUN_AGAIN="$i"
|
|
||||||
else
|
else
|
||||||
RUN_AGAIN=$RUN_AGAIN" $i"
|
runList=$runList" $confFile"
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
Logger "Run instance $(basename $i) succeed." "NOTICE"
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
RUN="$RUN_AGAIN"
|
elif [ -f "$CONF_FILE_PATH" ] && [ "${CONF_FILE_PATH##*.}" == "conf" ]; then
|
||||||
RUN_AGAIN=""
|
runList="$CONF_FILE_PATH"
|
||||||
RERUNS=$(($RERUNS + 1))
|
fi
|
||||||
|
|
||||||
|
if [ "$runList" == "" ]; then
|
||||||
|
Logger "Cannot find conf file path [$CONF_FILE_PATH]." "CRITICAL"
|
||||||
|
Usage
|
||||||
|
fi
|
||||||
|
|
||||||
|
while ([ $MAX_EXECUTION_TIME -gt $SECONDS ] || [ $MAX_EXECUTION_TIME -eq 0 ]) && [ "$runList" != "" ] && [ $MAX_RUNS -gt $runs ]
|
||||||
|
do
|
||||||
|
Logger "$SUBPROGRAM instances will be run for: $runList" "NOTICE"
|
||||||
|
for confFile in $runList
|
||||||
|
do
|
||||||
|
$SUBPROGRAM_EXECUTABLE "$confFile" $opts &
|
||||||
|
wait $!
|
||||||
|
result=$?
|
||||||
|
if [ $result != 0 ]; then
|
||||||
|
if [ $result == 1 ] || [ $result == 128 ]; then # Do not handle exit code 127 because it is already handled here
|
||||||
|
Logger "Run instance $(basename $confFile) failed with exit code [$result]." "ERROR"
|
||||||
|
if [ "$runAgainList" == "" ]; then
|
||||||
|
runAgainList="$confFile"
|
||||||
|
else
|
||||||
|
runAgainList=$runAgainList" $confFile"
|
||||||
|
fi
|
||||||
|
elif [ $result == 2 ]; then
|
||||||
|
Logger "Run instance $(basename $confFile) finished with warnings." "WARN"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
Logger "Run instance $(basename $confFile) succeed." "NOTICE"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
runList="$runAgainList"
|
||||||
|
runAgainList=""
|
||||||
|
runs=$(($runs + 1))
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,8 +145,8 @@ function Usage {
|
||||||
echo ""
|
echo ""
|
||||||
echo "[OPTIONS]"
|
echo "[OPTIONS]"
|
||||||
echo "--path=/path/to/conf Path to osync / obackup conf files, defaults to /etc/osync or /etc/obackup"
|
echo "--path=/path/to/conf Path to osync / obackup conf files, defaults to /etc/osync or /etc/obackup"
|
||||||
echo "--max-reruns=X Number of runs max for failed instances, (defaults to 3)"
|
echo "--max-runs=X Number of max runs per instance, (defaults to 3)"
|
||||||
echo "--max-exec-time=X Retry failed instances only if max execution time not reached (defaults to 36000 seconds). Set to 0 to bypass execution time check."
|
echo "--max-exec-time=X Retry failed instances only if max execution time not reached (defaults to 36000 seconds). Set to 0 to bypass execution time check"
|
||||||
echo "--no-maxtime Run osync / obackup without honoring conf file defined timeouts"
|
echo "--no-maxtime Run osync / obackup without honoring conf file defined timeouts"
|
||||||
echo "--dry Will run osync / obackup without actually doing anything; just testing"
|
echo "--dry Will run osync / obackup without actually doing anything; just testing"
|
||||||
echo "--silent Will run osync / obackup without any output to stdout, used for cron jobs"
|
echo "--silent Will run osync / obackup without any output to stdout, used for cron jobs"
|
||||||
|
@ -151,8 +173,8 @@ do
|
||||||
--path=*)
|
--path=*)
|
||||||
CONF_FILE_PATH=${i##*=}
|
CONF_FILE_PATH=${i##*=}
|
||||||
;;
|
;;
|
||||||
--max-reruns=*)
|
--max-runs=*)
|
||||||
MAX_RERUNS=${i##*=}
|
MAX_RUNS=${i##*=}
|
||||||
;;
|
;;
|
||||||
--max-exec-time=*)
|
--max-exec-time=*)
|
||||||
MAX_EXECUTION_TIME=${i##*=}
|
MAX_EXECUTION_TIME=${i##*=}
|
||||||
|
|
Loading…
Reference in New Issue