add probing before copy
This commit is contained in:
1 parent
6fe87107ce
commit
3e1c561559
1 file changed
+40
-2
@@ -113,6 +113,37 @@ fi
|
||||
# Kopieren der SMB-Freigaben
|
||||
# **************************************************
|
||||
EXIT_CODE=0
|
||||
PROBE_TIMEOUT="${PROBE_TIMEOUT:-20}"
|
||||
RSYNC_TIMEOUT="${RSYNC_TIMEOUT:-60}"
|
||||
|
||||
# Fuehrt einen Befehl mit Zeitlimit (Sekunden) aus; macOS hat kein timeout.
|
||||
# Ein haengender Prozess (z.B. ls auf toter SMB-Verbindung) wird nicht
|
||||
# abgewartet, sondern abgeschossen und zurueckgelassen.
|
||||
run_with_timeout() {
|
||||
local secs="$1" pid ticks=0
|
||||
shift
|
||||
"$@" >/dev/null 2>&1 &
|
||||
pid=$!
|
||||
while kill -0 "$pid" 2>/dev/null; do
|
||||
if [ "$ticks" -ge $((secs * 10)) ]; then
|
||||
kill -9 "$pid" 2>/dev/null
|
||||
return 124
|
||||
fi
|
||||
sleep 0.1
|
||||
ticks=$((ticks + 1))
|
||||
done
|
||||
wait "$pid"
|
||||
}
|
||||
|
||||
# Prueft, ob die Freigabe wirklich gemountet ist, Verzeichnisse listbar sind
|
||||
# und sich Dateiinhalt lesen laesst (Listing allein kann aus dem Cache kommen).
|
||||
probe_source() {
|
||||
local dir="$1" file
|
||||
mount | grep -q " on $dir (smbfs" || return 1
|
||||
ls -A "$dir" >/dev/null || return 1
|
||||
file="$(find "$dir" -maxdepth 3 -type f ! -name '.*' -print -quit)" || return 1
|
||||
[ -z "$file" ] || head -c 1 "$file" >/dev/null || return 1
|
||||
}
|
||||
|
||||
run_rsync() {
|
||||
local share="$1"
|
||||
@@ -138,11 +169,18 @@ run_rsync() {
|
||||
return
|
||||
fi
|
||||
|
||||
log "Pruefe Lesbarkeit von $source (Timeout ${PROBE_TIMEOUT}s)"
|
||||
if ! run_with_timeout "$PROBE_TIMEOUT" probe_source "$source"; then
|
||||
log "WARNUNG: $source nicht lesbar (haengt oder Fehler), ueberspringe $share. Freigabe im Finder trennen und neu verbinden."
|
||||
EXIT_CODE=1
|
||||
return
|
||||
fi
|
||||
|
||||
log "Sichere $share"
|
||||
# -r Unterverzeichnisse inkl. leerer, -l Symlinks, -t Zeitstempel (wie /COPY:DAT),
|
||||
# --partial setzt abgebrochene Uebertragungen fort (wie /z). Kein --delete:
|
||||
# robocopy /E spiegelt ebenfalls nicht.
|
||||
rsync -rlt -h -v --progress --partial --stats --exclude=".DS_Store" --exclude="._.DS_Store" "$source/" "$MOUNT_POINT/$share/"
|
||||
# robocopy /E spiegelt ebenfalls nicht. --timeout bricht bei SMB-Haengern ab.
|
||||
rsync -rlt -h -v --progress --partial --stats --timeout="$RSYNC_TIMEOUT" --exclude=".DS_Store" --exclude="._.DS_Store" "$source/" "$MOUNT_POINT/$share/"
|
||||
local rc=$?
|
||||
if [ "$rc" -ne 0 ]; then
|
||||
log "WARNUNG: rsync fuer $share endete mit Code $rc"
|
||||
|
||||
Reference in new issue
Block a user