Last active
December 29, 2020 11:13
-
-
Save ts1/a85fc151c8c9a48a5427958e956b5007 to your computer and use it in GitHub Desktop.
Time Machine cleaner - remove backups not listed in `tmutil listbackups`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eo pipefail | |
DIR=$(tmutil machinedirectory) | |
backups=$(tmutil listbackups) | |
ls "$DIR" | while read subdir; do | |
if echo $subdir | grep -q '[^0-9-]'; then continue; fi | |
if echo $backups | grep -q $subdir; then continue; fi | |
dir="$DIR/$subdir" | |
if [ "$1" = -n ]; then | |
echo "$dir" | |
else | |
tmutil delete "$dir" | |
fi | |
done |
This doesn't work with APFS backup introduced in Big Sur.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run this in
cron
, give Full Disk Access permission to/usr/sbin/cron
in Security and Privacy.