Просмотр исходного кода

Better protection against all the new kinds of fault

Zachary Kotlarek 12 лет назад
Родитель
Сommit
6f17f18d0e
2 измененных файлов с 26 добавлено и 13 удалено
  1. 11 2
      backup/checkMount.sh
  2. 15 11
      backup/sync.sh

+ 11 - 2
backup/checkMount.sh

@@ -9,11 +9,16 @@ fi
 if [ -z "${BASE_REMOTE}" ]; then
 	BASE_REMOTE="`"${VIDEO_DIR}/backup/remoteDir.sh"`"
 fi
-WC="${BASE_REMOTE}/.live_check"
 
 # State
 FAILED=0
 
+# Command-line options
+WC="${BASE_REMOTE}/.live_check"
+if [ -n "${1}" ]; then
+	WC="${BASE_REMOTE}/${1}/.write_check"
+fi
+
 # Stat check
 if [ $FAILED -lt 1 ]; then
 	if ! timeout "${TIMEOUT}" ls "${BASE_REMOTE}" >/dev/null 2>&1; then
@@ -61,9 +66,13 @@ if [ $FAILED -gt 0 ]; then
 			${SUDO} kill -9 $PID
 		fi
 
+		if [ "`mount | awk '$3 == "'"${BASE_REMOTE}"'" { print $3 }'`" == "${BASE_REMOTE}" ]; then
+			${SUDO} umount "${BASE_REMOTE}"
+		fi
+
 		DASH_NAME="`echo "${BASE_REMOTE}" | cut -d '/' -f 2- | sed 's%/%-%g'`"
-		${SUDO} umount "${BASE_REMOTE}"
 		${SUDO} rm -f "/var/run/mount.davfs/${DASH_NAME}.pid"
+
 		${SUDO} mount "${BASE_REMOTE}"
 	fi
 

+ 15 - 11
backup/sync.sh

@@ -52,21 +52,16 @@ if [ ! -d "${BASE_REMOTE}" ]; then
 fi
 
 # Ensure we can actually write to the remote drive
-WC="${BASE_REMOTE}/.write_check"
-timeout "${TIMEOUT}" touch "${WC}" >/dev/null 2>&1
-if [ ! -e "${WC}" ]; then
-	echo "Remote drive not writable" 1>&2
-	exit 1
-fi
-timeout "${TIMEOUT}" rm -f "${WC}" >/dev/null 2>&1
-if [ -e "${WC}" ]; then
-	echo "Remote drive not writable" 1>&2
+if ! "${VIDEO_DIR}/backup/checkMount.sh"; then
 	exit 1
 fi
 
 # Create the named subdirectory if it does not exist on the remote drive
 if [ ! -d "${BASE_REMOTE}/${SUB_DIR}" ]; then
-	timeout "${TIMEOUT}" mkdir -p "${BASE_REMOTE}/${SUB_DIR}"
+	timeout "${TIMEOUT}" mkdir -p "${BASE_REMOTE}/${SUB_DIR}" >/dev/null 2>&1
+	"${VIDEO_DIR}/backup/checkMount.sh" > /dev/null 2>&1 &
+	echo "Remote drive not in-sync" 1>&2
+	exit 1
 fi
 
 # Grab and sort the local file list
@@ -79,7 +74,16 @@ cat "${TMP_LOCAL2}" | sort > "${TMP_LOCAL}"
 
 # Grab and sort the remote file list
 TMP_REMOTE="`mktemp -t sync.remote.XXXXXXXX`"
-(timeout "${TIMEOUT}" cd "${BASE_REMOTE}" && timeout "$(( $TIMEOUT * 10 ))" find "${SUB_DIR}" | sort > "${TMP_REMOTE}")
+timeout $(( $TIMEOUT * 10 )) bash -c "
+	cd \"${BASE_REMOTE}\" && \
+	find \"${SUB_DIR}\" | \
+	sort > \"${TMP_REMOTE}\" \
+" 2>/dev/null
+if [ ! -s "${TMP_REMOTE}" ]; then
+	"${VIDEO_DIR}/backup/checkMount.sh" "${SUB_DIR}" > /dev/null 2>&1 &
+	echo "Remote drive not readable" 1>&2
+	exit 1
+fi
 
 # Diff to find the first mis-matched file, then drop out temp files
 TMP_DIFF="`mktemp -t sync.diff.XXXXXXXX`"