Created
June 21, 2020 00:58
-
-
Save appler1009/adf230249d1f1e983986b95756d37a77 to your computer and use it in GitHub Desktop.
Cleanup oldest Time Machine backup
This file contains hidden or 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/sh | |
| COMPUTER_NAME=$(/usr/sbin/scutil --get ComputerName) | |
| NBACKUPS=$(/usr/bin/tmutil listbackups | | |
| /usr/bin/grep "$COMPUTER_NAME" | | |
| /usr/bin/wc -l) | |
| OLDEST_BACKUP=$(/usr/bin/tmutil listbackups | | |
| /usr/bin/grep "$COMPUTER_NAME" | | |
| /usr/bin/head -n1) | |
| LATEST_BACKUP=$(/usr/bin/tmutil latestbackup) | |
| echo Latest backup: $LATEST_BACKUP | |
| if [[ -n "$LATEST_BACKUP" && "$LATEST_BACKUP" != "$OLDEST_BACKUP" ]] | |
| then | |
| echo -n "$NBACKUPS backups. Delete oldest: ${OLDEST_BACKUP##*/} [y/N]? " | |
| read answer | |
| case $answer in | |
| y*) | |
| echo Running: /usr/bin/sudo /usr/bin/tmutil delete "$OLDEST_BACKUP" | |
| /usr/bin/sudo time /usr/bin/tmutil delete "$OLDEST_BACKUP" | |
| ;; | |
| *) | |
| echo No change | |
| ;; | |
| esac | |
| else | |
| echo "No backup available for deletion" | |
| fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment