forked from Cloudxtreme/macscripts
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resetbackups.sh: Clearing apple time machine history
- Loading branch information
0 parents
commit 89c2546
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
|
||
# usage: "sudo ./resetbackups.sh" | ||
# deletes all time machine backups except the latest one, thus removing all history. | ||
# the time machine storage must be mounted when the script runs. | ||
|
||
[[ $EUID -ne 0 ]] && { echo "Error: Must run as root."; exit 1; } | ||
|
||
computername="$(scutil --get ComputerName)" | ||
cd "/Volumes/Time Machine Backups/Backups.backupdb/${computername}" | ||
[ $? -ne 0 ] && { echo "Error: Unable to access Time Machine backup storage."; exit 1; } | ||
|
||
ls | ||
|
||
files=($(ls)) | ||
|
||
if [ ${#files[@]} -le 2 ]; then | ||
echo "Only one backup, skipping..." | ||
exit | ||
fi | ||
|
||
MAX=${#files[@]} | ||
(( MAX = MAX - 2 )) | ||
START=0 | ||
echo "* Backups to delete: $MAX" | ||
while :; do | ||
(( NONZEROSTART = START + 1 )) | ||
echo ". ${NONZEROSTART}/${MAX}: ${files[$START]}" | ||
tmutil delete "${files[$START]}" | ||
if [ $? -ne 0 ]; then | ||
# error happened, or user pressed Ctrl+C | ||
echo "Aborting..." | ||
break | ||
fi | ||
|
||
(( START = START + 1 )) | ||
if [ $START -ge $MAX ]; then | ||
break | ||
fi | ||
done |