Added --summary and --no-prefix arguments
This commit is contained in:
parent
4fb0b5f5f7
commit
63c64c5d5e
|
@ -4,7 +4,7 @@ PROGRAM="osync" # Rsync based two way sync engine with fault tolerance
|
||||||
AUTHOR="(C) 2013-2016 by Orsiris de Jong"
|
AUTHOR="(C) 2013-2016 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.2-beta2
|
PROGRAM_VERSION=1.2-beta2
|
||||||
PROGRAM_BUILD=2016111401
|
PROGRAM_BUILD=2016111403
|
||||||
IS_STABLE=no
|
IS_STABLE=no
|
||||||
|
|
||||||
# Execution order #__WITH_PARANOIA_DEBUG
|
# Execution order #__WITH_PARANOIA_DEBUG
|
||||||
|
@ -1003,6 +1003,7 @@ function _deleteLocal {
|
||||||
Logger "Moving deleted file [$replicaDir$files] to [$replicaDir$deletionDir]." "VERBOSE"
|
Logger "Moving deleted file [$replicaDir$files] to [$replicaDir$deletionDir]." "VERBOSE"
|
||||||
mv -f "$replicaDir$files" "$replicaDir$deletionDir"
|
mv -f "$replicaDir$files" "$replicaDir$deletionDir"
|
||||||
fi
|
fi
|
||||||
|
echo "$replicaDir$files" >> "$RUN_DIR/$PROGRAM.delete.$replicaType.$SCRIPT_PID"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot move [$replicaDir$files] to deletion directory." "ERROR"
|
Logger "Cannot move [$replicaDir$files] to deletion directory." "ERROR"
|
||||||
echo "$files" >> "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/$replicaType${INITIATOR[$__failedDeletedListFile]}"
|
echo "$files" >> "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/$replicaType${INITIATOR[$__failedDeletedListFile]}"
|
||||||
|
@ -1680,6 +1681,43 @@ function SoftDelete {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _SummaryFromFile {
|
||||||
|
local summaryFile="${1}"
|
||||||
|
local direction="${2}"
|
||||||
|
|
||||||
|
__CheckArguments 0 $# "${FUNCNAME[0]}" "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
|
if [ -f "$summaryFile" ]; then
|
||||||
|
while read -r file; do
|
||||||
|
Logger "$direction $(echo $file | awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}')" "ALWAYS"
|
||||||
|
done < "$summaryFile"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function Summary {
|
||||||
|
__CheckArguments 0 $# "${FUNCNAME[0]}" "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
|
local prefix
|
||||||
|
|
||||||
|
prefix="$_LOGGER_PREFIX"
|
||||||
|
_LOGGER_PREFIX=""
|
||||||
|
|
||||||
|
Logger "File attribute updates: INITIATOR << >> TARGET" "ALWAYS"
|
||||||
|
|
||||||
|
_SummaryFromFile "$RUN_DIR/$PROGRAM.attr-update.target.$SCRIPT_PID" ">>"
|
||||||
|
_SummaryFromFile "$RUN_DIR/$PROGRAM.attr-update.initiator.$SCRIPT_PID" "<<"
|
||||||
|
|
||||||
|
Logger "File transfers: INITIATOR << >> TARGET" "ALWAYS"
|
||||||
|
_SummaryFromFile "$RUN_DIR/$PROGRAM.update.target.$SCRIPT_PID" ">>"
|
||||||
|
_SummaryFromFile "$RUN_DIR/$PROGRAM.update.initiator.$SCRIPT_PID" "<<"
|
||||||
|
|
||||||
|
Logger "File deletions: INITIATOR << >> TARGET" "ALWAYS"
|
||||||
|
_SummaryFromFile "$RUN_DIR/$PROGRAM.attr-update.target.$SCRIPT_PID" ">>"
|
||||||
|
_SummaryFromFile "$RUN_DIR/$PROGRAM.attr-update.initiator.$SCRIPT_PID" "<<"
|
||||||
|
|
||||||
|
_LOGGER_PREFIX="$prefix"
|
||||||
|
}
|
||||||
|
|
||||||
function Init {
|
function Init {
|
||||||
__CheckArguments 0 $# "${FUNCNAME[0]}" "$@" #__WITH_PARANOIA_DEBUG
|
__CheckArguments 0 $# "${FUNCNAME[0]}" "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
|
@ -1815,7 +1853,7 @@ function Init {
|
||||||
## Set sync only function arguments for rsync
|
## Set sync only function arguments for rsync
|
||||||
SYNC_OPTS="-u"
|
SYNC_OPTS="-u"
|
||||||
|
|
||||||
if [ $_VERBOSE == true ]; then
|
if [ $_VERBOSE == true ] || [ $_SUMMARY == true ]; then
|
||||||
SYNC_OPTS=$SYNC_OPTS" -i"
|
SYNC_OPTS=$SYNC_OPTS" -i"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1876,8 +1914,10 @@ function Usage {
|
||||||
echo ""
|
echo ""
|
||||||
echo "[OPTIONS]"
|
echo "[OPTIONS]"
|
||||||
echo "--dry Will run osync without actually doing anything; just testing"
|
echo "--dry Will run osync without actually doing anything; just testing"
|
||||||
|
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 "--summary Outputs a list of transferred / deleted files at the end of the run"
|
||||||
echo "--verbose Increases output"
|
echo "--verbose Increases output"
|
||||||
echo "--stats Adds rsync transfer statistics to verbose output"
|
echo "--stats Adds rsync transfer statistics to verbose output"
|
||||||
echo "--partial Allows rsync to keep partial downloads that can be resumed later (experimental)"
|
echo "--partial Allows rsync to keep partial downloads that can be resumed later (experimental)"
|
||||||
|
@ -1951,7 +1991,6 @@ fi
|
||||||
|
|
||||||
INITIATOR_LOCK_FILE_EXISTS=false
|
INITIATOR_LOCK_FILE_EXISTS=false
|
||||||
TARGET_LOCK_FILE_EXISTS=false
|
TARGET_LOCK_FILE_EXISTS=false
|
||||||
|
|
||||||
FORCE_UNLOCK=false
|
FORCE_UNLOCK=false
|
||||||
no_maxtime=false
|
no_maxtime=false
|
||||||
opts=""
|
opts=""
|
||||||
|
@ -1964,6 +2003,7 @@ _QUICK_SYNC=0
|
||||||
sync_on_changes=false
|
sync_on_changes=false
|
||||||
_NOLOCKS=false
|
_NOLOCKS=false
|
||||||
osync_cmd=$0
|
osync_cmd=$0
|
||||||
|
_SUMMARY=false
|
||||||
|
|
||||||
if [ $# -eq 0 ]
|
if [ $# -eq 0 ]
|
||||||
then
|
then
|
||||||
|
@ -2043,8 +2083,15 @@ for i in "$@"; do
|
||||||
_NOLOCKS=true
|
_NOLOCKS=true
|
||||||
;;
|
;;
|
||||||
--errors-only)
|
--errors-only)
|
||||||
_LOGGER_STDERR=True
|
#TODO: let err_only only output to stderr
|
||||||
_LOGGER_ERR_ONLY=True
|
#_LOGGER_STDERR=true
|
||||||
|
_LOGGER_ERR_ONLY=true
|
||||||
|
;;
|
||||||
|
--summary)
|
||||||
|
_SUMMARY=true
|
||||||
|
;;
|
||||||
|
--no-prefix)
|
||||||
|
_LOGGER_PREFIX=""
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
if [ $first == "0" ]; then
|
if [ $first == "0" ]; then
|
||||||
|
@ -2129,19 +2176,16 @@ opts="${opts# *}"
|
||||||
CheckCurrentConfig
|
CheckCurrentConfig
|
||||||
fi
|
fi
|
||||||
CheckCurrentConfigAll
|
CheckCurrentConfigAll
|
||||||
|
|
||||||
DATE=$(date)
|
DATE=$(date)
|
||||||
Logger "-------------------------------------------------------------" "NOTICE"
|
Logger "-------------------------------------------------------------" "NOTICE"
|
||||||
Logger "$DRY_WARNING $DATE - $PROGRAM $PROGRAM_VERSION script begin." "NOTICE"
|
Logger "$DRY_WARNING $DATE - $PROGRAM $PROGRAM_VERSION script begin." "ALWAYS"
|
||||||
Logger "-------------------------------------------------------------" "NOTICE"
|
Logger "-------------------------------------------------------------" "NOTICE"
|
||||||
Logger "Sync task [$INSTANCE_ID] launched as $LOCAL_USER@$LOCAL_HOST (PID $SCRIPT_PID)" "NOTICE"
|
Logger "Sync task [$INSTANCE_ID] launched as $LOCAL_USER@$LOCAL_HOST (PID $SCRIPT_PID)" "NOTICE"
|
||||||
|
|
||||||
if [ $sync_on_changes == true ]; then
|
if [ $sync_on_changes == true ]; then
|
||||||
SyncOnChanges
|
SyncOnChanges
|
||||||
else
|
else
|
||||||
GetRemoteOS
|
GetRemoteOS
|
||||||
InitRemoteOSSettings
|
InitRemoteOSSettings
|
||||||
|
|
||||||
if [ $no_maxtime == true ]; then
|
if [ $no_maxtime == true ]; then
|
||||||
SOFT_MAX_EXEC_TIME=0
|
SOFT_MAX_EXEC_TIME=0
|
||||||
HARD_MAX_EXEC_TIME=0
|
HARD_MAX_EXEC_TIME=0
|
||||||
|
@ -2153,4 +2197,7 @@ opts="${opts# *}"
|
||||||
if [ $? == 0 ]; then
|
if [ $? == 0 ]; then
|
||||||
SoftDelete
|
SoftDelete
|
||||||
fi
|
fi
|
||||||
|
if [ $_SUMMARY == true ]; then
|
||||||
|
Summary
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
## PROGRAM=program-name
|
## PROGRAM=program-name
|
||||||
## INSTANCE_ID=program-instance-name
|
## INSTANCE_ID=program-instance-name
|
||||||
## _DEBUG=yes/no
|
## _DEBUG=yes/no
|
||||||
## _LOGGER_STDERR=true/False
|
## _LOGGER_STDERR=true/false
|
||||||
## _LOGGER_ERR_ONLY=true/False
|
## _LOGGER_ERR_ONLY=true/false
|
||||||
## _LOGGER_PREFIX="date"/"time"/""
|
## _LOGGER_PREFIX="date"/"time"/""
|
||||||
|
|
||||||
#TODO: Windows checks, check sendmail & mailsend
|
#TODO: Windows checks, check sendmail & mailsend
|
||||||
|
@ -282,7 +282,7 @@ function SendAlert {
|
||||||
eval "cat \"$LOG_FILE\" $COMPRESSION_PROGRAM > $ALERT_LOG_FILE"
|
eval "cat \"$LOG_FILE\" $COMPRESSION_PROGRAM > $ALERT_LOG_FILE"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot create [$ALERT_LOG_FILE]" "WARN"
|
Logger "Cannot create [$ALERT_LOG_FILE]" "WARN"
|
||||||
attachment=False
|
attachment=false
|
||||||
else
|
else
|
||||||
attachment=true
|
attachment=true
|
||||||
fi
|
fi
|
||||||
|
@ -501,7 +501,7 @@ function LoadConfigFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Spinner {
|
function Spinner {
|
||||||
if [ $_SILENT == true ]; then
|
if [ $_SILENT == true ] || [ $_LOGGER_ERR_ONLY == true ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue