Replaced 0,1 with false,true

This commit is contained in:
deajan 2016-08-29 13:54:24 +02:00
parent 385bc5d40f
commit 472e5e2251
1 changed files with 63 additions and 52 deletions

View File

@ -71,7 +71,7 @@ function TrapStop {
function TrapQuit { function TrapQuit {
local exitcode local exitcode
if [ $ERROR_ALERT -ne 0 ]; then if [ $ERROR_ALERT == true ]; then
UnlockReplicas UnlockReplicas
if [ "$_DEBUG" != "yes" ] if [ "$_DEBUG" != "yes" ]
then then
@ -85,7 +85,7 @@ function TrapQuit {
CleanUp CleanUp
Logger "$PROGRAM finished with errors." "ERROR" Logger "$PROGRAM finished with errors." "ERROR"
exitcode=1 exitcode=1
elif [ $WARN_ALERT -ne 0 ]; then elif [ $WARN_ALERT == true ]; then
UnlockReplicas UnlockReplicas
if [ "$_DEBUG" != "yes" ] if [ "$_DEBUG" != "yes" ]
then then
@ -452,12 +452,12 @@ function CheckLocks {
local pids local pids
if [ $_NOLOCKS -eq 1 ]; then if [ $_NOLOCKS == true ]; then
return 0 return 0
fi fi
# Do not bother checking for locks when FORCE_UNLOCK is set # Do not bother checking for locks when FORCE_UNLOCK is set
if [ $FORCE_UNLOCK -eq 1 ]; then if [ $FORCE_UNLOCK == true ]; then
WriteLockFiles WriteLockFiles
if [ $? != 0 ]; then if [ $? != 0 ]; then
exit 1 exit 1
@ -593,7 +593,7 @@ function UnlockReplicas {
local pids local pids
if [ $_NOLOCKS -eq 1 ]; then if [ $_NOLOCKS == true ]; then
return 0 return 0
fi fi
@ -706,6 +706,14 @@ function _get_file_ctime_mtime_local {
echo -n "" > "$RUN_DIR/$PROGRAM.ctime_mtime.$replica_type.$SCRIPT_PID" echo -n "" > "$RUN_DIR/$PROGRAM.ctime_mtime.$replica_type.$SCRIPT_PID"
while read -r file; do $STAT_CTIME_MTIME_CMD "$replica_path$file" | sort >> "$RUN_DIR/$PROGRAM.ctime_mtime.$replica_type.$SCRIPT_PID"; done < "$file_list" while read -r file; do $STAT_CTIME_MTIME_CMD "$replica_path$file" | sort >> "$RUN_DIR/$PROGRAM.ctime_mtime.$replica_type.$SCRIPT_PID"; done < "$file_list"
if [ $? != 0 ]; then
Logger "Getting file attributes failed [$retval] on $replica_type. Stopping execution." "CRITICAL"
if [ $_VERBOSE == true ] && [ -f "$RUN_DIR/$PROGRAM.ctime_mtime.$replica_type.$SCRIPT_PID" ]; then
Logger "Command output:\n$(cat $RUN_DIR/$PROGRAM.ctime_mtime.$replica_type.$SCRIPT_PID)" "NOTICE"
fi
exit 1
fi
} }
function _get_file_ctime_mtime_remote { function _get_file_ctime_mtime_remote {
@ -721,7 +729,7 @@ function _get_file_ctime_mtime_remote {
eval "$cmd" eval "$cmd"
if [ $? != 0 ]; then if [ $? != 0 ]; then
Logger "Getting file attributes failed [$retval] on $replica_type. Stopping execution." "CRITICAL" Logger "Getting file attributes failed [$retval] on $replica_type. Stopping execution." "CRITICAL"
if [ $_VERBOSE -eq 0 ] && [ -f "$RUN_DIR/$PROGRAM.ctime_mtime.$replica_type.$SCRIPT_PID" ]; then if [ $_VERBOSE == true ] && [ -f "$RUN_DIR/$PROGRAM.ctime_mtime.$replica_type.$SCRIPT_PID" ]; then
Logger "Command output:\n$(cat $RUN_DIR/$PROGRAM.ctime_mtime.$replica_type.$SCRIPT_PID)" "NOTICE" Logger "Command output:\n$(cat $RUN_DIR/$PROGRAM.ctime_mtime.$replica_type.$SCRIPT_PID)" "NOTICE"
fi fi
exit 1 exit 1
@ -752,13 +760,13 @@ function sync_attrs {
eval "$rsync_cmd" eval "$rsync_cmd"
WaitForTaskCompletion $! $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME ${FUNCNAME[0]} false $KEEP_LOGGING WaitForTaskCompletion $! $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME ${FUNCNAME[0]} false $KEEP_LOGGING
retval=$? retval=$?
if [ $_VERBOSE -eq 1 ] && [ -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" ]; then if [ $_VERBOSE == true ] && [ -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" ]; then
Logger "List:\n$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID)" "NOTICE" Logger "List:\n$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID)" "NOTICE"
fi fi
if [ $retval != 0 ] && [ $retval != 24 ]; then if [ $retval != 0 ] && [ $retval != 24 ]; then
Logger "Getting list of files that need updates failed [$retval]. Stopping execution." "CRITICAL" Logger "Getting list of files that need updates failed [$retval]. Stopping execution." "CRITICAL"
if [ $_VERBOSE -eq 0 ] && [ -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" ]; then if [ $_VERBOSE == false ] && [ -f "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" ]; then
Logger "Rsync output:\n$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID)" "NOTICE" Logger "Rsync output:\n$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID)" "NOTICE"
fi fi
exit 1 #WIP: check why exit $retval was used exit 1 #WIP: check why exit $retval was used
@ -832,13 +840,13 @@ function sync_attrs {
eval "$rsync_cmd" eval "$rsync_cmd"
WaitForTaskCompletion $! $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME ${FUNCNAME[0]} false $KEEP_LOGGING WaitForTaskCompletion $! $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME ${FUNCNAME[0]} false $KEEP_LOGGING
retval=$? retval=$?
if [ $_VERBOSE -eq 1 ] && [ -f "$RUN_DIR/$PROGRAM.attr-update.$dest_replica.$SCRIPT_PID" ]; then if [ $_VERBOSE == true ] && [ -f "$RUN_DIR/$PROGRAM.attr-update.$dest_replica.$SCRIPT_PID" ]; then
Logger "List:\n$(cat $RUN_DIR/$PROGRAM.attr-update.$dest_replica.$SCRIPT_PID)" "NOTICE" Logger "List:\n$(cat $RUN_DIR/$PROGRAM.attr-update.$dest_replica.$SCRIPT_PID)" "NOTICE"
fi fi
if [ $retval != 0 ] && [ $retval != 24 ]; then if [ $retval != 0 ] && [ $retval != 24 ]; then
Logger "Updating file attributes on $dest_replica [$retval]. Stopping execution." "CRITICAL" Logger "Updating file attributes on $dest_replica [$retval]. Stopping execution." "CRITICAL"
if [ $_VERBOSE -eq 0 ] && [ -f "$RUN_DIR/$PROGRAM.attr-update.$dest_replica.$SCRIPT_PID" ]; then if [ $_VERBOSE == false ] && [ -f "$RUN_DIR/$PROGRAM.attr-update.$dest_replica.$SCRIPT_PID" ]; then
Logger "Rsync output:\n$(cat $RUN_DIR/$PROGRAM.attr-update.$dest_replica.$SCRIPT_PID)" "NOTICE" Logger "Rsync output:\n$(cat $RUN_DIR/$PROGRAM.attr-update.$dest_replica.$SCRIPT_PID)" "NOTICE"
fi fi
exit 1 #WIP check why exit $retval was used exit 1 #WIP check why exit $retval was used
@ -886,13 +894,13 @@ function sync_update {
Logger "RSYNC_CMD: $rsync_cmd" "DEBUG" Logger "RSYNC_CMD: $rsync_cmd" "DEBUG"
eval "$rsync_cmd" eval "$rsync_cmd"
retval=$? retval=$?
if [ $_VERBOSE -eq 1 ] && [ -f "$RUN_DIR/$PROGRAM.update.$destination_replica.$SCRIPT_PID" ]; then if [ $_VERBOSE == true ] && [ -f "$RUN_DIR/$PROGRAM.update.$destination_replica.$SCRIPT_PID" ]; then
Logger "List:\n$(cat $RUN_DIR/$PROGRAM.update.$destination_replica.$SCRIPT_PID)" "NOTICE" Logger "List:\n$(cat $RUN_DIR/$PROGRAM.update.$destination_replica.$SCRIPT_PID)" "NOTICE"
fi fi
if [ $retval != 0 ] && [ $retval != 24 ]; then if [ $retval != 0 ] && [ $retval != 24 ]; then
Logger "Updating $destination_replica replica failed. Stopping execution." "CRITICAL" Logger "Updating $destination_replica replica failed. Stopping execution." "CRITICAL"
if [ $_VERBOSE -eq 0 ] && [ -f "$RUN_DIR/$PROGRAM.update.$destination_replica.$SCRIPT_PID" ]; then if [ $_VERBOSE == false ] && [ -f "$RUN_DIR/$PROGRAM.update.$destination_replica.$SCRIPT_PID" ]; then
Logger "Rsync output:\n$(cat $RUN_DIR/$PROGRAM.update.$destination_replica.$SCRIPT_PID)" "NOTICE" Logger "Rsync output:\n$(cat $RUN_DIR/$PROGRAM.update.$destination_replica.$SCRIPT_PID)" "NOTICE"
fi fi
exit 1 #WIP exit $retval exit 1 #WIP exit $retval
@ -913,7 +921,7 @@ function _delete_local {
local parentdir local parentdir
local previous_file="" local previous_file=""
if [ ! -d "$replica_dir$deletion_dir" ] && [ $_DRYRUN -ne 1 ]; then if [ ! -d "$replica_dir$deletion_dir" ] && [ $_DRYRUN == false ]; then
$COMMAND_SUDO mkdir -p "$replica_dir$deletion_dir" $COMMAND_SUDO mkdir -p "$replica_dir$deletion_dir"
if [ $? != 0 ]; then if [ $? != 0 ]; then
Logger "Cannot create local replica deletion directory in [$replica_dir$deletion_dir]." "ERROR" Logger "Cannot create local replica deletion directory in [$replica_dir$deletion_dir]." "ERROR"
@ -924,12 +932,12 @@ function _delete_local {
while read -r files; do while read -r files; do
## On every run, check wheter the next item is already deleted because it is included in a directory already deleted ## On every run, check wheter the next item is already deleted because it is included in a directory already deleted
if [[ "$files" != "$previous_file/"* ]] && [ "$files" != "" ]; then if [[ "$files" != "$previous_file/"* ]] && [ "$files" != "" ]; then
if [ $_VERBOSE -eq 1 ]; then if [ $_VERBOSE == true ]; then
Logger "Soft deleting $replica_dir$files" "NOTICE" Logger "Soft deleting $replica_dir$files" "NOTICE"
fi fi
if [ "$SOFT_DELETE" != "no" ]; then if [ "$SOFT_DELETE" != "no" ]; then
if [ $_DRYRUN -ne 1 ]; then if [ $_DRYRUN == false ]; then
if [ -e "$replica_dir$deletion_dir/$files" ]; then if [ -e "$replica_dir$deletion_dir/$files" ]; then
rm -rf "${replica_dir:?}$deletion_dir/$files" rm -rf "${replica_dir:?}$deletion_dir/$files"
Logger "Deleting file [$replica_dir$files]." "DEBUG" Logger "Deleting file [$replica_dir$files]." "DEBUG"
@ -954,7 +962,7 @@ function _delete_local {
fi fi
fi fi
else else
if [ $_DRYRUN -ne 1 ]; then if [ $_DRYRUN == false ]; then
if [ -e "$replica_dir$files" ]; then if [ -e "$replica_dir$files" ]; then
rm -rf "$replica_dir$files" rm -rf "$replica_dir$files"
if [ $? != 0 ]; then if [ $? != 0 ]; then
@ -1003,7 +1011,7 @@ $SSH_CMD ERROR_ALERT=0 sync_on_changes=$sync_on_changes _SILENT=$_SILENT _DEBUG=
local value="${1}" # What to log local value="${1}" # What to log
echo -e "$value" >&2 #TODO(high): logfile output missing echo -e "$value" >&2 #TODO(high): logfile output missing
if [ $_SILENT -eq 0 ]; then if [ $_SILENT == false ]; then
echo -e "$value" echo -e "$value"
fi fi
} }
@ -1040,7 +1048,7 @@ $SSH_CMD ERROR_ALERT=0 sync_on_changes=$sync_on_changes _SILENT=$_SILENT _DEBUG=
parentdir= parentdir=
previous_file="" previous_file=""
if [ ! -d "$REPLICA_DIR$DELETE_DIR" ] && [ $_DRYRUN -ne 1 ]; then if [ ! -d "$REPLICA_DIR$DELETE_DIR" ] && [ $_DRYRUN == false ]; then
$COMMAND_SUDO mkdir -p "$REPLICA_DIR$DELETE_DIR" $COMMAND_SUDO mkdir -p "$REPLICA_DIR$DELETE_DIR"
if [ $? != 0 ]; then if [ $? != 0 ]; then
Logger "Cannot create remote replica deletion directory in [$REPLICA_DIR$DELETE_DIR]." "ERROR" Logger "Cannot create remote replica deletion directory in [$REPLICA_DIR$DELETE_DIR]." "ERROR"
@ -1051,12 +1059,12 @@ $SSH_CMD ERROR_ALERT=0 sync_on_changes=$sync_on_changes _SILENT=$_SILENT _DEBUG=
while read -r files; do while read -r files; do
## On every run, check wheter the next item is already deleted because it is included in a directory already deleted ## On every run, check wheter the next item is already deleted because it is included in a directory already deleted
if [[ "$files" != "$previous_file/"* ]] && [ "$files" != "" ]; then if [[ "$files" != "$previous_file/"* ]] && [ "$files" != "" ]; then
if [ $_VERBOSE -eq 1 ]; then if [ $_VERBOSE == true ]; then
Logger "Soft deleting $REPLICA_DIR$files" "NOTICE" Logger "Soft deleting $REPLICA_DIR$files" "NOTICE"
fi fi
if [ "$SOFT_DELETE" != "no" ]; then if [ "$SOFT_DELETE" != "no" ]; then
if [ $_DRYRUN -ne 1 ]; then if [ $_DRYRUN == false ]; then
if [ -e "$REPLICA_DIR$DELETE_DIR/$files" ]; then if [ -e "$REPLICA_DIR$DELETE_DIR/$files" ]; then
$COMMAND_SUDO rm -rf "$REPLICA_DIR$DELETE_DIR/$files" $COMMAND_SUDO rm -rf "$REPLICA_DIR$DELETE_DIR/$files"
Logger "Deleting file [$REPLICA_DIR$files]." "DEBUG" Logger "Deleting file [$REPLICA_DIR$files]." "DEBUG"
@ -1080,7 +1088,7 @@ $SSH_CMD ERROR_ALERT=0 sync_on_changes=$sync_on_changes _SILENT=$_SILENT _DEBUG=
fi fi
fi fi
else else
if [ $_DRYRUN -ne 1 ]; then if [ $_DRYRUN == false ]; then
if [ -e "$REPLICA_DIR$files" ]; then if [ -e "$REPLICA_DIR$files" ]; then
$COMMAND_SUDO rm -rf "$REPLICA_DIR$files" $COMMAND_SUDO rm -rf "$REPLICA_DIR$files"
if [ $? != 0 ]; then if [ $? != 0 ]; then
@ -1144,7 +1152,7 @@ function deletion_propagation {
fi fi
retval=$? retval=$?
if [ $retval == 0 ]; then if [ $retval == 0 ]; then
if [ -f "$RUN_DIR/$PROGRAM._delete_remote.$SCRIPT_PID" ] && [ $_VERBOSE -eq 1 ]; then if [ -f "$RUN_DIR/$PROGRAM._delete_remote.$SCRIPT_PID" ] && [ $_VERBOSE == true ]; then
Logger "Remote:\n$(cat $RUN_DIR/$PROGRAM._delete_remote.$SCRIPT_PID)" "DEBUG" Logger "Remote:\n$(cat $RUN_DIR/$PROGRAM._delete_remote.$SCRIPT_PID)" "DEBUG"
fi fi
return $retval return $retval
@ -1494,13 +1502,13 @@ function _SoftDeleteLocal {
local retval local retval
if [ -d "$replica_deletion_path" ]; then if [ -d "$replica_deletion_path" ]; then
if [ $_DRYRUN -eq 1 ]; then if [ $_DRYRUN == true ]; then
Logger "Listing files older than $change_time days on $replica_type replica. Does not remove anything." "NOTICE" Logger "Listing files older than $change_time days on $replica_type replica. Does not remove anything." "NOTICE"
else else
Logger "Removing files older than $change_time days on $replica_type replica." "NOTICE" Logger "Removing files older than $change_time days on $replica_type replica." "NOTICE"
fi fi
if [ $_VERBOSE -eq 1 ]; then if [ $_VERBOSE == true ]; then
# Cannot launch log function from xargs, ugly hack # Cannot launch log function from xargs, ugly hack
$COMMAND_SUDO $FIND_CMD "$replica_deletion_path/" -type f -ctime +$change_time -print0 | xargs -0 -I {} echo "Will delete file {}" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" $COMMAND_SUDO $FIND_CMD "$replica_deletion_path/" -type f -ctime +$change_time -print0 | xargs -0 -I {} echo "Will delete file {}" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID"
Logger "Command output:\n$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID)" "NOTICE" Logger "Command output:\n$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID)" "NOTICE"
@ -1508,7 +1516,7 @@ function _SoftDeleteLocal {
Logger "Command output:\n$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID)" "NOTICE" Logger "Command output:\n$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID)" "NOTICE"
fi fi
if [ $_DRYRUN -ne 1 ]; then if [ $_DRYRUN == false ]; then
$COMMAND_SUDO $FIND_CMD "$replica_deletion_path/" -type f -ctime +$change_time -print0 | xargs -0 -I {} $COMMAND_SUDO rm -f "{}" && $COMMAND_SUDO $FIND_CMD "$replica_deletion_path/" -type d -empty -ctime +$change_time -print0 | xargs -0 -I {} $COMMAND_SUDO rm -rf "{}" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" 2>&1 $COMMAND_SUDO $FIND_CMD "$replica_deletion_path/" -type f -ctime +$change_time -print0 | xargs -0 -I {} $COMMAND_SUDO rm -f "{}" && $COMMAND_SUDO $FIND_CMD "$replica_deletion_path/" -type d -empty -ctime +$change_time -print0 | xargs -0 -I {} $COMMAND_SUDO rm -rf "{}" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" 2>&1
else else
Dummy Dummy
@ -1536,13 +1544,13 @@ function _SoftDeleteRemote {
CheckConnectivity3rdPartyHosts CheckConnectivity3rdPartyHosts
CheckConnectivityRemoteHost CheckConnectivityRemoteHost
if [ $_DRYRUN -eq 1 ]; then if [ $_DRYRUN == true ]; then
Logger "Listing files older than $change_time days on $replica_type replica. Does not remove anything." "NOTICE" Logger "Listing files older than $change_time days on $replica_type replica. Does not remove anything." "NOTICE"
else else
Logger "Removing files older than $change_time days on $replica_type replica." "NOTICE" Logger "Removing files older than $change_time days on $replica_type replica." "NOTICE"
fi fi
if [ $_VERBOSE -eq 1 ]; then if [ $_VERBOSE == true ]; then
# Cannot launch log function from xargs, ugly hack # Cannot launch log function from xargs, ugly hack
cmd=$SSH_CMD' "if [ -d \"'$replica_deletion_path'\" ]; then '$COMMAND_SUDO' '$REMOTE_FIND_CMD' \"'$replica_deletion_path'/\" -type f -ctime +'$change_time' -print0 | xargs -0 -I {} echo Will delete file {} && '$COMMAND_SUDO' '$REMOTE_FIND_CMD' \"'$replica_deletion_path'/\" -type d -empty -ctime '$change_time' -print0 | xargs -0 -I {} echo Will delete directory {}; else echo \"No remote backup/deletion directory.\"; fi" > "'$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID'" 2>&1' cmd=$SSH_CMD' "if [ -d \"'$replica_deletion_path'\" ]; then '$COMMAND_SUDO' '$REMOTE_FIND_CMD' \"'$replica_deletion_path'/\" -type f -ctime +'$change_time' -print0 | xargs -0 -I {} echo Will delete file {} && '$COMMAND_SUDO' '$REMOTE_FIND_CMD' \"'$replica_deletion_path'/\" -type d -empty -ctime '$change_time' -print0 | xargs -0 -I {} echo Will delete directory {}; else echo \"No remote backup/deletion directory.\"; fi" > "'$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID'" 2>&1'
Logger "cmd: $cmd" "DEBUG" Logger "cmd: $cmd" "DEBUG"
@ -1550,7 +1558,7 @@ function _SoftDeleteRemote {
Logger "Command output:\n$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID)" "NOTICE" Logger "Command output:\n$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID)" "NOTICE"
fi fi
if [ $_DRYRUN -ne 1 ]; then if [ $_DRYRUN == false ]; then
cmd=$SSH_CMD' "if [ -d \"'$replica_deletion_path'\" ]; then '$COMMAND_SUDO' '$REMOTE_FIND_CMD' \"'$replica_deletion_path'/\" -type f -ctime +'$change_time' -print0 | xargs -0 -I {} '$COMMAND_SUDO' rm -f \"{}\" && '$COMMAND_SUDO' '$REMOTE_FIND_CMD' \"'$replica_deletion_path'/\" -type d -empty -ctime '$change_time' -print0 | xargs -0 -I {} '$COMMAND_SUDO' rm -rf \"{}\"; else echo \"No remote backup/deletion directory.\"; fi" > "'$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID'" 2>&1' cmd=$SSH_CMD' "if [ -d \"'$replica_deletion_path'\" ]; then '$COMMAND_SUDO' '$REMOTE_FIND_CMD' \"'$replica_deletion_path'/\" -type f -ctime +'$change_time' -print0 | xargs -0 -I {} '$COMMAND_SUDO' rm -f \"{}\" && '$COMMAND_SUDO' '$REMOTE_FIND_CMD' \"'$replica_deletion_path'/\" -type d -empty -ctime '$change_time' -print0 | xargs -0 -I {} '$COMMAND_SUDO' rm -rf \"{}\"; else echo \"No remote backup/deletion directory.\"; fi" > "'$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID'" 2>&1'
Logger "cmd: $cmd" "DEBUG" Logger "cmd: $cmd" "DEBUG"
@ -1611,7 +1619,7 @@ function Init {
set -o errtrace set -o errtrace
# Do not use exit and quit traps if osync runs in monitor mode # Do not use exit and quit traps if osync runs in monitor mode
if [ $sync_on_changes -eq 0 ]; then if [ $sync_on_changes == false ]; then
trap TrapStop INT HUP TERM QUIT trap TrapStop INT HUP TERM QUIT
trap TrapQuit EXIT trap TrapQuit EXIT
else else
@ -1681,7 +1689,7 @@ function Init {
local partial_dir="_partial" local partial_dir="_partial"
local last_action="last-action" local last_action="last-action"
local resume_count="resume-count" local resume_count="resume-count"
if [ "$_DRYRUN" -eq 1 ]; then if [ "$_DRYRUN" == true ]; then
local dry_suffix="-dry" local dry_suffix="-dry"
else else
local dry_suffix= local dry_suffix=
@ -1725,11 +1733,11 @@ function Init {
## Set sync only function arguments for rsync ## Set sync only function arguments for rsync
SYNC_OPTS="-u" SYNC_OPTS="-u"
if [ $_VERBOSE -eq 1 ]; then if [ $_VERBOSE == true ]; then
SYNC_OPTS=$SYNC_OPTS" -i" SYNC_OPTS=$SYNC_OPTS" -i"
fi fi
if [ $STATS -eq 1 ]; then if [ $STATS == true ]; then
SYNC_OPTS=$SYNC_OPTS" --stats" SYNC_OPTS=$SYNC_OPTS" --stats"
fi fi
@ -1852,8 +1860,8 @@ function SyncOnChanges {
} }
# quicksync mode settings, overriden by config file # quicksync mode settings, overriden by config file
STATS=0 STATS=false
PARTIAL=0 PARTIAL=no
if [ "$CONFLICT_PREVALANCE" == "" ]; then if [ "$CONFLICT_PREVALANCE" == "" ]; then
CONFLICT_PREVALANCE=initiator CONFLICT_PREVALANCE=initiator
fi fi
@ -1861,14 +1869,17 @@ fi
INITIATOR_LOCK_FILE_EXISTS=false INITIATOR_LOCK_FILE_EXISTS=false
TARGET_LOCK_FILE_EXISTS=false TARGET_LOCK_FILE_EXISTS=false
FORCE_UNLOCK=0 FORCE_UNLOCK=false
no_maxtime=0 no_maxtime=false
opts="" opts=""
ERROR_ALERT=0 ERROR_ALERT=false
WARN_ALERT=false
# Number of CTRL+C
SOFT_STOP=0 SOFT_STOP=0
# Number of given replicas in command line
_QUICK_SYNC=0 _QUICK_SYNC=0
sync_on_changes=0 sync_on_changes=false
_NOLOCKS=0 _NOLOCKS=false
osync_cmd=$0 osync_cmd=$0
if [ $# -eq 0 ] if [ $# -eq 0 ]
@ -1880,7 +1891,7 @@ first=1
for i in "$@"; do for i in "$@"; do
case $i in case $i in
--dry) --dry)
_DRYRUN=1 _DRYRUN=true
opts=$opts" --dry" opts=$opts" --dry"
;; ;;
--silent) --silent)
@ -1888,11 +1899,11 @@ for i in "$@"; do
opts=$opts" --silent" opts=$opts" --silent"
;; ;;
--verbose) --verbose)
_VERBOSE=1 _VERBOSE=true
opts=$opts" --verbose" opts=$opts" --verbose"
;; ;;
--stats) --stats)
STATS=1 STATS=true
opts=$opts" --stats" opts=$opts" --stats"
;; ;;
--partial) --partial)
@ -1900,11 +1911,11 @@ for i in "$@"; do
opts=$opts" --partial" opts=$opts" --partial"
;; ;;
--force-unlock) --force-unlock)
FORCE_UNLOCK=1 FORCE_UNLOCK=true
opts=$opts" --force-unlock" opts=$opts" --force-unlock"
;; ;;
--no-maxtime) --no-maxtime)
no_maxtime=1 no_maxtime=true
opts=$opts" --no-maxtime" opts=$opts" --no-maxtime"
;; ;;
--help|-h|--version|-v) --help|-h|--version|-v)
@ -1912,15 +1923,15 @@ for i in "$@"; do
;; ;;
--initiator=*) --initiator=*)
_QUICK_SYNC=$(($_QUICK_SYNC + 1)) _QUICK_SYNC=$(($_QUICK_SYNC + 1))
no_maxtime=1
INITIATOR_SYNC_DIR=${i##*=} INITIATOR_SYNC_DIR=${i##*=}
opts=$opts" --initiator=\"$INITIATOR_SYNC_DIR\"" opts=$opts" --initiator=\"$INITIATOR_SYNC_DIR\""
no_maxtime=true
;; ;;
--target=*) --target=*)
_QUICK_SYNC=$(($_QUICK_SYNC + 1)) _QUICK_SYNC=$(($_QUICK_SYNC + 1))
TARGET_SYNC_DIR=${i##*=} TARGET_SYNC_DIR=${i##*=}
opts=$opts" --target=\"$TARGET_SYNC_DIR\"" opts=$opts" --target=\"$TARGET_SYNC_DIR\""
no_maxtime=1 no_maxtime=true
;; ;;
--rsakey=*) --rsakey=*)
SSH_RSA_PRIVATE_KEY=${i##*=} SSH_RSA_PRIVATE_KEY=${i##*=}
@ -1931,13 +1942,13 @@ for i in "$@"; do
opts=$opts" --instance-id=\"$INSTANCE_ID\"" opts=$opts" --instance-id=\"$INSTANCE_ID\""
;; ;;
--on-changes) --on-changes)
sync_on_changes=1 sync_on_changes=true
_NOLOCKS=1 _NOLOCKS=true
_LOGGER_PREFIX="date" _LOGGER_PREFIX="date"
_LOGGER_STDERR=1 _LOGGER_STDERR=true
;; ;;
--no-locks) --no-locks)
_NOLOCKS=1 _NOLOCKS=true
;; ;;
*) *)
if [ $first == "0" ]; then if [ $first == "0" ]; then
@ -2026,13 +2037,13 @@ opts="${opts# *}"
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 -eq 1 ]; then if [ $sync_on_changes == true ]; then
SyncOnChanges SyncOnChanges
else else
GetRemoteOS GetRemoteOS
InitRemoteOSSettings InitRemoteOSSettings
if [ $no_maxtime -eq 1 ]; 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
fi fi