Various coding style compliance changes
This commit is contained in:
parent
d3a43d825a
commit
1f4a6a2b11
|
@ -6,6 +6,7 @@ KNOWN ISSUES
|
||||||
RECENT CHANGES
|
RECENT CHANGES
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
! Refactor local master, local slave, remote slave code to local and remote code for node-i or node-t
|
||||||
- Improved Logging
|
- Improved Logging
|
||||||
!- Updated osync to be fully compliant with coding style
|
!- Updated osync to be fully compliant with coding style
|
||||||
- Uploaded coding style manifest
|
- Uploaded coding style manifest
|
||||||
|
|
48
osync.sh
48
osync.sh
|
@ -1023,7 +1023,7 @@ function tree_list {
|
||||||
WaitForCompletion $child_pid $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME
|
WaitForCompletion $child_pid $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME
|
||||||
retval=$?
|
retval=$?
|
||||||
## Retval 24 = some files vanished while creating list
|
## Retval 24 = some files vanished while creating list
|
||||||
if ([ $retval == 0 ] || [ $retval == 24 ]) && [ -f $RUN_DIR/osync_$2_$SCRIPT_PID ]; then
|
if ([ $retval == 0 ] || [ $retval == 24 ]) && [ -f $RUN_DIR/osync_$replica_type_$SCRIPT_PID ]; then
|
||||||
mv $RUN_DIR/osync_$replica_type_$SCRIPT_PID "$MASTER_STATE_DIR/$replica_type$tree_filename"
|
mv $RUN_DIR/osync_$replica_type_$SCRIPT_PID "$MASTER_STATE_DIR/$replica_type$tree_filename"
|
||||||
return $?
|
return $?
|
||||||
else
|
else
|
||||||
|
@ -1037,20 +1037,20 @@ function delete_list {
|
||||||
local replica_type="${1}" # replica type: master, slave
|
local replica_type="${1}" # replica type: master, slave
|
||||||
local tree_file_after_filename="${2}" # tree-file-after, will be prefixed with replica type
|
local tree_file_after_filename="${2}" # tree-file-after, will be prefixed with replica type
|
||||||
local tree_file_current_filename="${3}" # tree-file-current, will be prefixed with replica type
|
local tree_file_current_filename="${3}" # tree-file-current, will be prefixed with replica type
|
||||||
local deleted_list_file="${4}" # file containing deleted file list, will be prefixed with replica type
|
local deleted_list_file_filename="${4}" # file containing deleted file list, will be prefixed with replica type
|
||||||
local deleted_failed_list_file="${5}" # file containing files that couldn't be deleted on last run, will be prefixed with replica type
|
local deleted_failed_list_file_filename="${5}" # file containing files that couldn't be deleted on last run, will be prefixed with replica type
|
||||||
|
|
||||||
# TODO: WIP here
|
# TODO: WIP here
|
||||||
|
|
||||||
Logger "Creating $replica_type replica deleted file list." "NOTICE"
|
Logger "Creating $replica_type replica deleted file list." "NOTICE"
|
||||||
if [ -f "$MASTER_STATE_DIR/$1$TREE_AFTER_FILENAME_NO_SUFFIX" ]; then
|
if [ -f "$MASTER_STATE_DIR/$replica_type$TREE_AFTER_FILENAME_NO_SUFFIX" ]; then
|
||||||
## Same functionnality, comm is much faster than grep but is not available on every platform
|
## Same functionnality, comm is much faster than grep but is not available on every platform
|
||||||
if type -p comm > /dev/null 2>&1
|
if type -p comm > /dev/null 2>&1
|
||||||
then
|
then
|
||||||
cmd="comm -23 \"$MASTER_STATE_DIR/$1$TREE_AFTER_FILENAME_NO_SUFFIX\" \"$MASTER_STATE_DIR/$1$3\" > \"$MASTER_STATE_DIR/$1$4\""
|
cmd="comm -23 \"$MASTER_STATE_DIR/$replica_type$TREE_AFTER_FILENAME_NO_SUFFIX\" \"$MASTER_STATE_DIR/$replica_type$3\" > \"$MASTER_STATE_DIR/$replica_type$4\""
|
||||||
else
|
else
|
||||||
## The || : forces the command to have a good result
|
## The || : forces the command to have a good result
|
||||||
cmd="(grep -F -x -v -f \"$MASTER_STATE_DIR/$1$3\" \"$MASTER_STATE_DIR/$1$TREE_AFTER_FILENAME_NO_SUFFIX\" || :) > \"$MASTER_STATE_DIR/$1$4\""
|
cmd="(grep -F -x -v -f \"$MASTER_STATE_DIR/$replica_type$3\" \"$MASTER_STATE_DIR/$replica_type$TREE_AFTER_FILENAME_NO_SUFFIX\" || :) > \"$MASTER_STATE_DIR/$replica_type$4\""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
Logger "CMD: $cmd" "DEBUG"
|
Logger "CMD: $cmd" "DEBUG"
|
||||||
|
@ -1058,22 +1058,26 @@ function delete_list {
|
||||||
retval=$?
|
retval=$?
|
||||||
|
|
||||||
# Add delete failed file list to current delete list and then empty it
|
# Add delete failed file list to current delete list and then empty it
|
||||||
if [ -f "$MASTER_STATE_DIR/$1$5" ]; then
|
if [ -f "$MASTER_STATE_DIR/$replica_type$5" ]; then
|
||||||
cat "$MASTER_STATE_DIR/$1$5" >> "$MASTER_STATE_DIR/$1$4"
|
cat "$MASTER_STATE_DIR/$replica_type$5" >> "$MASTER_STATE_DIR/$replica_type$4"
|
||||||
rm -f "$MASTER_STATE_DIR/$1$5"
|
rm -f "$MASTER_STATE_DIR/$replica_type$5"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return $retval
|
return $retval
|
||||||
else
|
else
|
||||||
touch "$MASTER_STATE_DIR/$1$4"
|
touch "$MASTER_STATE_DIR/$replica_type$4"
|
||||||
return $retval
|
return $retval
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# sync_update(source replica, destination replica, delete_list_filename)
|
# sync_update(source replica, destination replica, delete_list_filename)
|
||||||
function sync_update {
|
function sync_update {
|
||||||
Logger "Updating $2 replica." "NOTICE"
|
local source_replica="${1}" # Contains replica type of source: master, slave
|
||||||
if [ "$1" == "master" ]; then
|
local destination_replica="${2}" # Contains replica type of destination: master, slave
|
||||||
|
local delete_list_filename="${3}" # Contains deleted list filename, will be prefixed with replica type
|
||||||
|
|
||||||
|
Logger "Updating $destination_replica replica." "NOTICE"
|
||||||
|
if [ "$source_replica" == "master" ]; then
|
||||||
SOURCE_DIR="$MASTER_SYNC_DIR"
|
SOURCE_DIR="$MASTER_SYNC_DIR"
|
||||||
ESC_SOURCE_DIR=$(EscapeSpaces "$MASTER_SYNC_DIR")
|
ESC_SOURCE_DIR=$(EscapeSpaces "$MASTER_SYNC_DIR")
|
||||||
DEST_DIR="$SLAVE_SYNC_DIR"
|
DEST_DIR="$SLAVE_SYNC_DIR"
|
||||||
|
@ -1090,31 +1094,31 @@ function sync_update {
|
||||||
if [ "$REMOTE_SYNC" == "yes" ]; then
|
if [ "$REMOTE_SYNC" == "yes" ]; then
|
||||||
CheckConnectivity3rdPartyHosts
|
CheckConnectivity3rdPartyHosts
|
||||||
CheckConnectivityRemoteHost
|
CheckConnectivityRemoteHost
|
||||||
if [ "$1" == "master" ]; then
|
if [ "$source_replica" == "master" ]; then
|
||||||
rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS $SYNC_OPTS -e \"$RSYNC_SSH_CMD\" $BACKUP_DIR --exclude \"$OSYNC_DIR\" $RSYNC_EXCLUDE --exclude-from=\"$MASTER_STATE_DIR/$1$3\" --exclude-from=\"$MASTER_STATE_DIR/$2$3\" \"$SOURCE_DIR/\" $REMOTE_USER@$REMOTE_HOST:\"$ESC_DEST_DIR/\" > $RUN_DIR/osync_update_$2_replica_$SCRIPT_PID 2>&1 &"
|
rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS $SYNC_OPTS -e \"$RSYNC_SSH_CMD\" $BACKUP_DIR --exclude \"$OSYNC_DIR\" $RSYNC_EXCLUDE --exclude-from=\"$MASTER_STATE_DIR/$source_replica$delete_list_filename\" --exclude-from=\"$MASTER_STATE_DIR/$destination_replica$delete_list_filename\" \"$SOURCE_DIR/\" $REMOTE_USER@$REMOTE_HOST:\"$ESC_DEST_DIR/\" > $RUN_DIR/osync_update_$destination_replica_replica_$SCRIPT_PID 2>&1 &"
|
||||||
else
|
else
|
||||||
rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS $SYNC_OPTS -e \"$RSYNC_SSH_CMD\" $BACKUP_DIR --exclude \"$OSYNC_DIR\" $RSYNC_EXCLUDE --exclude-from=\"$MASTER_STATE_DIR/$2$3\" --exclude-from=\"$MASTER_STATE_DIR/$1$3\" $REMOTE_USER@$REMOTE_HOST:\"$ESC_SOURCE_DIR/\" \"$DEST_DIR/\" > $RUN_DIR/osync_update_$2_replica_$SCRIPT_PID 2>&1 &"
|
rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS $SYNC_OPTS -e \"$RSYNC_SSH_CMD\" $BACKUP_DIR --exclude \"$OSYNC_DIR\" $RSYNC_EXCLUDE --exclude-from=\"$MASTER_STATE_DIR/$destination_replica$delete_list_filename\" --exclude-from=\"$MASTER_STATE_DIR/$source_replica$delete_list_filename\" $REMOTE_USER@$REMOTE_HOST:\"$ESC_SOURCE_DIR/\" \"$DEST_DIR/\" > $RUN_DIR/osync_update_$destination_replica_replica_$SCRIPT_PID 2>&1 &"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS $SYNC_OPTS $BACKUP_DIR --exclude \"$OSYNC_DIR\" $RSYNC_EXCLUDE --exclude-from=\"$MASTER_STATE_DIR/$1$3\" --exclude-from=\"$MASTER_STATE_DIR/$2$3\" \"$SOURCE_DIR/\" \"$DEST_DIR/\" > $RUN_DIR/osync_update_$2_replica_$SCRIPT_PID 2>&1 &"
|
rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS $SYNC_OPTS $BACKUP_DIR --exclude \"$OSYNC_DIR\" $RSYNC_EXCLUDE --exclude-from=\"$MASTER_STATE_DIR/$source_replica$delete_list_filename\" --exclude-from=\"$MASTER_STATE_DIR/$destination_replica$delete_list_filename\" \"$SOURCE_DIR/\" \"$DEST_DIR/\" > $RUN_DIR/osync_update_$destination_replica_replica_$SCRIPT_PID 2>&1 &"
|
||||||
fi
|
fi
|
||||||
Logger "RSYNC_CMD: $rsync_cmd" "DEBUG"
|
Logger "RSYNC_CMD: $rsync_cmd" "DEBUG"
|
||||||
eval "$rsync_cmd"
|
eval "$rsync_cmd"
|
||||||
child_pid=$!
|
child_pid=$!
|
||||||
WaitForCompletion $child_pid $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME
|
WaitForCompletion $child_pid $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME
|
||||||
retval=$?
|
retval=$?
|
||||||
if [ $verbose -eq 1 ] && [ -f $RUN_DIR/osync_update_$2_replica_$SCRIPT_PID ]; then
|
if [ $verbose -eq 1 ] && [ -f $RUN_DIR/osync_update_$destination_replica_replica_$SCRIPT_PID ]; then
|
||||||
Logger "List:\n$(cat $RUN_DIR/osync_update_$2_replica_$SCRIPT_PID)" "NOTICE"
|
Logger "List:\n$(cat $RUN_DIR/osync_update_$destination_replica_replica_$SCRIPT_PID)" "NOTICE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $retval != 0 ] && [ $retval != 24 ]; then
|
if [ $retval != 0 ] && [ $retval != 24 ]; then
|
||||||
Logger "Updating $2 replica failed. Stopping execution." "CRITICAL"
|
Logger "Updating $destination_replica replica failed. Stopping execution." "CRITICAL"
|
||||||
if [ $verbose -eq 0 ] && [ -f $RUN_DIR/osync_update_$2_replica_$SCRIPT_PID ]; then
|
if [ $verbose -eq 0 ] && [ -f $RUN_DIR/osync_update_$destination_replica_replica_$SCRIPT_PID ]; then
|
||||||
Logger "Rsync output:\n$(cat $RUN_DIR/osync_update_$2_replica_$SCRIPT_PID)" "NOTICE"
|
Logger "Rsync output:\n$(cat $RUN_DIR/osync_update_$destination_replica_replica_$SCRIPT_PID)" "NOTICE"
|
||||||
fi
|
fi
|
||||||
exit $retval
|
exit $retval
|
||||||
else
|
else
|
||||||
Logger "Updating $2 replica succeded." "NOTICE"
|
Logger "Updating $destination_replica replica succeded." "NOTICE"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue