Compare commits

...

2 commits

Author SHA1 Message Date
65789f5328 correctes comments 2025-09-27 17:32:23 +02:00
ae7a71574a Bugfixes 2025-09-27 17:26:05 +02:00
2 changed files with 28 additions and 12 deletions

BIN
.DS_Store vendored

Binary file not shown.

View file

@ -1,40 +1,56 @@
#!/bin/zsh
set -euo pipefail
set -e -u
set -o pipefail
LOGF="/var/log/snapclean.log"
log() { print -r -- "$(date '+%F %T') $*" >> "$LOGF"; }
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
is_running() {
/usr/bin/tmutil status 2>/dev/null | /usr/bin/grep -Eq '"Running" = 1|Running = 1'
if /usr/bin/tmutil status 2>/dev/null | /usr/bin/grep -Eq '"Running" = 1|Running = 1'; then
return 0 # running
else
return 1 # idle
fi
}
wait_until_tm_idle() {
set +e
local i=0
while is_running; do
sleep 2
(( i++ ))
[[ $i -gt 150 ]] && log "Timeout: TM still running. Waiting until it's finished." && break
[[ $i -gt 150 ]] && log "Timeout: TM still running. Abort" && break
done
set -e
return 0
}
delete_all_snapshots() {
log "Deletes all local Snapshots at / …"
/usr/bin/tmutil deletelocalsnapshots / || true
log "Finished deleting."
log "Snapshots before deletion (/):"
/usr/bin/tmutil listlocalsnapshots / >>"$LOGF" 2>&1 || log "listlocalsnapshots(/): none/error"
log "Delete all local snapshots at / …"
set +e
/usr/bin/tmutil deletelocalsnapshots / >>"$LOGF" 2>&1
local rc=$?
set -e
log "Deletion successfull. (rc=${rc})"
}
# Make sure logfile exists
[[ -f "$LOGF" ]] || { sudo touch "$LOGF"; sudo chmod 644 "$LOGF"; }
# Make sure the logfile exists
[[ -f "$LOGF" ]] || { : > "$LOGF"; /bin/chmod 644 "$LOGF"; }
while IFS= read -r line; do
if print -r -- "$line" | /usr/bin/grep -q \
"com.apple.TimeMachine:LocalSnapshotManagement] Created Time Machine local snapshot"; then
log "Event erkannt: $line"
# Short break until the snapshot is in index
sleep 2
# Waiting until TM is finished
# Wait until Timemachine has finished
wait_until_tm_idle
# delete all local snapshots
# Wait a moment until the the snapshot is in index
sleep 10
# Delete all local snapshots
delete_all_snapshots
fi
done < <(