diff --git a/dev/n_osync.sh b/dev/n_osync.sh index f196562..3b7a182 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="(C) 2013-2016 by Orsiris de Jong" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" PROGRAM_VERSION=1.2-beta2 -PROGRAM_BUILD=2016101704 +PROGRAM_BUILD=2016102101 IS_STABLE=no # Execution order #__WITH_PARANOIA_DEBUG @@ -170,6 +170,11 @@ function CheckCurrentConfigAll { Logger "Cannot find rsa private key [$SSH_RSA_PRIVATE_KEY] nor password file [$SSH_PASSWORD_FILE]. No authentication method provided." "CRITICAL" exit 1 fi + + if [ "$SKIP_DELETION" != "" ] && [ $(arrayContains "${INITIATOR[$__type]}" "${SKIP_DELETION[@]}") -ne 0 ] && [ $(arrayContains "${TARGET[$__type]}" "${SKIP_DELETION[@]}") -ne 0 ]; then + Logger "Bogus skip deletion parameter." "CRITICAL" + exit 1 + fi } ###### Osync specific functions (non shared) @@ -1167,36 +1172,44 @@ function deletionPropagation { #TODO: deletionPropagation replicaType = source replica whereas _deleteXxxxxx replicaType = dest replica if [ "$replicaType" == "${INITIATOR[$__type]}" ]; then - replicaDir="${INITIATOR[$__replicaDir]}" - deleteDir="${INITIATOR[$__deleteDir]}" - - _deleteLocal "${TARGET[$__type]}" "$replicaDir" "$deleteDir" - retval=$? - if [ $retval != 0 ]; then - Logger "Deletion on $replicaType replica failed." "CRITICAL" - exit 1 - fi - else - replicaDir="${TARGET[$__replicaDir]}" - deleteDir="${TARGET[$__deleteDir]}" - - if [ "$REMOTE_OPERATION" == "yes" ]; then - _deleteRemote "${INITIATOR[$__type]}" "$replicaDir" "$deleteDir" + if [ $(arrayContains "${INITIATOR[$__type]}" "${SKIP_DELETION[@]}") -ne 0 ]; then + replicaDir="${INITIATOR[$__replicaDir]}" + deleteDir="${INITIATOR[$__deleteDir]}" + + _deleteLocal "${TARGET[$__type]}" "$replicaDir" "$deleteDir" + retval=$? + if [ $retval != 0 ]; then + Logger "Deletion on $replicaType replica failed." "CRITICAL" + exit 1 + fi else - _deleteLocal "${INITIATOR[$__type]}" "$replicaDir" "$deleteDir" + Logger "Skipping deletion on replica $replicaType." "NOTICE" fi - retval=$? - if [ $retval == 0 ]; then - if [ -f "$RUN_DIR/$PROGRAM._delete_remote.$SCRIPT_PID" ]; then - Logger "Remote:\n$(cat $RUN_DIR/$PROGRAM._delete_remote.$SCRIPT_PID)" "VERBOSE" + elif [ "$replicaType" == "${TARGET[$__type]}" ]; then + if [ $(arrayContains "${TARGET[$__type]}" "${SKIP_DELETION[@]}") -ne 0 ]; then + replicaDir="${TARGET[$__replicaDir]}" + deleteDir="${TARGET[$__deleteDir]}" + + if [ "$REMOTE_OPERATION" == "yes" ]; then + _deleteRemote "${INITIATOR[$__type]}" "$replicaDir" "$deleteDir" + else + _deleteLocal "${INITIATOR[$__type]}" "$replicaDir" "$deleteDir" fi - return $retval - else - Logger "Deletion on $replicaType failed." "CRITICAL" - if [ -f "$RUN_DIR/$PROGRAM.remote_deletion.$SCRIPT_PID" ]; then - Logger "Remote:\n$(cat $RUN_DIR/$PROGRAM.remote_deletion.$SCRIPT_PID)" "CRITICAL" + retval=$? + if [ $retval == 0 ]; then + if [ -f "$RUN_DIR/$PROGRAM._delete_remote.$SCRIPT_PID" ]; then + Logger "Remote:\n$(cat $RUN_DIR/$PROGRAM._delete_remote.$SCRIPT_PID)" "VERBOSE" + fi + return $retval + else + Logger "Deletion on $replicaType failed." "CRITICAL" + if [ -f "$RUN_DIR/$PROGRAM.remote_deletion.$SCRIPT_PID" ]; then + Logger "Remote:\n$(cat $RUN_DIR/$PROGRAM.remote_deletion.$SCRIPT_PID)" "CRITICAL" + fi + exit 1 fi - exit 1 + else + Logger "Skipping deletion on replica $replicaType." "NOTICE" fi fi } @@ -1847,6 +1860,7 @@ function Usage { echo "--rsakey=\"\" Alternative path to rsa private key for ssh connection to target replica" echo "--password-file=\"\" If no rsa private key is used for ssh authentication, a password file can be used" echo "--instance-id=\"\" Optional sync task name to identify this synchronization task when using multiple targets" + echo "--skip-deletion=\"\" You may skip deletion propagation on initiator or target. Valid values: initiator target initiator,target" echo "" echo "Additionaly, you may set most osync options at runtime. eg:" echo "SOFT_DELETE_DAYS=365 osync.sh --initiator=/path --target=/other/path" @@ -1983,6 +1997,11 @@ for i in "$@"; do INSTANCE_ID=${i##*=} opts=$opts" --instance-id=\"$INSTANCE_ID\"" ;; + --skip-deletion=*) + #SKIP_DELETION=${i##*=} + opts=$opts" --skip-deletion=\"${i##*=}\"" + IFS=',' read -r -a SKIP_DELETION <<< ${i##*=} + ;; --on-changes) sync_on_changes=true _NOLOCKS=true diff --git a/sync.conf.example b/sync.conf.example index 761cf02..a4e6ec4 100644 --- a/sync.conf.example +++ b/sync.conf.example @@ -2,7 +2,7 @@ ###### osync - Rsync based two way sync engine with fault tolerance ###### (C) 2013-2016 by Orsiris de Jong (www.netpower.fr) -###### osync v1.1x / v1.2x config file rev 2016101901 +###### osync v1.1x / v1.2x config file rev 2016102101 ## ---------- GENERAL OPTIONS @@ -133,6 +133,9 @@ SOFT_DELETE=yes ## Osync will clean deleted files after a given number of days. Setting this to 0 will disable cleaning and keep deleted files forever. Warning: This can be very space consuming. SOFT_DELETE_DAYS=30 +## Optional deletion skip on replicas. Valid values are "initiator", "target", or "initiator,target" +SKIP_DELETION= + ## ---------- RESUME OPTIONS ## Try to resume an aborted sync task diff --git a/upgrade-v1.0x-v1.2x.sh b/upgrade-v1.0x-v1.2x.sh index d0c2db0..5df25db 100755 --- a/upgrade-v1.0x-v1.2x.sh +++ b/upgrade-v1.0x-v1.2x.sh @@ -6,7 +6,7 @@ AUTHOR="(C) 2016 by Orsiris de Jong" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" OLD_PROGRAM_VERSION="v1.0x-v1.1x" NEW_PROGRAM_VERSION="v1.2x" -CONFIG_FILE_VERSION=2016101901 +CONFIG_FILE_VERSION=2016102101 PROGRAM_BUILD=2016101701 ## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode @@ -64,6 +64,7 @@ CONFLICT_BACKUP_DAYS CONFLICT_PREVALANCE SOFT_DELETE SOFT_DELETE_DAYS +SKIP_DELETION RESUME_SYNC RESUME_TRY FORCE_STRANGER_LOCK_RESUME @@ -130,6 +131,7 @@ no initiator yes 30 +'' yes 2 no