Added multislave async task support

This commit is contained in:
deajan 2014-05-08 22:08:15 +02:00
parent b65c5a22ff
commit a4edfb0207
2 changed files with 34 additions and 32 deletions

View File

@ -20,11 +20,12 @@ UNDER WORK
---------- ----------
!- Better deletion propagation (again). Using rsync for deletion propagation is definitly not working in all cases (especially empty sub directories) !- Better deletion propagation (again). Using rsync for deletion propagation is definitly not working in all cases (especially empty sub directories)
!- Mutlislave asynchronous sync support
RECENT CHANGES RECENT CHANGES
-------------- --------------
- Multislave asynchronous task support (Thanks to Ulrich Norbisrath)
- This breaks compat with elder osync runs. Add the SYNC_ID suffix to elder state files to keep deleted file information.
- Added an easier debug setting i.e DEBUG=yes ./osync.sh (Again, thanks to Ulrich Norbisrath) - Added an easier debug setting i.e DEBUG=yes ./osync.sh (Again, thanks to Ulrich Norbisrath)
- Added hardlink preservation (Thanks to Ulrich Norbisrath) - Added hardlink preservation (Thanks to Ulrich Norbisrath)
- Added external exclusion file support (Thanks to Pierre Clement) - Added external exclusion file support (Thanks to Pierre Clement)

View File

@ -4,7 +4,7 @@ PROGRAM="Osync" # Rsync based two way sync engine with fault tolerance
AUTHOR="(L) 2013-2014 by Orsiris \"Ozy\" de Jong" AUTHOR="(L) 2013-2014 by Orsiris \"Ozy\" de Jong"
CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr"
PROGRAM_VERSION=0.99preRC3 PROGRAM_VERSION=0.99preRC3
PROGRAM_BUILD=0805201403 PROGRAM_BUILD=0805201404
## allow debugging from command line with preceding ocsync with DEBUG=yes ## allow debugging from command line with preceding ocsync with DEBUG=yes
if [ ! "$DEBUG" == "yes" ] if [ ! "$DEBUG" == "yes" ]
@ -935,9 +935,9 @@ function tree_list
then then
if [ $dryrun -eq 1 ] if [ $dryrun -eq 1 ]
then then
mv $RUN_DIR/osync_$2_$SCRIPT_PID "$MASTER_STATE_DIR/dry-$2" mv $RUN_DIR/osync_$2_$SCRIPT_PID "$MASTER_STATE_DIR/dry-$2-$SYNC_ID"
else else
mv $RUN_DIR/osync_$2_$SCRIPT_PID "$MASTER_STATE_DIR/$2" mv $RUN_DIR/osync_$2_$SCRIPT_PID "$MASTER_STATE_DIR/$2-$SYNC_ID"
fi fi
echo "$3.success" > "$MASTER_LAST_ACTION" echo "$3.success" > "$MASTER_LAST_ACTION"
@ -952,24 +952,24 @@ function tree_list
function delete_list function delete_list
{ {
Log "Creating $1 replica deleted file list." Log "Creating $1 replica deleted file list."
if [ -f "$MASTER_STATE_DIR/$1-tree-after" ] if [ -f "$MASTER_STATE_DIR/$1-tree-after-$SYNC_ID" ]
then then
if [ $dryrun -eq 1 ] if [ $dryrun -eq 1 ]
then then
## Same functionnality, comm is much faster than grep but is not available on every platform ## Same functionnality, comm is much faster than grep but is not available on every platform
if type -p comm > /dev/null 2>&1 if type -p comm > /dev/null 2>&1
then then
cmd="comm -23 \"$MASTER_STATE_DIR/$1-tree-after\" \"$MASTER_STATE_DIR/dry-$1-tree-current\" > \"$MASTER_STATE_DIR/dry-$1-deleted-list\"" cmd="comm -23 \"$MASTER_STATE_DIR/$1-tree-after-$SYNC_ID\" \"$MASTER_STATE_DIR/dry-$1-tree-current-$SYNC_ID\" > \"$MASTER_STATE_DIR/dry-$1-deleted-list-$SYNC_ID\""
else else
## The || : forces the command to have a good result ## The || : forces the command to have a good result
cmd="grep -F -x -v -f \"$MASTER_STATE_DIR/dry-$1-tree-current\" \"$MASTER_STATE_DIR/$1-tree-after\" || : > \"$MASTER_STATE_DIR/dry-$1-deleted-list\"" cmd="grep -F -x -v -f \"$MASTER_STATE_DIR/dry-$1-tree-current-$SYNC_ID\" \"$MASTER_STATE_DIR/$1-tree-after-$SYNC_ID\" || : > \"$MASTER_STATE_DIR/dry-$1-deleted-list-$SYNC_ID\""
fi fi
else else
if type -p comm > /dev/null 2>&1 if type -p comm > /dev/null 2>&1
then then
cmd="comm -23 \"$MASTER_STATE_DIR/$1-tree-after\" \"$MASTER_STATE_DIR/$1-tree-current\" > \"$MASTER_STATE_DIR/$1-deleted-list\"" cmd="comm -23 \"$MASTER_STATE_DIR/$1-tree-after-$SYNC_ID\" \"$MASTER_STATE_DIR/$1-tree-current-$SYNC_ID\" > \"$MASTER_STATE_DIR/$1-deleted-list-$SYNC_ID\""
else else
cmd="grep -F -x -v -f \"$MASTER_STATE_DIR/$1-tree-current\" \"$MASTER_STATE_DIR/$1-tree-after\" || : > \"$MASTER_STATE_DIR/$1-deleted-list\"" cmd="grep -F -x -v -f \"$MASTER_STATE_DIR/$1-tree-current-$SYNC_ID\" \"$MASTER_STATE_DIR/$1-tree-after-$SYNC_ID\" || : > \"$MASTER_STATE_DIR/$1-deleted-list-$SYNC_ID\""
fi fi
fi fi
@ -977,7 +977,7 @@ function delete_list
eval $cmd eval $cmd
echo "$1-replica-deleted-list.success" > "$MASTER_LAST_ACTION" echo "$1-replica-deleted-list.success" > "$MASTER_LAST_ACTION"
else else
touch "$MASTER_STATE_DIR/$1-deleted-list" touch "$MASTER_STATE_DIR/$1-deleted-list-$SYNC_ID"
echo "$1-replica-deleted-list.empty" > "$MASTER_LAST_ACTION" echo "$1-replica-deleted-list.empty" > "$MASTER_LAST_ACTION"
fi fi
} }
@ -1007,12 +1007,12 @@ function sync_update
CheckConnectivityRemoteHost CheckConnectivityRemoteHost
if [ "$1" == "master" ] if [ "$1" == "master" ]
then then
rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS -rlptgoDEui --stats -e \"$RSYNC_SSH_CMD\" $BACKUP_DIR --exclude \"$OSYNC_DIR\" $RSYNC_EXCLUDE --exclude-from=\"$MASTER_STATE_DIR/$1-deleted-list\" --exclude-from=\"$MASTER_STATE_DIR/$2-deleted-list\" \"$SOURCE_DIR/\" $REMOTE_USER@$REMOTE_HOST:\"$ESC_DEST_DIR/\" > $RUN_DIR/osync_update_$2_replica_$SCRIPT_PID 2>&1 &" rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS -rlptgoDEui --stats -e \"$RSYNC_SSH_CMD\" $BACKUP_DIR --exclude \"$OSYNC_DIR\" $RSYNC_EXCLUDE --exclude-from=\"$MASTER_STATE_DIR/$1-deleted-list-$SYNC_ID\" --exclude-from=\"$MASTER_STATE_DIR/$2-deleted-list-$SYNC_ID\" \"$SOURCE_DIR/\" $REMOTE_USER@$REMOTE_HOST:\"$ESC_DEST_DIR/\" > $RUN_DIR/osync_update_$2_replica_$SCRIPT_PID 2>&1 &"
else else
rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS -rlptgoDEui --stats -e \"$RSYNC_SSH_CMD\" $BACKUP_DIR --exclude \"$OSYNC_DIR\" $RSYNC_EXCLUDE --exclude-from=\"$MASTER_STATE_DIR/$1-deleted-list\" --exclude-from=\"$MASTER_STATE_DIR/$2-deleted-list\" $REMOTE_USER@$REMOTE_HOST:\"$ESC_SOURCE_DIR/\" \"$DEST_DIR/\" > $RUN_DIR/osync_update_$2_replica_$SCRIPT_PID 2>&1 &" rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS -rlptgoDEui --stats -e \"$RSYNC_SSH_CMD\" $BACKUP_DIR --exclude \"$OSYNC_DIR\" $RSYNC_EXCLUDE --exclude-from=\"$MASTER_STATE_DIR/$1-deleted-list-$SYNC_ID\" --exclude-from=\"$MASTER_STATE_DIR/$2-deleted-list-$SYNC_ID\" $REMOTE_USER@$REMOTE_HOST:\"$ESC_SOURCE_DIR/\" \"$DEST_DIR/\" > $RUN_DIR/osync_update_$2_replica_$SCRIPT_PID 2>&1 &"
fi fi
else else
rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS -rlptgoDEui --stats $BACKUP_DIR --exclude \"$OSYNC_DIR\" $RSYNC_EXCLUDE --exclude-from=\"$MASTER_STATE_DIR/$1-deleted-list\" --exclude-from=\"$MASTER_STATE_DIR/$2-deleted-list\" \"$SOURCE_DIR/\" \"$DEST_DIR/\" > $RUN_DIR/osync_update_$2_replica_$SCRIPT_PID 2>&1 &" rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS -rlptgoDEui --stats $BACKUP_DIR --exclude \"$OSYNC_DIR\" $RSYNC_EXCLUDE --exclude-from=\"$MASTER_STATE_DIR/$1-deleted-list-$SYNC_ID\" --exclude-from=\"$MASTER_STATE_DIR/$2-deleted-list-$SYNC_ID\" \"$SOURCE_DIR/\" \"$DEST_DIR/\" > $RUN_DIR/osync_update_$2_replica_$SCRIPT_PID 2>&1 &"
fi fi
LogDebug "RSYNC_CMD: $rsync_cmd" LogDebug "RSYNC_CMD: $rsync_cmd"
eval "$rsync_cmd" eval "$rsync_cmd"
@ -1063,13 +1063,12 @@ function deletion_propagation
CheckConnectivityRemoteHost CheckConnectivityRemoteHost
if [ "$1" == "master" ] if [ "$1" == "master" ]
then then
#rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS -rlptgoDEui --stats -e \"$RSYNC_SSH_CMD\" $DELETE_DIR --delete --exclude \"$OSYNC_DIR\" --include-from=\"$MASTER_STATE_DIR/$1-deleted-list\" --filter=\"-! */\" \"$SOURCE_DIR/\" $REMOTE_USER@$REMOTE_HOST:\"$ESC_DEST_DIR/\" > $RUN_DIR/osync_deletion_on_$2_$SCRIPT_PID 2>&1 &" rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS -rlptgoDEui --stats -e \"$RSYNC_SSH_CMD\" $DELETE_DIR --delete --exclude \"$OSYNC_DIR\" --include=\"*/\" --include-from=\"$MASTER_STATE_DIR/$1-deleted-list-$SYNC_ID\" --filter=\"- *\" \"$SOURCE_DIR/\" $REMOTE_USER@$REMOTE_HOST:\"$ESC_DEST_DIR/\" > $RUN_DIR/osync_deletion_on_$2_$SCRIPT_PID 2>&1 &"
rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS -rlptgoDEui --stats -e \"$RSYNC_SSH_CMD\" $DELETE_DIR --delete --exclude \"$OSYNC_DIR\" --include=\"*/\" --include-from=\"$MASTER_STATE_DIR/$1-deleted-list\" --filter=\"- *\" \"$SOURCE_DIR/\" $REMOTE_USER@$REMOTE_HOST:\"$ESC_DEST_DIR/\" > $RUN_DIR/osync_deletion_on_$2_$SCRIPT_PID 2>&1 &"
else else
rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS -rlptgoDEui --stats -e \"$RSYNC_SSH_CMD\" $DELETE_DIR --delete --exclude \"$OSYNC_DIR\" --include=\"*/\" --include-from=\"$MASTER_STATE_DIR/$1-deleted-list\" --filter=\"- *\" $REMOTE_USER@$REMOTE_HOST:\"$ESC_SOURCE_DIR/\" \"$DEST_DIR/\"> $RUN_DIR/osync_deletion_on_$2_$SCRIPT_PID 2>&1 &" rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS -rlptgoDEui --stats -e \"$RSYNC_SSH_CMD\" $DELETE_DIR --delete --exclude \"$OSYNC_DIR\" --include=\"*/\" --include-from=\"$MASTER_STATE_DIR/$1-deleted-list-$SYNC_ID\" --filter=\"- *\" $REMOTE_USER@$REMOTE_HOST:\"$ESC_SOURCE_DIR/\" \"$DEST_DIR/\"> $RUN_DIR/osync_deletion_on_$2_$SCRIPT_PID 2>&1 &"
fi fi
else else
rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS -rlptgoDEui --stats $DELETE_DIR --delete --exclude \"$OSYNC_DIR\" --include=\"*/\" --include-from=\"$MASTER_STATE_DIR/$1-deleted-list\" --filter=\"- *\" \"$SOURCE_DIR/\" \"$DEST_DIR/\" > $RUN_DIR/osync_deletion_on_$2_$SCRIPT_PID 2>&1 &" rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $RSYNC_ARGS -rlptgoDEui --stats $DELETE_DIR --delete --exclude \"$OSYNC_DIR\" --include=\"*/\" --include-from=\"$MASTER_STATE_DIR/$1-deleted-list-$SYNC_ID\" --filter=\"- *\" \"$SOURCE_DIR/\" \"$DEST_DIR/\" > $RUN_DIR/osync_deletion_on_$2_$SCRIPT_PID 2>&1 &"
fi fi
LogDebug "RSYNC_CMD: $rsync_cmd" LogDebug "RSYNC_CMD: $rsync_cmd"
eval "$rsync_cmd" eval "$rsync_cmd"
@ -1102,12 +1101,12 @@ function Sync
CheckConnectivity3rdPartyHosts CheckConnectivity3rdPartyHosts
CheckConnectivityRemoteHost CheckConnectivityRemoteHost
if [ -f "$MASTER_STATE_DIR/last-action" ] && [ "$RESUME_SYNC" == "yes" ] if [ -f "$MASTER_LAST_ACTION" ] && [ "$RESUME_SYNC" == "yes" ]
then then
resume_sync=$(cat "$MASTER_STATE_DIR/last-action") resume_sync=$(cat "$MASTER_LAST_ACTION")
if [ -f "$MASTER_STATE_DIR/resume-count" ] if [ -f "$MASTER_RESUME_COUNT" ]
then then
resume_count=$(cat "$MASTER_STATE_DIR/resume-count") resume_count=$(cat "$MASTER_RESUME_COUNT")
else else
resume_count=0 resume_count=0
fi fi
@ -1116,10 +1115,10 @@ function Sync
then then
if [ "$resume_sync" != "sync.success" ] if [ "$resume_sync" != "sync.success" ]
then then
Log "WARNING: Trying to resume aborted osync execution on $(stat --format %y "$MASTER_STATE_DIR/last-action") at task [$resume_sync]. [$resume_count] previous tries." Log "WARNING: Trying to resume aborted osync execution on $(stat --format %y "$MASTER_LAST_ACTION") at task [$resume_sync]. [$resume_count] previous tries."
if [ $dryrun -ne 1 ] if [ $dryrun -ne 1 ]
then then
echo $(($resume_count+1)) > "$MASTER_STATE_DIR/resume-count" echo $(($resume_count+1)) > "$MASTER_RESUME_COUNT"
fi fi
else else
resume_sync=none resume_sync=none
@ -1129,7 +1128,7 @@ function Sync
if [ $dryrun -ne 1 ] if [ $dryrun -ne 1 ]
then then
echo "noresume" > "$MASTER_LAST_ACTION" echo "noresume" > "$MASTER_LAST_ACTION"
echo "0" > "$MASTER_STATE_DIR/resume-count" echo "0" > "$MASTER_RESUME_COUNT"
fi fi
resume_sync=none resume_sync=none
fi fi
@ -1144,13 +1143,13 @@ function Sync
if [ "$resume_sync" == "none" ] || [ "$resume_sync" == "noresume" ] || [ "$resume_sync" == "master-replica-tree.fail" ] if [ "$resume_sync" == "none" ] || [ "$resume_sync" == "noresume" ] || [ "$resume_sync" == "master-replica-tree.fail" ]
then then
#master_tree_current #master_tree_current
tree_list "$MASTER_SYNC_DIR" master-tree-current master-replica-tree tree_list "$MASTER_SYNC_DIR" master-tree-current-$SYNC_ID master-replica-tree-$SYNC_ID
resume_sync="resumed" resume_sync="resumed"
fi fi
if [ "$resume_sync" == "resumed" ] || [ "$resume_sync" == "master-replica-tree.success" ] || [ "$resume_sync" == "slave-replica-tree.fail" ] if [ "$resume_sync" == "resumed" ] || [ "$resume_sync" == "master-replica-tree.success" ] || [ "$resume_sync" == "slave-replica-tree.fail" ]
then then
#slave_tree_current #slave_tree_current
tree_list "$SLAVE_SYNC_DIR" slave-tree-current slave-replica-tree tree_list "$SLAVE_SYNC_DIR" slave-tree-current-$SYNC_ID slave-replica-tree-$SYNC_ID
resume_sync="resumed" resume_sync="resumed"
fi fi
if [ "$resume_sync" == "resumed" ] || [ "$resume_sync" == "slave-replica-tree.success" ] || [ "$resume_sync" == "master-replica-deleted-list.fail" ] if [ "$resume_sync" == "resumed" ] || [ "$resume_sync" == "slave-replica-tree.success" ] || [ "$resume_sync" == "master-replica-deleted-list.fail" ]
@ -1203,13 +1202,13 @@ function Sync
if [ "$resume_sync" == "resumed" ] || [ "$resume_sync" == "delete-propagation-master.success" ] || [ "$resume_sync" == "master-replica-tree-after.fail" ] if [ "$resume_sync" == "resumed" ] || [ "$resume_sync" == "delete-propagation-master.success" ] || [ "$resume_sync" == "master-replica-tree-after.fail" ]
then then
#master_tree_after #master_tree_after
tree_list "$MASTER_SYNC_DIR" master-tree-after master-replica-tree-after tree_list "$MASTER_SYNC_DIR" master-tree-after-$SYNC_ID master-replica-tree-after-$SYNC_ID
resume_sync="resumed" resume_sync="resumed"
fi fi
if [ "$resume_sync" == "resumed" ] || [ "$resume_sync" == "master-replica-tree-after.success" ] || [ "$resume_sync" == "slave-replica-tree-after.fail" ] if [ "$resume_sync" == "resumed" ] || [ "$resume_sync" == "master-replica-tree-after.success" ] || [ "$resume_sync" == "slave-replica-tree-after.fail" ]
then then
#slave_tree_after #slave_tree_after
tree_list "$SLAVE_SYNC_DIR" slave-tree-after slave-replica-tree-after tree_list "$SLAVE_SYNC_DIR" slave-tree-after-$SYNC_ID slave-replica-tree-after-$SYNC_ID
resume_sync="resumed" resume_sync="resumed"
fi fi
@ -1218,7 +1217,7 @@ function Sync
if [ $dryrun -ne 1 ] if [ $dryrun -ne 1 ]
then then
echo "0" > "$MASTER_STATE_DIR/resume-count" echo "0" > "$MASTER_RESUME_COUNT"
fi fi
} }
@ -1469,9 +1468,11 @@ function Init
if [ $dryrun -eq 1 ] if [ $dryrun -eq 1 ]
then then
MASTER_LAST_ACTION="$MASTER_STATE_DIR/dry-last-action" MASTER_LAST_ACTION="$MASTER_STATE_DIR/dry-last-action-$SYNC_ID"
MASTER_RESUME_COUNT="$MASTER_STATE_DIR/dry-resume-count-$SYNC_ID"
else else
MASTER_LAST_ACTION="$MASTER_STATE_DIR/last-action" MASTER_LAST_ACTION="$MASTER_STATE_DIR/last-action-$SYNC_ID"
MASTER_RESUME_COUNT="$MASTER_STATE_DIR/resume-count-$SYNC_ID"
fi fi
## Working directories to keep backups of updated / deleted files ## Working directories to keep backups of updated / deleted files
@ -1535,7 +1536,7 @@ function Init
then then
RSYNC_ARGS=$RSYNC_ARGS"z" RSYNC_ARGS=$RSYNC_ARGS"z"
fi fi
if [ "$PRESERVE_HARDLINKS" != "no" ] if [ "$PRESERVE_HARDLINKS" == "yes" ]
then then
RSYNC_ARGS$RSYNC_ARGS"H" RSYNC_ARGS$RSYNC_ARGS"H"
fi fi