-
Notifications
You must be signed in to change notification settings - Fork 2
/
Timeshift_Backup_Manager.sh
executable file
·194 lines (168 loc) · 4.3 KB
/
Timeshift_Backup_Manager.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/bash
# Timeshift Backup Manager
warning='\033[0;31m' #Red
reset='\033[0m' #No Color
sucess='\033[0;32m' #Green
#info='\033[0;33m' #Yellow
timeshift_installed_check() {
if ! command -v timeshift &> /dev/null
then
echo -e "${warning}Timeshift is not installed please install it first.${reset}"
exit 1
fi
}
sudo_check() {
if [ "$EUID" -ne 0 ]
then
#Timeshift needs to be run as root
echo -e "${warning}Please run this as root${reset}"
exit 1
fi
}
create_backup() {
backup_type=$1
timeshift_installed_check
case $backup_type in
"manual")
timeshift --create --comments "Manual Backup created by Timeshift Backup Manager"
;;
"daily")
timeshift --create --comments "Daily Backup created by Timeshift Backup Manager" --tags "D"
;;
"weekly")
timeshift --create --comments "Weekly Backup created by Timeshift Backup Manager" --tags "W"
;;
"monthly")
timeshift --create --comments "Monthly Backup created by Timeshift Backup Manager" --tags "M"
;;
*)
echo "Invalid backup type"
backup_menu
#exit 1
;;
esac
main_menu #Return to main menu
}
delete_backup() {
timeshift_installed_check
deletion_type=$1
case $deletion_type in
"manual")
timeshift --delete #Only nuke a little bit
;;
"all")
timeshift --delete-all #Nuke it from orbit it's the only way to be sure
;;
*)
echo -e "${warning}Invalid option ${reset}"
exit 1
;;
esac
}
get_backup_list() {
timeshift_installed_check
timeshift --list
read -p "Press enter to contine"
}
restore_backup() {
timeshift_installed_check
timeshift --restore
}
main_menu(){
echo "------------------------------------"
echo -e "${sucess}Timeshift Backup Manager${reset}"
echo "1. Create a backup"
echo "2. List Backups"
echo "3. Delete Backups"
echo "4. Restore a Backup"
echo -e "${warning}5. Exit${reset}"
read -p "Enter your choice: " choice
echo "------------------------------------"
case $choice in
1)
backup_menu
;;
2)
get_backup_list
;;
3)
deletion_menu
;;
4)
restore_backup
;;
5)
exit 0
;;
*)
echo -e "${warning}Invalid option${reset}"
main_menu
;;
esac
main_menu
}
backup_menu(){
echo "------------------------------------"
echo "1. Create a Daily Backup"
echo "2. Create a Weekly Backup"
echo "3. Create a Monthly Backup"
echo "4. Create a Manual Backup"
echo "5. Return to main menu"
read -p "Enter your choice: " choice
echo "------------------------------------"
case $choice in
1)
create_backup "daily"
;;
2)
create_backup "weekly"
;;
3)
create_backup "monthly"
;;
4)
create_backup "manual"
;;
5)
main_menu
;;
*)
echo -e "${warning}Invalid option${reset}"
backup_menu
;;
esac
}
deletion_menu(){
echo "------------------------------------"
echo "1. Delete a Backup"
echo "2. Delete all Backups"
echo "3. Return to main menu"
read -p "Enter your choice: " choice
echo "------------------------------------"
case $choice in
1)
delete_backup "manual"
;;
2)
read -p "Are you sure ? this is the point of no return [y/N]: " response #Nuke confirmation
case $response in
[yY][eE][sS]|[yY])
delete_backup "all"
;;
*)
main_menu
;;
esac
;;
3)
main_menu
;;
*)
echo -e "${warning}Invalid option${reset}"
deletion_menu
;;
esac
}
timeshift_installed_check
sudo_check
main_menu