forked from urmilshroff/backup_deleter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup_deleter.sh
75 lines (65 loc) · 2.26 KB
/
backup_deleter.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
echo -e "\nThis is a script to manage local Time Machine backups that get created automatically on macOS High Sierra or above. Please use with caution and only on a Macintosh computer running macOS 10.13 or higher."
echo -e "\n***I AM NOT RESPONSIBLE FOR ANY DAMAGE(S) THIS MAY CAUSE TO YOU OR YOUR LIFE.***"
while true
do
backup=$(tmutil listlocalsnapshots / | head -1) #stores oldest backup name
echo -e "\nWhat would you like to do?\n1. Display all backups\n2. Delete oldest backup\n3. Delete all backups\n4. Check storage status\n5. Exit"
read choice
case $choice in
1) #displays all backups
if [ -z "$backup" ] #if no backup exists
then
echo -e "\nNo backups to display!"
break
else
echo -e "\nAll local backups are"
tmutil listlocalsnapshots /
fi
;;
2) #deletes oldest backup
if [ -z "$backup" ]
then
echo -e "\nNo backups to delete!"
break
else
backup=$(tmutil listlocalsnapshots / | head -1)
backup_date=${backup#"com.apple.TimeMachine."} #stores only date of backup
echo -e "\nDeleting com.apple.TimeMachine.$backup_date..."
tmutil deletelocalsnapshots $backup_date
fi
;;
3) #deletes all backups
if [ -z "$backup" ]
then
echo -e "\nNo backups to delete!"
break
else
while true #keeps looping to delete all remaining backups
do
backup=$(tmutil listlocalsnapshots / | head -1)
if [ -z "$backup" ]
then
echo -e "\nAll backups deleted!"
break
else
backup_date=${backup#"com.apple.TimeMachine."}
echo -e "\nDeleting com.apple.TimeMachine.$backup_date..."
tmutil deletelocalsnapshots $backup_date
fi
done
fi
break
;;
4)
echo -e "\nCurrent storage status is"
df -h /
;;
5)
break
;;
*)
echo -e "\nInvalid choice, try again!"
;;
esac
done