diff --git a/dev/n_osync.sh b/dev/n_osync.sh index 0c384af..ff0da9b 100755 --- a/dev/n_osync.sh +++ b/dev/n_osync.sh @@ -2,12 +2,13 @@ #TODO treeList, deleteList, _getFileCtimeMtime, conflictList should be called without having statedir informed. Just give the full path ? #TODO check if _getCtimeMtime | sort removal needs to be backported +#Check dryruns with nosuffix mode for timestampList PROGRAM="osync" # Rsync based two way sync engine with fault tolerance AUTHOR="(C) 2013-2017 by Orsiris de Jong" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" PROGRAM_VERSION=1.2.2-dev -PROGRAM_BUILD=2017061801 +PROGRAM_BUILD=2017072701 IS_STABLE=no @@ -2242,6 +2243,7 @@ function Init { readonly __timestampAfterFile=17 readonly __timestampAfterFileNoSuffix=18 readonly __conflictListFile=19 + readonly __updateTriggerFile=20 INITIATOR=() INITIATOR[$__type]='initiator' @@ -2264,6 +2266,7 @@ function Init { INITIATOR[$__timestampAfterFile]="-timestamps-after-$INSTANCE_ID$drySuffix" INITIATOR[$__timestampAfterFileNoSuffix]="-timestamps-after-$INSTANCE_ID" INITIATOR[$__conflictListFile]="conflicts-$INSTANCE_ID$drySuffix" + INITIATOR[$__updateTriggerFile]="$INITIATOR_SYNC_DIR$OSYNC_DIR/.osync-update.push" TARGET=() TARGET[$__type]='target' @@ -2278,7 +2281,6 @@ function Init { TARGET[$__resumeCount]="$TARGET_SYNC_DIR$OSYNC_DIR/$stateDir/$resumeCount-$INSTANCE_ID$drySuffix" # unused TARGET[$__treeCurrentFile]="-tree-current-$INSTANCE_ID$drySuffix" # unused TARGET[$__treeAfterFile]="-tree-after-$INSTANCE_ID$drySuffix" # unused - #WIP NoSuffix file to add to timestamp TARGET[$__treeAfterFileNoSuffix]="-tree-after-$INSTANCE_ID" # unused TARGET[$__deletedListFile]="-deleted-list-$INSTANCE_ID$drySuffix" # unused TARGET[$__failedDeletedListFile]="-failed-delete-$INSTANCE_ID$drySuffix" @@ -2287,6 +2289,7 @@ function Init { TARGET[$__timestampAfterFile]="-timestamps-after-$INSTANCE_ID$drySuffix" TARGET[$__timestampAfterFileNoSuffix]="-timestamps-after-$INSTANCE_ID" TARGET[$__conflictListFile]="conflicts-$INSTANCE_ID$drySuffix" + TARGET[$__updateTriggerFile]="$TARGET_SYNC_DIR$OSYNC_DIR/.osync-update.push" PARTIAL_DIR="${INITIATOR[$__partialDir]}" @@ -2479,165 +2482,169 @@ _NOLOCKS=false osync_cmd=$0 _SUMMARY=false -if [ $# -eq 0 ] -then - Usage -fi -first=1 -for i in "$@"; do - case $i in - --dry) - _DRYRUN=true - opts=$opts" --dry" - ;; - --silent) - _LOGGER_SILENT=true - opts=$opts" --silent" - ;; - --verbose) - _LOGGER_VERBOSE=true - opts=$opts" --verbose" - ;; - --stats) - STATS=true - opts=$opts" --stats" - ;; - --partial) - PARTIAL="yes" - opts=$opts" --partial" - ;; - --force-unlock) - FORCE_UNLOCK=true - opts=$opts" --force-unlock" - ;; - --no-maxtime) - no_maxtime=true - opts=$opts" --no-maxtime" - ;; - --help|-h|--version|-v) +function GetCommandlineArguments { + local isFirstArgument=true + + if [ $# -eq 0 ] + then Usage - ;; - --initiator=*) - _QUICK_SYNC=$(($_QUICK_SYNC + 1)) - INITIATOR_SYNC_DIR=${i##*=} - opts=$opts" --initiator=\"$INITIATOR_SYNC_DIR\"" - ;; - --target=*) - _QUICK_SYNC=$(($_QUICK_SYNC + 1)) - TARGET_SYNC_DIR=${i##*=} - opts=$opts" --target=\"$TARGET_SYNC_DIR\"" - ;; - --rsakey=*) - SSH_RSA_PRIVATE_KEY=${i##*=} - opts=$opts" --rsakey=\"$SSH_RSA_PRIVATE_KEY\"" - ;; - --password-file=*) - SSH_PASSWORD_FILE=${i##*=} - opts=$opts" --password-file\"$SSH_PASSWORD_FILE\"" - ;; - --instance-id=*) - INSTANCE_ID=${i##*=} - opts=$opts" --instance-id=\"$INSTANCE_ID\"" - ;; - --skip-deletion=*) - opts=$opts" --skip-deletion=\"${i##*=}\"" - SKIP_DELETION=${##*=} - ;; - --on-changes) - sync_on_changes=true - _NOLOCKS=true - _LOGGER_PREFIX="date" - ;; - --no-resume) - opts=$opts" --no-resume" - RESUME_TRY=0 - ;; - --no-locks) - _NOLOCKS=true - ;; - --errors-only) - opts=$opts" --errors-only" - _LOGGER_ERR_ONLY=true - ;; - --summary) - opts=$opts" --summary" - _SUMMARY=true - ;; - --log-conflicts) - LOG_CONFLICTS="yes" - opts=$opts" --log-conflicts" - ;; - --alert-conflicts) - ALERT_CONFLICTS="yes" - LOG_CONFLICTS="yes" - opts=$opts" --alert-conflicts" - ;; - --no-prefix) - opts=$opts" --no-prefix" - _LOGGER_PREFIX="" - ;; - --destination-mails=*) - DESTINATION_MAILS=${i##*=} - ;; - --remote-token=*) - _REMOTE_TOKEN=${i##*=} - ;; - *) - if [ $first == "0" ]; then - Logger "Unknown option '$i'" "CRITICAL" - Usage - fi - ;; - esac - first=0 -done - -# Remove leading space if there is one -opts="${opts# *}" - - ## Here we set default options for quicksync tasks when no configuration file is provided. - - if [ $_QUICK_SYNC -eq 2 ]; then - if [ "$INSTANCE_ID" == "" ]; then - INSTANCE_ID="quicksync_task" - fi - - # Let the possibility to initialize those values directly via command line like SOFT_DELETE_DAYS=60 ./osync.sh - - if [ $(IsInteger $MINIMUM_SPACE) -ne 1 ]; then - MINIMUM_SPACE=1024 - fi - - if [ $(IsInteger $CONFLICT_BACKUP_DAYS) -ne 1 ]; then - CONFLICT_BACKUP_DAYS=30 - fi - - if [ $(IsInteger $SOFT_DELETE_DAYS) -ne 1 ]; then - SOFT_DELETE_DAYS=30 - fi - - if [ $(IsInteger $RESUME_TRY) -ne 1 ]; then - RESUME_TRY=1 - fi - - if [ $(IsInteger $SOFT_MAX_EXEC_TIME) -ne 1 ]; then - SOFT_MAX_EXEC_TIME=0 - fi - if [ $(IsInteger $HARD_MAX_EXEC_TIME) -ne 1 ]; then - HARD_MAX_EXEC_TIME=0 - fi - - if [ "$PATH_SEPARATOR_CHAR" == "" ]; then - PATH_SEPARATOR_CHAR=";" - fi - - MIN_WAIT=30 - else - ConfigFile="${1}" - LoadConfigFile "$ConfigFile" fi + for i in "$@"; do + case $i in + --dry) + _DRYRUN=true + opts=$opts" --dry" + ;; + --silent) + _LOGGER_SILENT=true + opts=$opts" --silent" + ;; + --verbose) + _LOGGER_VERBOSE=true + opts=$opts" --verbose" + ;; + --stats) + STATS=true + opts=$opts" --stats" + ;; + --partial) + PARTIAL="yes" + opts=$opts" --partial" + ;; + --force-unlock) + FORCE_UNLOCK=true + opts=$opts" --force-unlock" + ;; + --no-maxtime) + no_maxtime=true + opts=$opts" --no-maxtime" + ;; + --help|-h|--version|-v) + Usage + ;; + --initiator=*) + _QUICK_SYNC=$(($_QUICK_SYNC + 1)) + INITIATOR_SYNC_DIR=${i##*=} + opts=$opts" --initiator=\"$INITIATOR_SYNC_DIR\"" + ;; + --target=*) + _QUICK_SYNC=$(($_QUICK_SYNC + 1)) + TARGET_SYNC_DIR=${i##*=} + opts=$opts" --target=\"$TARGET_SYNC_DIR\"" + ;; + --rsakey=*) + SSH_RSA_PRIVATE_KEY=${i##*=} + opts=$opts" --rsakey=\"$SSH_RSA_PRIVATE_KEY\"" + ;; + --password-file=*) + SSH_PASSWORD_FILE=${i##*=} + opts=$opts" --password-file\"$SSH_PASSWORD_FILE\"" + ;; + --instance-id=*) + INSTANCE_ID=${i##*=} + opts=$opts" --instance-id=\"$INSTANCE_ID\"" + ;; + --skip-deletion=*) + opts=$opts" --skip-deletion=\"${i##*=}\"" + SKIP_DELETION=${##*=} + ;; + --on-changes) + sync_on_changes=true + _NOLOCKS=true + _LOGGER_PREFIX="date" + ;; + --no-resume) + opts=$opts" --no-resume" + RESUME_TRY=0 + ;; + --no-locks) + _NOLOCKS=true + ;; + --errors-only) + opts=$opts" --errors-only" + _LOGGER_ERR_ONLY=true + ;; + --summary) + opts=$opts" --summary" + _SUMMARY=true + ;; + --log-conflicts) + LOG_CONFLICTS="yes" + opts=$opts" --log-conflicts" + ;; + --alert-conflicts) + ALERT_CONFLICTS="yes" + LOG_CONFLICTS="yes" + opts=$opts" --alert-conflicts" + ;; + --no-prefix) + opts=$opts" --no-prefix" + _LOGGER_PREFIX="" + ;; + --destination-mails=*) + DESTINATION_MAILS=${i##*=} + ;; + --remote-token=*) + _REMOTE_TOKEN=${i##*=} + ;; + *) + if [ $isFirstArgument == false ]; then + Logger "Unknown option '$i'" "CRITICAL" + Usage + fi + ;; + esac + isFirstArgument=false + done + + # Remove leading space if there is one + opts="${opts# *}" +} + +GetCommandlineArguments "$@" + +## Here we set default options for quicksync tasks when no configuration file is provided. +if [ $_QUICK_SYNC -eq 2 ]; then + if [ "$INSTANCE_ID" == "" ]; then + INSTANCE_ID="quicksync_task" + fi + + # Let the possibility to initialize those values directly via command line like SOFT_DELETE_DAYS=60 ./osync.sh + if [ $(IsInteger $MINIMUM_SPACE) -ne 1 ]; then + MINIMUM_SPACE=1024 + fi + + if [ $(IsInteger $CONFLICT_BACKUP_DAYS) -ne 1 ]; then + CONFLICT_BACKUP_DAYS=30 + fi + + if [ $(IsInteger $SOFT_DELETE_DAYS) -ne 1 ]; then + SOFT_DELETE_DAYS=30 + fi + + if [ $(IsInteger $RESUME_TRY) -ne 1 ]; then + RESUME_TRY=1 + fi + + if [ $(IsInteger $SOFT_MAX_EXEC_TIME) -ne 1 ]; then + SOFT_MAX_EXEC_TIME=0 + fi + + if [ $(IsInteger $HARD_MAX_EXEC_TIME) -ne 1 ]; then + HARD_MAX_EXEC_TIME=0 + fi + + if [ "$PATH_SEPARATOR_CHAR" == "" ]; then + PATH_SEPARATOR_CHAR=";" + fi + MIN_WAIT=30 +else + ConfigFile="${1}" + LoadConfigFile "$ConfigFile" +fi + if [ "$LOGFILE" == "" ]; then if [ -w /var/log ]; then LOG_FILE="/var/log/$PROGRAM.$INSTANCE_ID.log"