Compare commits
No commits in common. "main" and "macOS-snapcleaner_1.0.1" have entirely different histories.
main
...
macOS-snap
2 changed files with 12 additions and 28 deletions
BIN
.DS_Store
vendored
BIN
.DS_Store
vendored
Binary file not shown.
|
|
@ -1,56 +1,40 @@
|
||||||
#!/bin/zsh
|
#!/bin/zsh
|
||||||
set -e -u
|
set -euo pipefail
|
||||||
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"; }
|
||||||
|
|
||||||
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
|
||||||
|
|
||||||
is_running() {
|
is_running() {
|
||||||
if /usr/bin/tmutil status 2>/dev/null | /usr/bin/grep -Eq '"Running" = 1|Running = 1'; then
|
/usr/bin/tmutil status 2>/dev/null | /usr/bin/grep -Eq '"Running" = 1|Running = 1'
|
||||||
return 0 # running
|
|
||||||
else
|
|
||||||
return 1 # idle
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_until_tm_idle() {
|
wait_until_tm_idle() {
|
||||||
set +e
|
|
||||||
local i=0
|
local i=0
|
||||||
while is_running; do
|
while is_running; do
|
||||||
sleep 2
|
sleep 2
|
||||||
(( i++ ))
|
(( i++ ))
|
||||||
[[ $i -gt 150 ]] && log "Timeout: TM still running. Abort" && break
|
[[ $i -gt 150 ]] && log "Timeout: TM still running. Waiting until it's finished." && break
|
||||||
done
|
done
|
||||||
set -e
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_all_snapshots() {
|
delete_all_snapshots() {
|
||||||
log "Snapshots before deletion (/):"
|
log "Deletes all local Snapshots at / …"
|
||||||
/usr/bin/tmutil listlocalsnapshots / >>"$LOGF" 2>&1 || log "listlocalsnapshots(/): none/error"
|
/usr/bin/tmutil deletelocalsnapshots / || true
|
||||||
|
log "Finished deleting."
|
||||||
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 the logfile exists
|
# Make sure logfile exists
|
||||||
[[ -f "$LOGF" ]] || { : > "$LOGF"; /bin/chmod 644 "$LOGF"; }
|
[[ -f "$LOGF" ]] || { sudo touch "$LOGF"; sudo chmod 644 "$LOGF"; }
|
||||||
|
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
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"
|
||||||
# Wait until Timemachine has finished
|
# Short break until the snapshot is in index
|
||||||
|
sleep 2
|
||||||
|
# Waiting until TM is finished
|
||||||
wait_until_tm_idle
|
wait_until_tm_idle
|
||||||
# Wait a moment until the the snapshot is in index
|
# delete all local snapshots
|
||||||
sleep 10
|
|
||||||
# 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