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