Improved remote deletion
This commit is contained in:
parent
8214f151db
commit
ab4ed13d8b
38
osync.sh
38
osync.sh
|
@ -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=2505201405
|
PROGRAM_BUILD=2505201406
|
||||||
|
|
||||||
## 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" ]
|
||||||
|
@ -378,9 +378,8 @@ function WaitForTaskCompletion
|
||||||
while eval $PROCESS_TEST > /dev/null
|
while eval $PROCESS_TEST > /dev/null
|
||||||
do
|
do
|
||||||
Spinner
|
Spinner
|
||||||
sleep 1
|
|
||||||
EXEC_TIME=$(($SECONDS - $SECONDS_BEGIN))
|
EXEC_TIME=$(($SECONDS - $SECONDS_BEGIN))
|
||||||
if [ $(($EXEC_TIME % $KEEP_LOGGING)) -eq 0 ]
|
if [ $((($EXEC_TIME + 1) % $KEEP_LOGGING)) -eq 0 ]
|
||||||
then
|
then
|
||||||
Log "Current task still running."
|
Log "Current task still running."
|
||||||
fi
|
fi
|
||||||
|
@ -409,6 +408,7 @@ function WaitForTaskCompletion
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
sleep 1
|
||||||
done
|
done
|
||||||
wait $child_pid
|
wait $child_pid
|
||||||
return $?
|
return $?
|
||||||
|
@ -428,8 +428,7 @@ function WaitForCompletion
|
||||||
while eval $PROCESS_TEST > /dev/null
|
while eval $PROCESS_TEST > /dev/null
|
||||||
do
|
do
|
||||||
Spinner
|
Spinner
|
||||||
sleep 1
|
if [ $((($SECONDS + 1) % $KEEP_LOGGING)) -eq 0 ]
|
||||||
if [ $(($SECONDS % $KEEP_LOGGING)) -eq 0 ]
|
|
||||||
then
|
then
|
||||||
Log "Current task still running."
|
Log "Current task still running."
|
||||||
fi
|
fi
|
||||||
|
@ -458,6 +457,7 @@ function WaitForCompletion
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
sleep 1
|
||||||
done
|
done
|
||||||
wait $child_pid
|
wait $child_pid
|
||||||
return $?
|
return $?
|
||||||
|
@ -1062,12 +1062,11 @@ function sync_update
|
||||||
# delete_local(replica dir, delete file list, delete dir)
|
# delete_local(replica dir, delete file list, delete dir)
|
||||||
function _delete_local
|
function _delete_local
|
||||||
{
|
{
|
||||||
|
|
||||||
## On every run, check wheter the next item is already deleted because it's included in a directory already deleted
|
## On every run, check wheter the next item is already deleted because it's included in a directory already deleted
|
||||||
previous_file=""
|
previous_file=""
|
||||||
OLD_IFS=$IFS
|
OLD_IFS=$IFS
|
||||||
IFS=$'\r\n'
|
IFS=$'\r\n'
|
||||||
for files in $(cat "$2")
|
for files in $(cat "$MASTER_STATE_DIR/$2")
|
||||||
do
|
do
|
||||||
if [[ "$files" != "$previous_file/"* ]] && [ "$files" != "" ]
|
if [[ "$files" != "$previous_file/"* ]] && [ "$files" != "" ]
|
||||||
then
|
then
|
||||||
|
@ -1123,9 +1122,9 @@ function _delete_remote
|
||||||
## Anything beetween << ENDSSH and ENDSSH will be executed remotely
|
## Anything beetween << ENDSSH and ENDSSH will be executed remotely
|
||||||
|
|
||||||
# Additionnaly, we need to copy the deletetion list to the remote state folder
|
# Additionnaly, we need to copy the deletetion list to the remote state folder
|
||||||
ESC_DEST_DIR="$(EscapeSpaces $SLAVE_STATE_DIR)"
|
ESC_DEST_DIR="$(EscapeSpaces "$SLAVE_STATE_DIR")"
|
||||||
rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $SYNC_OPTS -e \"$RSYNC_SSH_CMD\" \"$2\" $REMOTE_USER@$REMOTE_HOST:\"$ESC_DEST_DIR/\" > $RUN_DIR/osync_remote_deletion_list_copy_$SCRIPT_PID 2>&1"
|
rsync_cmd="$(type -p $RSYNC_EXECUTABLE) --rsync-path=\"$RSYNC_PATH\" $SYNC_OPTS -e \"$RSYNC_SSH_CMD\" \"$MASTER_STATE_DIR/$2\" $REMOTE_USER@$REMOTE_HOST:\"$ESC_DEST_DIR/\" > $RUN_DIR/osync_remote_deletion_list_copy_$SCRIPT_PID 2>&1"
|
||||||
eval $rsync_cmd
|
eval $rsync_cmd 2>> "$LOG_FILE"
|
||||||
if [ $? != 0 ]
|
if [ $? != 0 ]
|
||||||
then
|
then
|
||||||
LogError "Cannot copy the deletion list to remote replica."
|
LogError "Cannot copy the deletion list to remote replica."
|
||||||
|
@ -1136,7 +1135,7 @@ function _delete_remote
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$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 "$SLAVE_STATE_DIR/$(basename $2)") REPLICA_DIR="$(EscapeSpaces "$REPLICA_DIR") DELETE_DIR="$(EscapeSpaces "$DELETE_DIR") 'bash -s' << 'ENDSSH' > $RUN_DIR/osync_remote_deletion_$SCRIPT_PID 2>&1 &
|
$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 "$SLAVE_STATE_DIR/$2")" REPLICA_DIR="$(EscapeSpaces "$REPLICA_DIR")" DELETE_DIR="$(EscapeSpaces "$DELETE_DIR")" 'bash -s' << 'ENDSSH' > $RUN_DIR/osync_remote_deletion_$SCRIPT_PID 2>&1 &
|
||||||
|
|
||||||
## The following lines are executed remotely
|
## The following lines are executed remotely
|
||||||
function Log
|
function Log
|
||||||
|
@ -1209,7 +1208,8 @@ $SSH_CMD error_alert=0 sync_on_changes=$sync_on_changes silent=$silent DEBUG=$DE
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
ENDSSH
|
ENDSSH
|
||||||
|
## Need to add a trivial sleep time to give ssh time to log to local file
|
||||||
|
sleep 5
|
||||||
exit $?
|
exit $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1226,9 +1226,9 @@ function deletion_propagation
|
||||||
DELETE_DIR="$MASTER_DELETE_DIR"
|
DELETE_DIR="$MASTER_DELETE_DIR"
|
||||||
if [ $dryrun -eq 1 ]
|
if [ $dryrun -eq 1 ]
|
||||||
then
|
then
|
||||||
DELETION_FILE_LIST="$MASTER_STATE_DIR/dry-slave-deleted-list-$SYNC_ID"
|
DELETION_FILE_LIST="dry-slave-deleted-list-$SYNC_ID"
|
||||||
else
|
else
|
||||||
DELETION_FILE_LIST="$MASTER_STATE_DIR/slave-deleted-list-$SYNC_ID"
|
DELETION_FILE_LIST="slave-deleted-list-$SYNC_ID"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_delete_local "$REPLICA_DIR" "$DELETION_FILE_LIST" "$DELETE_DIR" &
|
_delete_local "$REPLICA_DIR" "$DELETION_FILE_LIST" "$DELETE_DIR" &
|
||||||
|
@ -1248,9 +1248,9 @@ function deletion_propagation
|
||||||
DELETE_DIR="$SLAVE_DELETE_DIR"
|
DELETE_DIR="$SLAVE_DELETE_DIR"
|
||||||
if [ $dryrun -eq 1 ]
|
if [ $dryrun -eq 1 ]
|
||||||
then
|
then
|
||||||
DELETION_FILE_LIST="$MASTER_STATE_DIR/dry-master-deleted-list-$SYNC_ID"
|
DELETION_FILE_LIST="dry-master-deleted-list-$SYNC_ID"
|
||||||
else
|
else
|
||||||
DELETION_FILE_LIST="$MASTER_STATE_DIR/master-deleted-list-$SYNC_ID"
|
DELETION_FILE_LIST="master-deleted-list-$SYNC_ID"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$REMOTE_SYNC" == "yes" ]
|
if [ "$REMOTE_SYNC" == "yes" ]
|
||||||
|
@ -1264,12 +1264,16 @@ function deletion_propagation
|
||||||
retval=$?
|
retval=$?
|
||||||
if [ $retval == 0 ]
|
if [ $retval == 0 ]
|
||||||
then
|
then
|
||||||
|
if [ -f $RUN_DIR/osync_remote_deletion_$SCRIPT_PID ] && [ $verbose -eq 1 ]
|
||||||
|
then
|
||||||
|
Log "Remote:\n$(cat $RUN_DIR/osync_remote_deletion_$SCRIPT_PID)"
|
||||||
|
fi
|
||||||
echo "delete-propagation-$1.success" > "$MASTER_LAST_ACTION"
|
echo "delete-propagation-$1.success" > "$MASTER_LAST_ACTION"
|
||||||
else
|
else
|
||||||
LogError "Deletion on remote system failed."
|
LogError "Deletion on remote system failed."
|
||||||
if [ -f $RUN_DIR/osync_remote_deletion_$SCRIPT_PID ]
|
if [ -f $RUN_DIR/osync_remote_deletion_$SCRIPT_PID ]
|
||||||
then
|
then
|
||||||
LogError "$(cat $RUN_DIR/osync_remote_deletion_$SCRIPT_PID)"
|
LogError "Remote:\n$(cat $RUN_DIR/osync_remote_deletion_$SCRIPT_PID)"
|
||||||
fi
|
fi
|
||||||
echo "delete-propagation-$1.fail" > "$MASTER_LAST_ACTION"
|
echo "delete-propagation-$1.fail" > "$MASTER_LAST_ACTION"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
Loading…
Reference in New Issue