diff --git a/scripts/agathe_backup.sh b/scripts/agathe_backup.sh index 9fe483d..0b720d4 100755 --- a/scripts/agathe_backup.sh +++ b/scripts/agathe_backup.sh @@ -139,7 +139,7 @@ cleanup() { set +e log "== Cleanup ==" - if mountpoint -q "$CIFS_MOUNTPOINT"; then + if is_cifs_mounted; then log "Unmount: $CIFS_MOUNTPOINT" umount "$CIFS_MOUNTPOINT" 2>/dev/null || umount -l "$CIFS_MOUNTPOINT" || true else @@ -218,10 +218,14 @@ _mount_cifs_with_opts() { fi } +is_cifs_mounted() { + awk -v mp="$CIFS_MOUNTPOINT" '$2 == mp && $3 == "cifs" { found=1 } END { exit(found ? 0 : 1) }' /proc/mounts +} + mount_cifs() { log "== CIFS mount: $CIFS_SHARE -> $CIFS_MOUNTPOINT ==" - if mountpoint -q "$CIFS_MOUNTPOINT"; then + if is_cifs_mounted; then log "Mountpoint ist gemountet -> versuche umount" umount "$CIFS_MOUNTPOINT" 2>/dev/null || umount -l "$CIFS_MOUNTPOINT" || true fi @@ -241,34 +245,49 @@ mount_cifs() { _mount_cifs_with_opts "$opts_robust" local rc=$? set -e - if [[ $rc -eq 0 ]]; then + if [[ $rc -eq 0 ]] && is_cifs_mounted; then log "OK gemountet (robust)." return 0 fi + if [[ $rc -eq 0 ]]; then + log "WARNUNG: mount meldet Erfolg, aber CIFS ist nicht stabil eingehängt." + fi log "WARNUNG: CIFS mount (robust) fehlgeschlagen (rc=$rc). Fallback auf Basis-Optionen." set +e _mount_cifs_with_opts "$opts_base" rc=$? set -e - if [[ $rc -eq 0 ]]; then + if [[ $rc -eq 0 ]] && is_cifs_mounted; then log "OK gemountet (base)." return 0 fi + if [[ $rc -eq 0 ]]; then + log "WARNUNG: mount (base) meldet Erfolg, aber CIFS ist nicht stabil eingehängt." + fi log "FEHLER: CIFS mount fehlgeschlagen (rc=$rc)." exit 1 } ensure_cifs() { - if ! mountpoint -q "$CIFS_MOUNTPOINT"; then - log "WARNUNG: CIFS nicht gemountet -> remount" + local attempt + for ((attempt=1; attempt<=3; attempt++)); do + if is_cifs_mounted; then + return 0 + fi + + log "WARNUNG: CIFS nicht gemountet -> remount (Versuch ${attempt}/3)" mount_cifs - fi - if ! mountpoint -q "$CIFS_MOUNTPOINT"; then - log "FEHLER: CIFS Remount fehlgeschlagen." - exit 1 - fi + sleep 1 + + if is_cifs_mounted; then + return 0 + fi + done + + log "FEHLER: CIFS Remount fehlgeschlagen." + exit 1 } run_rsync_with_cifs_retry() { @@ -292,7 +311,7 @@ run_rsync_with_cifs_retry() { if [[ "$rc" -eq 11 || "$rc" -eq 12 || "$rc" -eq 30 || "$rc" -eq 35 ]]; then if [[ "$attempt" -lt "$TOMEDO_RSYNC_MAX_RETRIES" ]]; then log "WARNUNG: rsync ${label} fehlgeschlagen (rc=$rc). Remount und Retry in ${TOMEDO_RSYNC_RETRY_SLEEP}s." - if mountpoint -q "$CIFS_MOUNTPOINT"; then + if is_cifs_mounted; then umount "$CIFS_MOUNTPOINT" 2>/dev/null || umount -l "$CIFS_MOUNTPOINT" || true fi sleep "$TOMEDO_RSYNC_RETRY_SLEEP"