@ -6,8 +6,8 @@
PROGRAM = "osync" # Rsync based two way sync engine with fault tolerance
PROGRAM = "osync" # Rsync based two way sync engine with fault tolerance
AUTHOR = "(C) 2013-2022 by Orsiris de Jong"
AUTHOR = "(C) 2013-2022 by Orsiris de Jong"
CONTACT = "http://www.netpower.fr/osync - ozy@netpower.fr"
CONTACT = "http://www.netpower.fr/osync - ozy@netpower.fr"
PROGRAM_VERSION = 1.3.0-rc3
PROGRAM_VERSION = 1.3.0-rc4-dev
PROGRAM_BUILD = 202 10629 01
PROGRAM_BUILD = 202 30610 01
IS_STABLE = true
IS_STABLE = true
CONFIG_FILE_REVISION_REQUIRED = 1.3.0
CONFIG_FILE_REVISION_REQUIRED = 1.3.0
@ -42,8 +42,8 @@ CONFIG_FILE_REVISION_REQUIRED=1.3.0
# UnlockReplicas yes #__WITH_PARANOIA_DEBUG
# UnlockReplicas yes #__WITH_PARANOIA_DEBUG
# CleanUp no #__WITH_PARANOIA_DEBUG
# CleanUp no #__WITH_PARANOIA_DEBUG
_OFUNCTIONS_VERSION = 2.4.3
_OFUNCTIONS_VERSION = 2.5.0
_OFUNCTIONS_BUILD = 202 20508 01
_OFUNCTIONS_BUILD = 202 30610 01
_OFUNCTIONS_BOOTSTRAP = true
_OFUNCTIONS_BOOTSTRAP = true
if ! type " $BASH " > /dev/null; then
if ! type " $BASH " > /dev/null; then
@ -66,6 +66,8 @@ _LOGGER_SILENT=false
_LOGGER_VERBOSE = false
_LOGGER_VERBOSE = false
_LOGGER_ERR_ONLY = false
_LOGGER_ERR_ONLY = false
_LOGGER_PREFIX = "date"
_LOGGER_PREFIX = "date"
_LOGGER_WRITE_PARTIAL_LOGS = false # Writes partial log files to /tmp so sending logs via alerts can feed on them
_OFUNCTIONS_SHOW_SPINNER = true # Show spinner in ExecTasks function
if [ " $KEEP_LOGGING " = = "" ] ; then
if [ " $KEEP_LOGGING " = = "" ] ; then
KEEP_LOGGING = 1801
KEEP_LOGGING = 1801
fi
fi
@ -174,7 +176,7 @@ function _Logger {
echo -e " $logValue " >> " $LOG_FILE "
echo -e " $logValue " >> " $LOG_FILE "
# Build current log file for alerts if we have a sufficient environment
# Build current log file for alerts if we have a sufficient environment
if [ " $ RUN_DIR/ $PROGRAM " != "/" ] ; then
if [ " $ _LOGGER_WRITE_PARTIAL_LOGS" = = true ] && [ " $ RUN_DIR/ $PROGRAM " != "/" ] ; then
echo -e " $logValue " >> " $RUN_DIR / $PROGRAM ._Logger. $SCRIPT_PID . $TSTAMP "
echo -e " $logValue " >> " $RUN_DIR / $PROGRAM ._Logger. $SCRIPT_PID . $TSTAMP "
fi
fi
fi
fi
@ -290,18 +292,18 @@ function Logger {
if [ " $level " = = "CRITICAL" ] ; then
if [ " $level " = = "CRITICAL" ] ; then
_Logger " $prefix ( $level ): $value " " $prefix \e[1;33;41m $value \e[0m " true
_Logger " $prefix ( $level ): $value " " $prefix \e[1;33;41m $value \e[0m " true
ERROR_ALERT = true
ERROR_ALERT = true
# ERROR_ALERT / WARN_ALERT is not set in main when Logger is called from a subprocess. Need to keep this flag.
# ERROR_ALERT / WARN_ALERT is not set in main when Logger is called from a subprocess. We need to create these flag files for ERROR_ALERT / WARN_ALERT to be picked up by Alert
echo -e " [ $retval ] in [ $( joinString , ${ FUNCNAME [@] } ) ] SP= $SCRIPT_PID P= $$ \n $prefix ( $level ): $value " >> " $RUN_DIR / $PROGRAM . ${ FUNCNAME [0] } .error .$SCRIPT_PID . $TSTAMP "
echo -e " [ $retval ] in [ $( joinString , ${ FUNCNAME [@] } ) ] SP= $SCRIPT_PID P= $$ \n $prefix ( $level ): $value " >> " $RUN_DIR / $PROGRAM . ERROR_ALERT .$SCRIPT_PID . $TSTAMP "
return
return
elif [ " $level " = = "ERROR" ] ; then
elif [ " $level " = = "ERROR" ] ; then
_Logger " $prefix ( $level ): $value " " $prefix \e[91m $value \e[0m " true
_Logger " $prefix ( $level ): $value " " $prefix \e[91m $value \e[0m " true
ERROR_ALERT = true
ERROR_ALERT = true
echo -e " [ $retval ] in [ $( joinString , ${ FUNCNAME [@] } ) ] SP= $SCRIPT_PID P= $$ \n $prefix ( $level ): $value " >> " $RUN_DIR / $PROGRAM . ${ FUNCNAME [0] } .error .$SCRIPT_PID . $TSTAMP "
echo -e " [ $retval ] in [ $( joinString , ${ FUNCNAME [@] } ) ] SP= $SCRIPT_PID P= $$ \n $prefix ( $level ): $value " >> " $RUN_DIR / $PROGRAM . ERROR_ALERT .$SCRIPT_PID . $TSTAMP "
return
return
elif [ " $level " = = "WARN" ] ; then
elif [ " $level " = = "WARN" ] ; then
_Logger " $prefix ( $level ): $value " " $prefix \e[33m $value \e[0m " true
_Logger " $prefix ( $level ): $value " " $prefix \e[33m $value \e[0m " true
WARN_ALERT = true
WARN_ALERT = true
echo -e " [ $retval ] in [ $( joinString , ${ FUNCNAME [@] } ) ] SP= $SCRIPT_PID P= $$ \n $prefix ( $level ): $value " >> " $RUN_DIR / $PROGRAM . ${ FUNCNAME [0] } .warn .$SCRIPT_PID . $TSTAMP "
echo -e " [ $retval ] in [ $( joinString , ${ FUNCNAME [@] } ) ] SP= $SCRIPT_PID P= $$ \n $prefix ( $level ): $value " >> " $RUN_DIR / $PROGRAM . WARN_ALERT .$SCRIPT_PID . $TSTAMP "
return
return
elif [ " $level " = = "NOTICE" ] ; then
elif [ " $level " = = "NOTICE" ] ; then
if [ " $_LOGGER_ERR_ONLY " != true ] ; then
if [ " $_LOGGER_ERR_ONLY " != true ] ; then
@ -423,11 +425,11 @@ function GenericTrapQuit {
local exitcode = 0
local exitcode = 0
# Get ERROR / WARN alert flags from subprocesses that call Logger
# Get ERROR / WARN alert flags from subprocesses that call Logger
if [ -f " $RUN_DIR / $PROGRAM . Logger.warn .$SCRIPT_PID . $TSTAMP " ] ; then
if [ -f " $RUN_DIR / $PROGRAM . WARN_ALERT .$SCRIPT_PID . $TSTAMP " ] ; then
WARN_ALERT = true
WARN_ALERT = true
exitcode = 2
exitcode = 2
fi
fi
if [ -f " $RUN_DIR / $PROGRAM . Logger.error .$SCRIPT_PID . $TSTAMP " ] ; then
if [ -f " $RUN_DIR / $PROGRAM . ERROR_ALERT .$SCRIPT_PID . $TSTAMP " ] ; then
ERROR_ALERT = true
ERROR_ALERT = true
exitcode = 1
exitcode = 1
fi
fi
@ -487,7 +489,11 @@ function SendAlert {
fi
fi
fi
fi
body = " $MAIL_ALERT_MSG " $'\n\n' "Last 1000 lines of current log" $'\n\n' " $( tail -n 1000 " $RUN_DIR / $PROGRAM ._Logger. $SCRIPT_PID . $TSTAMP " ) "
if [ " $_LOGGER_WRITE_PARTIAL_LOGS " = = true ] ; then
body = " $MAIL_ALERT_MSG " $'\n\n' "Last 1000 lines of current log" $'\n\n' " $( tail -n 1000 " $RUN_DIR / $PROGRAM ._Logger. $SCRIPT_PID . $TSTAMP " ) "
else
body = " $MAIL_ALERT_MSG " $'\n\n' "Last 1000 lines of current log" $'\n\n' " $( tail -n 1000 " $LOG_FILE " ) "
fi
if [ $ERROR_ALERT = = true ] ; then
if [ $ERROR_ALERT = = true ] ; then
subject = " Error alert for $INSTANCE_ID "
subject = " Error alert for $INSTANCE_ID "
@ -980,7 +986,7 @@ function ExecTasks {
# soft / hard execution time checks that needs to be a subfunction since it is called both from main loop and from parallelExec sub loop
# soft / hard execution time checks that needs to be a subfunction since it is called both from main loop and from parallelExec sub loop
function _ExecTasksTimeCheck {
function _ExecTasksTimeCheck {
if [ $spinner = = true ] ; then
if [ $spinner = = true ] && [ " $_OFUNCTIONS_SHOW_SPINNER " != false ] ; then
Spinner
Spinner
fi
fi
if [ $counting = = true ] ; then
if [ $counting = = true ] ; then
@ -2477,16 +2483,8 @@ function FileMove () {
mv -f " $source " " $dest "
mv -f " $source " " $dest "
return $?
return $?
elif [ -w " $source " ] ; then
elif [ -w " $source " ] ; then
if [ -f " $dest " ] ; then # for files we don't need recursive delete
[ -f " $dest " ] && rm -f " $dest "
rm -f " $dest "
cp -p " $source " " $dest " && rm -f " $source "
elif [ -d " $dest " ] ; then # for directories we need recursive delete
rm -rf " $dest "
fi
if [ -f " $source " ] ; then
cp -p " $source " " $dest " && rm -f " $source " # for files we don't need recursive copy & delete
elif [ -d " $source " ] ; then
cp -rp " $source " " $dest " && rm -rf " $source " # for directories we need recursive copy & delete
fi
return $?
return $?
else
else
return -1
return -1
@ -2641,6 +2639,7 @@ _OFUNCTIONS_BOOTSTRAP=true
[ " $_OFUNCTIONS_BOOTSTRAP " != true ] && echo " Please use bootstrap.sh to load this dev version of $( basename $0 ) or build it with merge.sh " && exit 1
[ " $_OFUNCTIONS_BOOTSTRAP " != true ] && echo " Please use bootstrap.sh to load this dev version of $( basename $0 ) or build it with merge.sh " && exit 1
_LOGGER_PREFIX = "time"
_LOGGER_PREFIX = "time"
_LOGGER_WRITE_PARTIAL_LOGS = true
## Working directory. This directory exists in any replica and contains state files, backups, soft deleted files etc
## Working directory. This directory exists in any replica and contains state files, backups, soft deleted files etc
OSYNC_DIR = ".osync_workdir"
OSYNC_DIR = ".osync_workdir"
@ -3056,7 +3055,7 @@ function _Logger {
echo -e " $logValue " >> " $LOG_FILE "
echo -e " $logValue " >> " $LOG_FILE "
# Build current log file for alerts if we have a sufficient environment
# Build current log file for alerts if we have a sufficient environment
if [ " $ RUN_DIR/ $PROGRAM " != "/" ] ; then
if [ " $ _LOGGER_WRITE_PARTIAL_LOGS" = = true ] && [ " $ RUN_DIR/ $PROGRAM " != "/" ] ; then
echo -e " $logValue " >> " $RUN_DIR / $PROGRAM ._Logger. $SCRIPT_PID . $TSTAMP "
echo -e " $logValue " >> " $RUN_DIR / $PROGRAM ._Logger. $SCRIPT_PID . $TSTAMP "
fi
fi
fi
fi
@ -3485,7 +3484,7 @@ function _Logger {
echo -e " $logValue " >> " $LOG_FILE "
echo -e " $logValue " >> " $LOG_FILE "
# Build current log file for alerts if we have a sufficient environment
# Build current log file for alerts if we have a sufficient environment
if [ " $ RUN_DIR/ $PROGRAM " != "/" ] ; then
if [ " $ _LOGGER_WRITE_PARTIAL_LOGS" = = true ] && [ " $ RUN_DIR/ $PROGRAM " != "/" ] ; then
echo -e " $logValue " >> " $RUN_DIR / $PROGRAM ._Logger. $SCRIPT_PID . $TSTAMP "
echo -e " $logValue " >> " $RUN_DIR / $PROGRAM ._Logger. $SCRIPT_PID . $TSTAMP "
fi
fi
fi
fi
@ -4118,7 +4117,7 @@ function _Logger {
echo -e " $logValue " >> " $LOG_FILE "
echo -e " $logValue " >> " $LOG_FILE "
# Build current log file for alerts if we have a sufficient environment
# Build current log file for alerts if we have a sufficient environment
if [ " $ RUN_DIR/ $PROGRAM " != "/" ] ; then
if [ " $ _LOGGER_WRITE_PARTIAL_LOGS" = = true ] && [ " $ RUN_DIR/ $PROGRAM " != "/" ] ; then
echo -e " $logValue " >> " $RUN_DIR / $PROGRAM ._Logger. $SCRIPT_PID . $TSTAMP "
echo -e " $logValue " >> " $RUN_DIR / $PROGRAM ._Logger. $SCRIPT_PID . $TSTAMP "
fi
fi
fi
fi
@ -4768,7 +4767,7 @@ function _Logger {
echo -e " $logValue " >> " $LOG_FILE "
echo -e " $logValue " >> " $LOG_FILE "
# Build current log file for alerts if we have a sufficient environment
# Build current log file for alerts if we have a sufficient environment
if [ " $ RUN_DIR/ $PROGRAM " != "/" ] ; then
if [ " $ _LOGGER_WRITE_PARTIAL_LOGS" = = true ] && [ " $ RUN_DIR/ $PROGRAM " != "/" ] ; then
echo -e " $logValue " >> " $RUN_DIR / $PROGRAM ._Logger. $SCRIPT_PID . $TSTAMP "
echo -e " $logValue " >> " $RUN_DIR / $PROGRAM ._Logger. $SCRIPT_PID . $TSTAMP "
fi
fi
fi
fi
@ -4873,16 +4872,8 @@ function FileMove () {
mv -f " $source " " $dest "
mv -f " $source " " $dest "
return $?
return $?
elif [ -w " $source " ] ; then
elif [ -w " $source " ] ; then
if [ -f " $dest " ] ; then # for files we don't need recursive delete
[ -f " $dest " ] && rm -f " $dest "
rm -f " $dest "
cp -p " $source " " $dest " && rm -f " $source "
elif [ -d " $dest " ] ; then # for directories we need recursive delete
rm -rf " $dest "
fi
if [ -f " $source " ] ; then
cp -p " $source " " $dest " && rm -f " $source " # for files we don't need recursive copy & delete
elif [ -d " $source " ] ; then
cp -rp " $source " " $dest " && rm -rf " $source " # for directories we need recursive copy & delete
fi
return $?
return $?
else
else
return -1
return -1
@ -5783,7 +5774,7 @@ function _Logger {
echo -e " $logValue " >> " $LOG_FILE "
echo -e " $logValue " >> " $LOG_FILE "
# Build current log file for alerts if we have a sufficient environment
# Build current log file for alerts if we have a sufficient environment
if [ " $ RUN_DIR/ $PROGRAM " != "/" ] ; then
if [ " $ _LOGGER_WRITE_PARTIAL_LOGS" = = true ] && [ " $ RUN_DIR/ $PROGRAM " != "/" ] ; then
echo -e " $logValue " >> " $RUN_DIR / $PROGRAM ._Logger. $SCRIPT_PID . $TSTAMP "
echo -e " $logValue " >> " $RUN_DIR / $PROGRAM ._Logger. $SCRIPT_PID . $TSTAMP "
fi
fi
fi
fi
@ -6071,7 +6062,7 @@ function _Logger {
echo -e " $logValue " >> " $LOG_FILE "
echo -e " $logValue " >> " $LOG_FILE "
# Build current log file for alerts if we have a sufficient environment
# Build current log file for alerts if we have a sufficient environment
if [ " $ RUN_DIR/ $PROGRAM " != "/" ] ; then
if [ " $ _LOGGER_WRITE_PARTIAL_LOGS" = = true ] && [ " $ RUN_DIR/ $PROGRAM " != "/" ] ; then
echo -e " $logValue " >> " $RUN_DIR / $PROGRAM ._Logger. $SCRIPT_PID . $TSTAMP "
echo -e " $logValue " >> " $RUN_DIR / $PROGRAM ._Logger. $SCRIPT_PID . $TSTAMP "
fi
fi
fi
fi
@ -6596,6 +6587,7 @@ function Usage {
echo "--no-prefix Will suppress time / date suffix from output"
echo "--no-prefix Will suppress time / date suffix from output"
echo "--silent Will run osync without any output to stdout, used for cron jobs"
echo "--silent Will run osync without any output to stdout, used for cron jobs"
echo "--errors-only Output only errors (can be combined with silent or verbose)"
echo "--errors-only Output only errors (can be combined with silent or verbose)"
echo "--non-interactive Don't show running animation in cron / service mode"
echo "--summary Outputs a list of transferred / deleted files at the end of the run"
echo "--summary Outputs a list of transferred / deleted files at the end of the run"
echo "--log-conflicts [EXPERIMENTAL] Outputs a list of conflicted files"
echo "--log-conflicts [EXPERIMENTAL] Outputs a list of conflicted files"
echo "--alert-conflicts Send an email if conflictual files found (implies --log-conflicts)"
echo "--alert-conflicts Send an email if conflictual files found (implies --log-conflicts)"
@ -6872,6 +6864,10 @@ function GetCommandlineArguments {
opts = $opts " --errors-only"
opts = $opts " --errors-only"
_LOGGER_ERR_ONLY = true
_LOGGER_ERR_ONLY = true
; ;
; ;
--non-interactive)
opts$opts " --non-interactive"
_OFUNCTIONS_SHOW_SPINNER = false
; ;
--summary)
--summary)
opts = $opts " --summary"
opts = $opts " --summary"
_SUMMARY = true
_SUMMARY = true