diff --git a/scripts/auto-snapclean-listener.sh b/scripts/auto-snapclean-listener.sh index 36cf068..6f13e4d 100644 --- a/scripts/auto-snapclean-listener.sh +++ b/scripts/auto-snapclean-listener.sh @@ -1,10 +1,11 @@ #!/bin/zsh set -e -u -set -o pipefail +set -o pipefail # zsh: pipefail so wirklich aktiv LOGF="/var/log/snapclean.log" log() { print -r -- "$(date '+%F %T') $*" >> "$LOGF"; } +# minimaler PATH für launchd-Umgebung export PATH="/usr/bin:/bin:/usr/sbin:/sbin" is_running() { @@ -21,36 +22,39 @@ wait_until_tm_idle() { while is_running; do sleep 2 (( i++ )) - [[ $i -gt 150 ]] && log "Timeout: TM still running. Abort" && break + [[ $i -gt 150 ]] && log "Timeout: TM noch Running, breche Warten ab." && break done set -e + log "TM jetzt idle (oder Timeout erreicht)." return 0 } delete_all_snapshots() { - log "Snapshots before deletion (/):" + log "Snapshots vor Delete (/):" /usr/bin/tmutil listlocalsnapshots / >>"$LOGF" 2>&1 || log "listlocalsnapshots(/): none/error" - log "Delete all local snapshots at / …" + log "Lösche alle lokalen Snapshots auf / …" set +e /usr/bin/tmutil deletelocalsnapshots / >>"$LOGF" 2>&1 local rc=$? set -e - log "Deletion successfull. (rc=${rc})" + log "Fertig gelöscht. (rc=${rc})" } -# Make sure the logfile exists +# Sicherstellen, dass Logfile existiert (läuft als root – kein sudo nötig) [[ -f "$LOGF" ]] || { : > "$LOGF"; /bin/chmod 644 "$LOGF"; } +# KEINE Pipe → keine Subshell-Probleme while IFS= read -r line; do + # nur die konkrete Zeile matchen, die du gepostet hast if print -r -- "$line" | /usr/bin/grep -q \ "com.apple.TimeMachine:LocalSnapshotManagement] Created Time Machine local snapshot"; then log "Event erkannt: $line" - # Wait until Timemachine has finished + # Warten bis Time Machine fertig ist wait_until_tm_idle - # Wait a moment until the the snapshot is in index + # Ein Hauch warten, bis der Snapshot sicher im Index steht sleep 10 - # Delete all local snapshots + # Dann alle lokalen Snapshots löschen delete_all_snapshots fi done < <(