WIP: conflict list
This commit is contained in:
parent
99b606fef8
commit
83fd33bf78
|
@ -1,13 +1,12 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# treeList, deleteList, _getFileCtimeMtime, conflictList should be called without having statedir informed. Just give the full path ?
|
||||
|
||||
#TODO treeList, deleteList, _getFileCtimeMtime, conflictList should be called without having statedir informed. Just give the full path ?
|
||||
|
||||
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=2017053102
|
||||
PROGRAM_BUILD=2017060101
|
||||
IS_STABLE=no
|
||||
|
||||
|
||||
|
@ -889,17 +888,15 @@ function timestampList {
|
|||
else
|
||||
_getFileCtimeMtimeLocal "$replicaPath" "$replicaType" "$fileList" "$timestampFilename"
|
||||
fi
|
||||
retval=$?
|
||||
return $retval
|
||||
}
|
||||
|
||||
#WIP
|
||||
function conflictList {
|
||||
return 0
|
||||
|
||||
local replicaPath="${1}" # path to the replica for which a tree needs to be constructed
|
||||
local replicaType="${2}" # replica type: initiator, target
|
||||
local timestampCurrentFilename="${3}" # filename of current timestamp list (will be prefixed with $replicaType)
|
||||
local timestampPreviousFilename="${3}" # filename of previous timestamp list (will be prefixed with $replicaType)
|
||||
local conflictFilename="{4}" # filename of conflicts
|
||||
local timestampCurrentFilename="${1}" # filename of current timestamp list (will be prefixed with $replicaType)
|
||||
local timestampPreviousFilename="${2}" # filename of previous timestamp list (will be prefixed with $replicaType)
|
||||
local conflictFilename="{3}" # filename of conflicts
|
||||
|
||||
__CheckArguments 4 $# "$@" #__WITH_PARANOIA_DEBUG
|
||||
|
||||
|
@ -907,27 +904,35 @@ function conflictList {
|
|||
local escapedReplicaPath
|
||||
local rsyncCmd
|
||||
|
||||
Logger "Creating conflict list for $replicaType replica." "NOTICE"
|
||||
if [ -f "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/${INITIATOR[$__type]}$timestampCurrentFilename" ] && [ -f "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/${TARGET[$__type]}$timestampCurrentFilename" ]; then
|
||||
# Remove prepending replicaPaths
|
||||
sed -i'.replicaPath' "s;^${INITIATOR[$__replicaDir]};;g" "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/${INITIATOR[$__type]}$timestampCurrentFilename"
|
||||
sed -i'.replicaPath' "s;^${TARGET[$__replicaDir]};;g" "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/${TARGET[$__type]}$timestampCurrentFilename"
|
||||
fi
|
||||
|
||||
#WIP missing replica type for those files, also check for presence of current filename
|
||||
if [ -f "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/$timestampPreviousFilename" ] && [ -f "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/$timestampPreviousFilename" ]; then
|
||||
# Compare if previous exists
|
||||
Dummy
|
||||
comm -23 "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/$timestampCurrentFilename" "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/$timestampPreviousFilename" > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$STAMP"
|
||||
comm -23 "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/$timestampCurrentFilename" "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/$timestampPreviousFilename" > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$STAMP"
|
||||
if [ -f "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/${INITIATOR[$__type]}$timestampPreviousFilename" ] && [ -f "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/${TARGET[$__type]}$timestampPreviousFilename" ]; then
|
||||
|
||||
Logger "Creating conflictual file list." "NOTICE"
|
||||
|
||||
comm -23 "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/${INITIATOR[$__type]}$timestampCurrentFilename" "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/${INITIATOR[$__type]}$timestampPreviousFilename" > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.${INITIATOR[$__type]}.$SCRIPT_PID.$STAMP"
|
||||
comm -23 "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/${TARGET[$__type]}$timestampCurrentFilename" "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/${TARGET[$__type]}$timestampPreviousFilename" > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.${TARGET[$__type]}.$SCRIPT_PID.$STAMP"
|
||||
|
||||
|
||||
cp "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.${INITIATOR[$__type]}.$SCRIPT_PID.$STAMP" /tmp/i
|
||||
cp "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.${TARGET[$__type]}.$SCRIPT_PID.$STAMP" /tmp/t
|
||||
fi
|
||||
}
|
||||
|
||||
#WIP
|
||||
function renameTimestampFiles {
|
||||
return 0
|
||||
local timestampCurrentFilename="${1}" # filename of current timestamp list (will be prefixed with $replicaType)
|
||||
local timestampPreviousFilename="${2}" # filename of previous timestamp list (will be prefixed with $replicaType)
|
||||
|
||||
local timestampCurrentFilename="${3}" # filename of current timestamp list (will be prefixed with $replicaType)
|
||||
local timestampPreviousFilename="${3}" # filename of previous timestamp list (will be prefixed with $replicaType)
|
||||
__CheckArguments 2 $# "$@" #__WITH_PARANOIA_DEBUG
|
||||
|
||||
__CheckArguments 4 $# "$@" #__WITH_PARANOIA_DEBUG
|
||||
|
||||
mv -f "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/$timestampCurrentFilename" "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/$timestampPreviousFileName"
|
||||
# WIP missing exit code tests
|
||||
mv -f "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/${INITIATOR[$__type]}$timestampCurrentFilename" "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/${INITIATOR[$__type]}$timestampPreviousFilename"
|
||||
mv -f "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/${TARGET[$__type]}$timestampCurrentFilename" "${INITIATOR[$__replicaDir]}${INITIATOR[$__stateDir]}/${TARGET[$__type]}$timestampPreviousFilename"
|
||||
}
|
||||
|
||||
# rsync does sync with mtime, but file attribute modifications only change ctime.
|
||||
|
@ -1632,46 +1637,18 @@ function Sync {
|
|||
## Step 3a & 3b
|
||||
if [ "$resumeInitiator" == "${SYNC_ACTION[3]}" ] || [ "$resumeTarget" == "${SYNC_ACTION[3]}" ]; then
|
||||
if [[ "$RSYNC_ATTR_ARGS" == *"-X"* ]] || [[ "$RSYNC_ATTR_ARGS" == *"-A"* ]] || [ "$LOG_CONFLICTS" == "yes" ]; then
|
||||
if [ "$resumeInitiator" == "${SYNC_ACTION[3]}" ]; then
|
||||
conflictList "${INITIATOR[$__type]}" &
|
||||
initiatorPid="$!"
|
||||
fi
|
||||
|
||||
if [ "$resumeTarget" == "${SYNC_ACTION[3]}" ]; then
|
||||
conflictList "${TARGET[$__type]}" &
|
||||
targetPid="$!"
|
||||
fi
|
||||
|
||||
WaitForTaskCompletion "$initiatorPid;$targetPid" $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME $SLEEP_TIME $KEEP_LOGGING false true false
|
||||
conflictList "${INITIATOR[$__timestampCurrentFile]}" "${INITIATOR[$__timestempPreviousFile]}" &
|
||||
WaitForTaskCompletion $! $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME $SLEEP_TIME $KEEP_LOGGING false true false
|
||||
if [ $? -ne 0 ]; then
|
||||
IFS=';' read -r -a pidArray <<< "$(eval echo \"\$WAIT_FOR_TASK_COMPLETION_${FUNCNAME[0]}\")"
|
||||
initiatorFail=false
|
||||
targetFail=false
|
||||
for pid in "${pidArray[@]}"; do
|
||||
pid=${pid%:*}
|
||||
if [ "$pid" == "$initiatorPid" ]; then
|
||||
echo "${SYNC_ACTION[3]}" > "${INITIATOR[$__initiatorLastActionFile]}"
|
||||
initiatorFail=true
|
||||
elif [ "$pid" == "$targetPid" ]; then
|
||||
echo "${SYNC_ACTION[3]}" > "${INITIATOR[$__targetLastActionFile]}"
|
||||
targetFail=true
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $initiatorFail == false ]; then
|
||||
echo "${SYNC_ACTION[4]}" > "${INITIATOR[$__initiatorLastActionFile]}"
|
||||
fi
|
||||
|
||||
if [ $targetFail == false ]; then
|
||||
echo "${SYNC_ACTION[4]}" > "${INITIATOR[$__targetLastActionFile]}"
|
||||
fi
|
||||
|
||||
echo "${SYNC_ACTION[3]}" > "${INITIATOR[$__initiatorLastActionFile]}"
|
||||
echo "${SYNC_ACTION[3]}" > "${INITIATOR[$__targetLastActionFile]}"
|
||||
exit 1
|
||||
else
|
||||
echo "${SYNC_ACTION[4]}" > "${INITIATOR[$__initiatorLastActionFile]}"
|
||||
echo "${SYNC_ACTION[4]}" > "${INITIATOR[$__targetLastActionFile]}"
|
||||
resumeInitiator="${SYNC_ACTION[4]}"
|
||||
resumeTarget="${SYNC_ACTION[4]}"
|
||||
|
||||
fi
|
||||
else
|
||||
echo "${SYNC_ACTION[4]}" > "${INITIATOR[$__initiatorLastActionFile]}"
|
||||
|
@ -1854,8 +1831,8 @@ function Sync {
|
|||
|
||||
# Step 8 #WIP adapt to last function
|
||||
if [ "$resumeInitiator" == "${SYNC_ACTION[8]}" ] || [ "$resumeTarget" == "${SYNC_ACTION[8]}" ]; then
|
||||
if [[ "$RSYNC_ATTR_ARGS" == *"-X"* ]] || [[ "$RSYNC_ATTR_ARGS" == *"-A"* ]]; then
|
||||
renameTimestampFiles "${INITIATOR[$__replicaDir]}" "$TARGET_SYNC_DIR" &
|
||||
if [[ "$RSYNC_ATTR_ARGS" == *"-X"* ]] || [[ "$RSYNC_ATTR_ARGS" == *"-A"* ]] || [ "$LOG_CONFLICTS" == "yes" ]; then
|
||||
renameTimestampFiles "${INITIATOR[$__timestampCurrentFile]}" "${INITIATOR[$__timestampPreviousFile]}" &
|
||||
WaitForTaskCompletion $! $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME $SLEEP_TIME $KEEP_LOGGING false true false
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "${SYNC_ACTION[8]}" > "${INITIATOR[$__initiatorLastActionFile]}"
|
||||
|
|
Loading…
Reference in New Issue