From 3b2924d7d9beb494fa530b13f0f742f921fb951f Mon Sep 17 00:00:00 2001 From: "Andrey M. Smirnov" Date: Wed, 27 Jul 2016 22:33:10 +0000 Subject: [PATCH 1/7] Correct arguments for remote deletion command + debug printing it those arguments and a command input --- osync.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/osync.sh b/osync.sh index a7db1f4..65a7252 100755 --- a/osync.sh +++ b/osync.sh @@ -2075,8 +2075,11 @@ function _delete_remote { fi #TODO: check output file without & and sleep 5 -$SSH_CMD ERROR_ALERT=0 sync_on_changes=$sync_on_changes _SILENT=$_SILENT _DEBUG=$_DEBUG _DRYRUN=$_DRYRUN _VERBOSE=$_VERBOSE COMMAND_SUDO=$COMMAND_SUDO FILE_LIST="$(EscapeSpaces "$TARGET_STATE_DIR/$deleted_list_file")" REPLICA_DIR="$(EscapeSpaces "$replica_dir")" DELETE_DIR="$(EscapeSpaces "$deletion_dir")" FAILED_DELETE_LIST="$(EscapeSpaces "${TARGET[1]}${TARGET[3]}/$deleted_failed_list_file")" 'bash -s' << 'ENDSSH' > "$RUN_DIR/$PROGRAM.remote_deletion.$SCRIPT_PID" 2>&1 - +local TARGET_STATE_DIR="${TARGET[1]}${TARGET[3]}" +local DELETE_CMD=( +$SSH_CMD ERROR_ALERT=0 sync_on_changes=$sync_on_changes _SILENT=$_SILENT _DEBUG=$_DEBUG _DRYRUN=$_DRYRUN _VERBOSE=$_VERBOSE COMMAND_SUDO=$COMMAND_SUDO FILE_LIST="$(EscapeSpaces "$TARGET_STATE_DIR/$deleted_list_file")" REPLICA_DIR="$(EscapeSpaces "$replica_dir")" DELETE_DIR="$(EscapeSpaces "$deletion_dir")" FAILED_DELETE_LIST="$(EscapeSpaces "${TARGET[1]}${TARGET[3]}/$deleted_failed_list_file")" 'bash -s' +) +local DELETE_CMD_INPUT = $(cat << 'ENDSSH' ## The following lines are executed remotely function _logger { local value="${1}" # What to log @@ -2177,6 +2180,11 @@ $SSH_CMD ERROR_ALERT=0 sync_on_changes=$sync_on_changes _SILENT=$_SILENT _DEBUG= done IFS=$OLD_IFS ENDSSH +) +Logger "DELETE_CMD_INPUT: $DELETE_CMD_INPUT" "DEBUG" +Logger "DELETE_CMD: ${DELETE_CMD[*]}" "DEBUG" + + printf "%s" $DELETE_CMD_INPUT | ${DELETE_CMD[*]} > "$RUN_DIR/$PROGRAM.remote_deletion.$SCRIPT_PID" 2>&1 ## Copy back the deleted failed file list esc_source_file="$(EscapeSpaces "${TARGET[1]}${TARGET[3]}/$deleted_failed_list_file")" From 7bb6eebea335eefba4c560de621f027427348e56 Mon Sep 17 00:00:00 2001 From: "Andrey M. Smirnov" Date: Wed, 27 Jul 2016 23:01:33 +0000 Subject: [PATCH 2/7] typo --- osync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osync.sh b/osync.sh index 65a7252..c2de569 100755 --- a/osync.sh +++ b/osync.sh @@ -2079,7 +2079,7 @@ local TARGET_STATE_DIR="${TARGET[1]}${TARGET[3]}" local DELETE_CMD=( $SSH_CMD ERROR_ALERT=0 sync_on_changes=$sync_on_changes _SILENT=$_SILENT _DEBUG=$_DEBUG _DRYRUN=$_DRYRUN _VERBOSE=$_VERBOSE COMMAND_SUDO=$COMMAND_SUDO FILE_LIST="$(EscapeSpaces "$TARGET_STATE_DIR/$deleted_list_file")" REPLICA_DIR="$(EscapeSpaces "$replica_dir")" DELETE_DIR="$(EscapeSpaces "$deletion_dir")" FAILED_DELETE_LIST="$(EscapeSpaces "${TARGET[1]}${TARGET[3]}/$deleted_failed_list_file")" 'bash -s' ) -local DELETE_CMD_INPUT = $(cat << 'ENDSSH' +local DELETE_CMD_INPUT=$(cat << 'ENDSSH' ## The following lines are executed remotely function _logger { local value="${1}" # What to log From 9129020daf246020b4676cb997d7bc539ea94ab8 Mon Sep 17 00:00:00 2001 From: "Andrey M. Smirnov" Date: Thu, 28 Jul 2016 00:08:40 +0000 Subject: [PATCH 3/7] Write logs to STDERR on remote side --- osync.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osync.sh b/osync.sh index c2de569..352cc3a 100755 --- a/osync.sh +++ b/osync.sh @@ -2083,7 +2083,8 @@ local DELETE_CMD_INPUT=$(cat << 'ENDSSH' ## The following lines are executed remotely function _logger { local value="${1}" # What to log - echo -e "$value" >> "$LOG_FILE" + #echo -e "$value" >> "$LOG_FILE" + echo -e "$value" >&2 # writing to STDERR because if [ $_SILENT -eq 0 ]; then echo -e "$value" From b46a79784e19909a7d044dcc084d4056df52515e Mon Sep 17 00:00:00 2001 From: "Andrey M. Smirnov" Date: Thu, 28 Jul 2016 00:09:05 +0000 Subject: [PATCH 4/7] Log verbosely what's happening on remote side on deletion --- osync.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osync.sh b/osync.sh index 352cc3a..6e82d70 100755 --- a/osync.sh +++ b/osync.sh @@ -2128,6 +2128,7 @@ local DELETE_CMD_INPUT=$(cat << 'ENDSSH' IFS=$'\r\n' for files in $(cat "$FILE_LIST") do + Logger "Processing file $files" "DEBUG" if [[ "$files" != "$previous_file/"* ]] && [ "$files" != "" ]; then if [ ! -d "$REPLICA_DIR$DELETE_DIR" ]; then $COMMAND_SUDO mkdir -p "$REPLICA_DIR$DELETE_DIR" @@ -2166,6 +2167,7 @@ local DELETE_CMD_INPUT=$(cat << 'ENDSSH' Logger "Deleting $REPLICA_DIR$files" "NOTICE" fi + Logger "Full path for deletion: ""$REPLICA_DIR$files" "DEBUG" if [ $_DRYRUN -ne 1 ]; then if [ -e "$REPLICA_DIR$files" ]; then $COMMAND_SUDO rm -rf "$REPLICA_DIR$files" From 16fc23c66d5da71833dff6642c92aa50d8c45e3d Mon Sep 17 00:00:00 2001 From: "Andrey M. Smirnov" Date: Thu, 28 Jul 2016 00:09:34 +0000 Subject: [PATCH 5/7] Fixed a (probable) mistake --- osync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osync.sh b/osync.sh index 6e82d70..07358fd 100755 --- a/osync.sh +++ b/osync.sh @@ -2173,7 +2173,7 @@ local DELETE_CMD_INPUT=$(cat << 'ENDSSH' $COMMAND_SUDO rm -rf "$REPLICA_DIR$files" if [ $? != 0 ]; then Logger "Cannot delete $REPLICA_DIR$files" "ERROR" - echo "$files" >> "$TARGET_STATE_DIR/$FAILED_DELETE_LIST" + echo "$files" >> "$FAILED_DELETE_LIST" fi fi fi From 0ab67c02ce1fe7d64acc77a885633eb5a36ef3f3 Mon Sep 17 00:00:00 2001 From: "Andrey M. Smirnov" Date: Thu, 28 Jul 2016 00:30:38 +0000 Subject: [PATCH 6/7] Possible typo --- osync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osync.sh b/osync.sh index 07358fd..aa00f96 100755 --- a/osync.sh +++ b/osync.sh @@ -2147,7 +2147,7 @@ local DELETE_CMD_INPUT=$(cat << 'ENDSSH' $COMMAND_SUDO rm -rf "$REPLICA_DIR$DELETE_DIR/$files" fi - if [ -e "$$REPLICA_DIR$files" ]; then + if [ -e "$REPLICA_DIR$files" ]; then # In order to keep full path on soft deletion, create parent directories before move parentdir="$(dirname "$files")" if [ "$parentdir" != "." ]; then From 836659947fc9ea5604609f62cbf1b062f2287985 Mon Sep 17 00:00:00 2001 From: "Andrey M. Smirnov" Date: Thu, 28 Jul 2016 00:31:02 +0000 Subject: [PATCH 7/7] Wrapped $DELETE_CMD_INPUT with "" --- osync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osync.sh b/osync.sh index aa00f96..7cffef4 100755 --- a/osync.sh +++ b/osync.sh @@ -2187,7 +2187,7 @@ ENDSSH Logger "DELETE_CMD_INPUT: $DELETE_CMD_INPUT" "DEBUG" Logger "DELETE_CMD: ${DELETE_CMD[*]}" "DEBUG" - printf "%s" $DELETE_CMD_INPUT | ${DELETE_CMD[*]} > "$RUN_DIR/$PROGRAM.remote_deletion.$SCRIPT_PID" 2>&1 + printf "%s" "$DELETE_CMD_INPUT" | ${DELETE_CMD[*]} > "$RUN_DIR/$PROGRAM.remote_deletion.$SCRIPT_PID" 2>&1 ## Copy back the deleted failed file list esc_source_file="$(EscapeSpaces "${TARGET[1]}${TARGET[3]}/$deleted_failed_list_file")"