diff --git a/dev/debug_osync.sh b/dev/debug_osync.sh index ff96b0b..bae6ba2 100755 --- a/dev/debug_osync.sh +++ b/dev/debug_osync.sh @@ -4,7 +4,7 @@ PROGRAM="osync" # Rsync based two way sync engine with fault tolerance AUTHOR="(L) 2013-2016 by Orsiris de Jong" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" PROGRAM_VERSION=1.1-dev -PROGRAM_BUILD=2016021703 +PROGRAM_BUILD=2016021704 IS_STABLE=no FUNC_BUILD=2016021604 @@ -1535,17 +1535,17 @@ function delete_list { fi } -function _get_file_attrs_local { +function _get_file_ctime_mtime_local { local replica_path="${1}" # Contains replica path local replica_type="${2}" # Initiator / Target local file_list="${3}" # Contains list of files to get time attrs __CheckArguments 3 $# $FUNCNAME "$@" #__WITH_PARANOIA_DEBUG - cd "$replica_path" - cat "$file_list" | xargs -I {} stat -c '%n|%Z|%Y' "{}" | sort > "$RUN_DIR/$PROGRAM.$FUNCNAME.$replica_type.$SCRIPT_PID" + # TODO: make this more beautiful (include path in stat command ?) + cat "$file_list" | xargs -I {} stat -c '%n|%Z|%Y' "$replica_path{}" | sort > "$RUN_DIR/$PROGRAM.$FUNCNAME.$replica_type.$SCRIPT_PID" } -function _get_file_attrs_remote { +function _get_file_ctime_mtime_remote { local replica_path="${1}" # Contains replica path local replica_type="${2}" local file_list="${3}" @@ -1561,6 +1561,8 @@ function sync_attrs { local target_replica="${2}" __CheckArguments 2 $# $FUNCNAME "$@" #__WITH_PARANOIA_DEBUG + local rsync_cmd= + Logger "Getting file attributes." "NOTICE" if [ "$REMOTE_OPERATION" == "yes" ]; then @@ -1592,17 +1594,37 @@ function sync_attrs { fi fi - _get_file_attrs_local "${INITIATOR[1]}" "${INITIATOR[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" + _get_file_ctime_mtime_local "${INITIATOR[1]}" "${INITIATOR[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" if [ "$REMOTE_OPERATION" != "yes" ]; then - _get_file_attrs_remote "${TARGET[1]}" "${TARGET[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" + _get_file_ctime_mtime_local "${TARGET[1]}" "${TARGET[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" else - _get_file_attrs_local "${TARGET[1]}" "${TARGET[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" + _get_file_ctime_mtime_remote "${TARGET[1]}" "${TARGET[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" fi #WIP - # Join both files into tmp file - # Rsync file from tmp file + join -j 1 -t ';' -o 1.1,1.2,2.2 init targ | awk -F';' '{if ($2 < $3) print $1}' > "$RUN_DIR/$PROGRAM.$FUNCNAME-attrfiles.$SCRIPT_PID" + if [ "$REMOTE_OPERATION" != "yes" ]; then + rsync_cmd="" + else + rsync_cmd="" + fi + Logger "RSYNC_CMD: $rsync_cmd" "DEBUG" + eval "$rsync_cmd" + WaitForCompletion $! $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME $FUNCNAME + retval=$? + if [ $_VERBOSE -eq 1 ] && [ -f "$RUN_DIR/$PROGRAM.$FUNCNAME-attrfiles.$SCRIPT_PID" ]; then + Logger "List:\n$(cat $RUN_DIR/$PROGRAM.$FUNCNAM-attrfiles.$SCRIPT_PID)" "NOTICE" + fi + if [ $retval != 0 ] && [ $retval != 24 ]; then + Logger "Getting file attributes failed [$retval]. Stopping execution." "CRITICAL" + if [ $_VERBOSE -eq 0 ] && [ -f "$RUN_DIR/$PROGRAM.$FUNCNAME-attrfiles.$SCRIPT_PID" ]; then + Logger "Rsync output:\n$(cat $RUN_DIR/$PROGRAM.$FUNCNAME-attrfiles.$SCRIPT_PID)" "NOTICE" + fi + exit $retval + else + Logger "Successfully updated file attributes on target replica." "NOTICE" + fi } # sync_update(source replica, destination replica, delete_list_filename) diff --git a/dev/n_osync.sh b/dev/n_osync.sh index 5bc79dc..f2a0945 100755 --- a/dev/n_osync.sh +++ b/dev/n_osync.sh @@ -4,7 +4,7 @@ PROGRAM="osync" # Rsync based two way sync engine with fault tolerance AUTHOR="(L) 2013-2016 by Orsiris de Jong" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" PROGRAM_VERSION=1.1-dev -PROGRAM_BUILD=2016021703 +PROGRAM_BUILD=2016021704 IS_STABLE=no source "./ofunctions.sh" @@ -620,17 +620,17 @@ function delete_list { fi } -function _get_file_attrs_local { +function _get_file_ctime_mtime_local { local replica_path="${1}" # Contains replica path local replica_type="${2}" # Initiator / Target local file_list="${3}" # Contains list of files to get time attrs __CheckArguments 3 $# $FUNCNAME "$@" #__WITH_PARANOIA_DEBUG - cd "$replica_path" - cat "$file_list" | xargs -I {} stat -c '%n|%Z|%Y' "{}" | sort > "$RUN_DIR/$PROGRAM.$FUNCNAME.$replica_type.$SCRIPT_PID" + # TODO: make this more beautiful (include path in stat command ?) + cat "$file_list" | xargs -I {} stat -c '%n|%Z|%Y' "$replica_path{}" | sort > "$RUN_DIR/$PROGRAM.$FUNCNAME.$replica_type.$SCRIPT_PID" } -function _get_file_attrs_remote { +function _get_file_ctime_mtime_remote { local replica_path="${1}" # Contains replica path local replica_type="${2}" local file_list="${3}" @@ -646,6 +646,8 @@ function sync_attrs { local target_replica="${2}" __CheckArguments 2 $# $FUNCNAME "$@" #__WITH_PARANOIA_DEBUG + local rsync_cmd= + Logger "Getting file attributes." "NOTICE" if [ "$REMOTE_OPERATION" == "yes" ]; then @@ -677,17 +679,37 @@ function sync_attrs { fi fi - _get_file_attrs_local "${INITIATOR[1]}" "${INITIATOR[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" + _get_file_ctime_mtime_local "${INITIATOR[1]}" "${INITIATOR[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" if [ "$REMOTE_OPERATION" != "yes" ]; then - _get_file_attrs_remote "${TARGET[1]}" "${TARGET[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" + _get_file_ctime_mtime_local "${TARGET[1]}" "${TARGET[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" else - _get_file_attrs_local "${TARGET[1]}" "${TARGET[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" + _get_file_ctime_mtime_remote "${TARGET[1]}" "${TARGET[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" fi #WIP - # Join both files into tmp file - # Rsync file from tmp file + join -j 1 -t ';' -o 1.1,1.2,2.2 init targ | awk -F';' '{if ($2 < $3) print $1}' > "$RUN_DIR/$PROGRAM.$FUNCNAME-attrfiles.$SCRIPT_PID" + if [ "$REMOTE_OPERATION" != "yes" ]; then + rsync_cmd="" + else + rsync_cmd="" + fi + Logger "RSYNC_CMD: $rsync_cmd" "DEBUG" + eval "$rsync_cmd" + WaitForCompletion $! $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME $FUNCNAME + retval=$? + if [ $_VERBOSE -eq 1 ] && [ -f "$RUN_DIR/$PROGRAM.$FUNCNAME-attrfiles.$SCRIPT_PID" ]; then + Logger "List:\n$(cat $RUN_DIR/$PROGRAM.$FUNCNAM-attrfiles.$SCRIPT_PID)" "NOTICE" + fi + if [ $retval != 0 ] && [ $retval != 24 ]; then + Logger "Getting file attributes failed [$retval]. Stopping execution." "CRITICAL" + if [ $_VERBOSE -eq 0 ] && [ -f "$RUN_DIR/$PROGRAM.$FUNCNAME-attrfiles.$SCRIPT_PID" ]; then + Logger "Rsync output:\n$(cat $RUN_DIR/$PROGRAM.$FUNCNAME-attrfiles.$SCRIPT_PID)" "NOTICE" + fi + exit $retval + else + Logger "Successfully updated file attributes on target replica." "NOTICE" + fi } # sync_update(source replica, destination replica, delete_list_filename) diff --git a/osync.sh b/osync.sh index 267578a..3836103 100755 --- a/osync.sh +++ b/osync.sh @@ -4,7 +4,7 @@ PROGRAM="osync" # Rsync based two way sync engine with fault tolerance AUTHOR="(L) 2013-2016 by Orsiris de Jong" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" PROGRAM_VERSION=1.1-dev -PROGRAM_BUILD=2016021703 +PROGRAM_BUILD=2016021704 IS_STABLE=no FUNC_BUILD=2016021604 @@ -1409,16 +1409,16 @@ function delete_list { fi } -function _get_file_attrs_local { +function _get_file_ctime_mtime_local { local replica_path="${1}" # Contains replica path local replica_type="${2}" # Initiator / Target local file_list="${3}" # Contains list of files to get time attrs - cd "$replica_path" - cat "$file_list" | xargs -I {} stat -c '%n|%Z|%Y' "{}" | sort > "$RUN_DIR/$PROGRAM.$FUNCNAME.$replica_type.$SCRIPT_PID" + # TODO: make this more beautiful (include path in stat command ?) + cat "$file_list" | xargs -I {} stat -c '%n|%Z|%Y' "$replica_path{}" | sort > "$RUN_DIR/$PROGRAM.$FUNCNAME.$replica_type.$SCRIPT_PID" } -function _get_file_attrs_remote { +function _get_file_ctime_mtime_remote { local replica_path="${1}" # Contains replica path local replica_type="${2}" local file_list="${3}" @@ -1432,6 +1432,8 @@ function sync_attrs { local initiator_replica="${1}" # Contains #TODO: Write ACL update function, check other ctime related attributes (xattr ?) local target_replica="${2}" + local rsync_cmd= + Logger "Getting file attributes." "NOTICE" if [ "$REMOTE_OPERATION" == "yes" ]; then @@ -1463,17 +1465,37 @@ function sync_attrs { fi fi - _get_file_attrs_local "${INITIATOR[1]}" "${INITIATOR[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" + _get_file_ctime_mtime_local "${INITIATOR[1]}" "${INITIATOR[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" if [ "$REMOTE_OPERATION" != "yes" ]; then - _get_file_attrs_remote "${TARGET[1]}" "${TARGET[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" + _get_file_ctime_mtime_local "${TARGET[1]}" "${TARGET[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" else - _get_file_attrs_local "${TARGET[1]}" "${TARGET[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" + _get_file_ctime_mtime_remote "${TARGET[1]}" "${TARGET[0]}" "$RUN_DIR/$PROGRAM.$FUNCNAME-cleaned.$SCRIPT_PID" fi #WIP - # Join both files into tmp file - # Rsync file from tmp file + join -j 1 -t ';' -o 1.1,1.2,2.2 init targ | awk -F';' '{if ($2 < $3) print $1}' > "$RUN_DIR/$PROGRAM.$FUNCNAME-attrfiles.$SCRIPT_PID" + if [ "$REMOTE_OPERATION" != "yes" ]; then + rsync_cmd="" + else + rsync_cmd="" + fi + Logger "RSYNC_CMD: $rsync_cmd" "DEBUG" + eval "$rsync_cmd" + WaitForCompletion $! $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME $FUNCNAME + retval=$? + if [ $_VERBOSE -eq 1 ] && [ -f "$RUN_DIR/$PROGRAM.$FUNCNAME-attrfiles.$SCRIPT_PID" ]; then + Logger "List:\n$(cat $RUN_DIR/$PROGRAM.$FUNCNAM-attrfiles.$SCRIPT_PID)" "NOTICE" + fi + if [ $retval != 0 ] && [ $retval != 24 ]; then + Logger "Getting file attributes failed [$retval]. Stopping execution." "CRITICAL" + if [ $_VERBOSE -eq 0 ] && [ -f "$RUN_DIR/$PROGRAM.$FUNCNAME-attrfiles.$SCRIPT_PID" ]; then + Logger "Rsync output:\n$(cat $RUN_DIR/$PROGRAM.$FUNCNAME-attrfiles.$SCRIPT_PID)" "NOTICE" + fi + exit $retval + else + Logger "Successfully updated file attributes on target replica." "NOTICE" + fi } # sync_update(source replica, destination replica, delete_list_filename)