From adad3257b353d56ac081c9b35eda06086c99ef50 Mon Sep 17 00:00:00 2001 From: Orsiris de Jong Date: Wed, 24 Jun 2015 14:07:00 +0200 Subject: [PATCH 1/4] Hotfix #22 added -f to mv command --- osync.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osync.sh b/osync.sh index ab9dd0b..ba38999 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-2015 by Orsiris \"Ozy\" de Jong" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" PROGRAM_VERSION=1.00pre -PROGRAM_BUILD=1805201501 +PROGRAM_BUILD=2406201501 ## type doesn't work on platforms other than linux (bash). If if doesn't work, always assume output is not a zero exitcode if ! type -p "$BASH" > /dev/null @@ -1179,7 +1179,7 @@ function _delete_local if [ $dryrun -ne 1 ] then - mv "$REPLICA_DIR$files" "$REPLICA_DIR$3" + mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$3" if [ $? != 0 ] then LogError "Cannot move $REPLICA_DIR$files to deletion directory." @@ -1282,7 +1282,7 @@ $SSH_CMD error_alert=0 sync_on_changes=$sync_on_changes silent=$silent DEBUG=$DE if [ $dryrun -ne 1 ] then - $COMMAND_SUDO mv "$REPLICA_DIR$files" "$REPLICA_DIR$DELETE_DIR" + $COMMAND_SUDO mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$DELETE_DIR" if [ $? != 0 ] then LogError "Cannot move $REPLICA_DIR$files to deletion directory." From eb9625bddcb3f371fe638ba1909fed8f642fe5ca Mon Sep 17 00:00:00 2001 From: Orsiris de Jong Date: Wed, 24 Jun 2015 21:43:00 +0200 Subject: [PATCH 2/4] Hotfix #22 added rm -rf if file already exists Fix is only useful if deleted directories already exist and are not empty --- osync.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/osync.sh b/osync.sh index ba38999..974817b 100755 --- a/osync.sh +++ b/osync.sh @@ -1179,6 +1179,10 @@ function _delete_local if [ $dryrun -ne 1 ] then + if [ -e "$REPLICA_DIR$3$files" ] + then + rm -rf "$REPLICA_DIR$3$files" + fi mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$3" if [ $? != 0 ] then @@ -1282,6 +1286,10 @@ $SSH_CMD error_alert=0 sync_on_changes=$sync_on_changes silent=$silent DEBUG=$DE if [ $dryrun -ne 1 ] then + if [ -e "$REPLICA_DIR$DELETE_DIR$files" ] + then + $COMMAND_SUDO rm -rf "$REPLICA_DIR$DELETE_DIR$files" + fi $COMMAND_SUDO mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$DELETE_DIR" if [ $? != 0 ] then From 9aa2e1166e52df037c393fd64a9e3c5c86edd713 Mon Sep 17 00:00:00 2001 From: Orsiris de Jong Date: Wed, 24 Jun 2015 21:50:46 +0200 Subject: [PATCH 3/4] Added missing slash --- osync.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/osync.sh b/osync.sh index 974817b..9369bdd 100755 --- a/osync.sh +++ b/osync.sh @@ -3,8 +3,8 @@ PROGRAM="Osync" # Rsync based two way sync engine with fault tolerance AUTHOR="(L) 2013-2015 by Orsiris \"Ozy\" de Jong" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" -PROGRAM_VERSION=1.00pre -PROGRAM_BUILD=2406201501 +PROGRAM_VERSION=1.00pre-hotfix22 +PROGRAM_BUILD=2406201502 ## type doesn't work on platforms other than linux (bash). If if doesn't work, always assume output is not a zero exitcode if ! type -p "$BASH" > /dev/null @@ -1179,9 +1179,9 @@ function _delete_local if [ $dryrun -ne 1 ] then - if [ -e "$REPLICA_DIR$3$files" ] + if [ -e "$REPLICA_DIR$3/$files" ] then - rm -rf "$REPLICA_DIR$3$files" + rm -rf "$REPLICA_DIR$3/$files" fi mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$3" if [ $? != 0 ] @@ -1286,9 +1286,9 @@ $SSH_CMD error_alert=0 sync_on_changes=$sync_on_changes silent=$silent DEBUG=$DE if [ $dryrun -ne 1 ] then - if [ -e "$REPLICA_DIR$DELETE_DIR$files" ] + 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" fi $COMMAND_SUDO mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$DELETE_DIR" if [ $? != 0 ] From 54c13b85ef5aef6ee84d05fa065180582b2d03dd Mon Sep 17 00:00:00 2001 From: deajan Date: Fri, 26 Jun 2015 16:31:11 +0200 Subject: [PATCH 4/4] Hotfix #22 - Missing full path in soft deletion --- CHANGELOG.md | 2 ++ osync.sh | 28 ++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef964d6..d4100d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ SHORT FUTURE IMPROVEMENTS ------------------------- - Tree functions execute piped commands (grep, awk) on local system when launched on remote slave which can cause more bandwith usage +- Function calls give variables like $1, $2 etc. Reassign them to local variables with better names for easier code reading FAR FUTURE IMPROVEMENTS ----------------------- @@ -31,6 +32,7 @@ UNDER WORK RECENT CHANGES -------------- +- Fixed #22 (missing full path in soft deletion) - Fixed #21 by adding portable shell readlink / realpath from https://github.com/mkropat/sh-realpath - Added detection of osync.sh script in osync-batch.sh to overcome mising path in crontab - Fixed osync-batch.sh script when osync is in executable path like /usr/local/bin diff --git a/osync.sh b/osync.sh index 9369bdd..d246d85 100755 --- a/osync.sh +++ b/osync.sh @@ -1,10 +1,10 @@ -#!/usr/bin/env bash +2#!/usr/bin/env bash PROGRAM="Osync" # Rsync based two way sync engine with fault tolerance AUTHOR="(L) 2013-2015 by Orsiris \"Ozy\" de Jong" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" -PROGRAM_VERSION=1.00pre-hotfix22 -PROGRAM_BUILD=2406201502 +PROGRAM_VERSION=1.00pre-hotfix2#22 +PROGRAM_BUILD=2606201501 ## type doesn't work on platforms other than linux (bash). If if doesn't work, always assume output is not a zero exitcode if ! type -p "$BASH" > /dev/null @@ -870,7 +870,7 @@ function RsyncExcludeFrom function WriteLockFiles { - echo $SCRIPT_PID > "$MASTER_LOCK" + echo $SCRIPT_PID > "$MASTER_LOCK" 2> "$LOG_FILE" if [ $? != 0 ] then LogError "Could not set lock on master replica." @@ -1183,7 +1183,15 @@ function _delete_local then rm -rf "$REPLICA_DIR$3/$files" fi - mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$3" + # In order to keep full path on soft deletion, create parent directories before move + parentdir="$(dirname "$files")" + if [ "$parentdir" != "." ] + then + mkdir --parents "$REPLICA_DIR$3/$parentdir" + mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$3/$parentdir" + else + mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$3" + fi if [ $? != 0 ] then LogError "Cannot move $REPLICA_DIR$files to deletion directory." @@ -1290,7 +1298,15 @@ $SSH_CMD error_alert=0 sync_on_changes=$sync_on_changes silent=$silent DEBUG=$DE then $COMMAND_SUDO rm -rf "$REPLICA_DIR$DELETE_DIR/$files" fi - $COMMAND_SUDO mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$DELETE_DIR" + # In order to keep full path on soft deletion, create parent directories before move + parentdir="$(dirname "$files")" + if [ "$parentdir" != "." ] + then + $COMMAND_SUDO mkdir --parents "$REPLICA_DIR$DELETE_DIR/$parentdir" + $COMMAND_SUDO mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$DELETE_DIR/$parentdir" + else + $COMMAND_SUDO mv -f "$REPLICA_DIR$files" "$REPLICA_DIR$DELETE_DIR" + fi if [ $? != 0 ] then LogError "Cannot move $REPLICA_DIR$files to deletion directory."