-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackupscript.sh
More file actions
519 lines (488 loc) · 14.1 KB
/
backupscript.sh
File metadata and controls
519 lines (488 loc) · 14.1 KB
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
#!/bin/bash
# Init
#
# BSD 2-Clause License
#
# Copyright (c) 2019, Fabian Schmeltzer
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
function jumpto() {
label=$1
cmd=$(sed -n "/$label:/{:a;n;p;ba};" $0 | grep -v ':$')
eval "$cmd"
exit
}
menue=${1:-"menue"}
update=${2:-"update"}
settings=${3:-"settings"}
backup=${4:-"backup"}
restore=${5:-"restore"}
# root check
FILE="/tmp/out.$$"
GREP="/bin/grep"
if [ "$(id -u)" != "0" ]; then
echo "Das Script muss als root gestartet werden." 1>&2
exit 1
fi
# farbcodes
red=($(tput setaf 1))
green=($(tput setaf 2))
yellow=($(tput setaf 3))
reset=($(tput sgr0))
#menü
clear
if [[ -d "files" ]]; then
jumpto update
elif [[ * ]]; then
apt-get update
clear
apt-get upgrade -y
clear
apt-get install curl -y
clear
apt-get install zip -y
clear
apt-get install unzip -y
clear
apt-get install tar -y
clear
jumpto update
fi
# ███ ███ ███████ ███ ██ ██ ██
# ████ ████ ██ ████ ██ ██ ██
# ██ ████ ██ █████ ██ ██ ██ ██ ██
# ██ ██ ██ ██ ██ ██ ██ ██ ██
# ██ ██ ███████ ██ ████ ██████
menue:
mkdir files
mkdir files/backup
touch files/backup/name
touch files/backup/list
touch files/backup/to
clear
echo "
██████ █████ ██████ ██ ██ ██ ██ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██████ ███████ ██ █████ ██ ██ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██████ ██ ██ ██████ ██ ██ ██████ ██
"
set -u
clear
echo "$yellow########################################"
read -t 0.1
echo "###### BackUp Script by Mobulos ######"
read -t 0.1
echo "########################################"
read -t 0.1
# echo "ACHTUNG| Alpha Update |ACHTUNG"
echo
echo "Version 2.3.1"
echo "Update 29.2.2020" #TODO Version und Datum ändern
echo "$reset"
echo
read -t 0.1
echo "Auswahlmöglichkeiten"
read -t 0.1
tmp=($(tput setaf 3))
echo -n "$tmp"
echo "[1] Backup erstellen"
read -t 0.1
tmp=($(tput setaf 3))
echo -n "$tmp"
echo "[2] Backup wiederherstellen"
read -t 0.1
tmp=($(tput setaf 1))
echo -n "$tmp"
echo "[3] Backup löschen"
read -t 0.1
tmp=($(tput setaf 2))
echo -n "$tmp"
echo "[4] Liste der Backups"
read -t 0.1
tmp=($(tput setaf 6))
echo -n "$tmp"
echo "[5] Script Updaten"
read -t 0.1
tmp=($(tput setaf 5))
echo -n "$tmp"
echo "[6] Enstellungen Ändern"
read -t 0.1
tmp=($(tput setaf 4))
echo -n "$tmp"
echo "[7] Exit"
echo "$reset"
read -t 0.1
read -n1 -p "Was willst du tun?: " befehl
clear
case $befehl in
1)
jumpto backup
exit
;;
# 2)
# jumpto backupink
# exit
# ;;
2)
jumpto restore
exit
;;
3)
jumpto delete
exit
;;
4)
jumpto list
exit
;;
5)
rm 20*
clear
jumpto update
exit
;;
6)
jumpto settings
;;
7)
clear
exit
;;
*)
echo "Dieser Befehl existiert nicht!"
read -t 3 -n 1
jumpto menue
exit
;;
esac
# ██ ██ ███████ ████████
# ██ ██ ██ ██
# ██ ██ ███████ ██
# ██ ██ ██ ██
# ███████ ██ ███████ ██
list:
clear
echo "Follgende Backups wurden erstellt: "
paste files/backup/name files/backup/list >temp
cat -n temp
rm temp
read -n1
jumpto menue
exit
# ██████ █████ ██████ ██ ██ ██ ██ ██████
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
# ██████ ███████ ██ █████ ██ ██ ██████
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
# ██████ ██ ██ ██████ ██ ██ ██████ ██
backup:
clear
echo "Folgende Backups exsistieren: "
paste files/backup/name files/backup/list >temp
cat -n temp
rm temp
echo
echo
bck=""
bckto=""
nam=""
read -e -p "Von welchem Ordner soll ein Backup erstellt werden? " bck
if [ -d "$bck" ]; then
echo
elif [[ * ]]; then
echo "Dieser Ordner existiert nicht!"
jumpto backup
fi
clear
echo "Wo soll das Backup gespeichert werden?"
echo
echo 'Bitte im folgenden Format angeben: "/pfad/zum/ordner/" '
echo
read -e -p 'Standardmäßig lautet der Pfad: "/root/backup/" ' bckto
if [ -z "$bckto" ]; then
bckto="/root/backup/"
mkdir -p "$bckto"
clear
elif [[ * ]]; then
echo
fi
clear
if [ -d "$bckto" ]; then
echo
elif [[ * ]]; then
for i in . .. ...; do
clear
echo "Dieser Ordner existiert nicht!"
echo "Daher wird er nun erstellt $i"
read -t 1
done
mkdir -p "$bckto"
fi
clear
read -p "Gebe ein Namen für das Backup an: " nam
clear
echo "$nam" >>files/backup/name
echo "$bck" >>files/backup/list
echo "$bckto" >>files/backup/to
tar -cpz $bck | (pv -n >$bckto$nam.tgz) 2>&1 | dialog --gauge "Wallie erstellt ein Backup, ich wusste garnicht, dass das möglich ist......" 10 70 0
# rsync -a --delete $bck $bckto/$nam
clear
echo "Das Backup wurde erstellt!"
read -n1
exit
# ██████ ███████ ███████ ████████ ██████ ██████ ███████
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
# ██████ █████ ███████ ██ ██ ██ ██████ █████
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
# ██ ██ ███████ ███████ ██ ██████ ██ ██ ███████
restore:
clear
echo "Welche der folgenden Backups möchtest du wiederherstellen?"
echo
paste files/backup/name files/backup/list >temp
cat -n temp
rm temp
echo
read -p 'Bitte gebe die Zahl des Backups ein: ' resup
resto=$(sed -ne "$resup"'p' files/backup/to)
reslist=$(sed -ne "$resup"'p' files/backup/list)
resname=$(sed -ne "$resup"'p' files/backup/name)
echo -n "$red"
echo "ACHTUNG: IN EINIGEN FÄLLEN WAR DAS ERSTELLEN DES BACKUPS FEHLERHAFT!"
echo " üBERPRÜFE UNBEDING, OB DAS BACKUP ERFOLGREICH WAR(Die .tar Datei öffnen und auf vollständigkeit überprüfen)"
echo "$reset"
read -n1 -p 'WARNUNG: Das Zielverzeichnis wird überschrieben !!! (Y/N): ' warn
case $warn in
Y | y | J | j)
(tar -xzf $resto$resname.tgz -C /) | dialog --gauge "Wallie stell das Backup wiederher, das ist echt unglaublich......" 10 70 0
clear
echo "Das Backup wurde wiederhergestellt!"
read -t 5 -n 1
clear
jumpto menue
;;
N | n)
echo -n "$red"
echo "Es tut mir leid, doch ich darf das Backup nicht wiederherstellen, wenn Du mich das Zielverzeichnis nicht überschreiben lässt!"
echo -n "$reset"
read -n1
jumpto menue
exit
;;
esac
# ██████ ███████ ██ ███████ ████████ ███████
# ██ ██ ██ ██ ██ ██ ██
# ██ ██ █████ ██ █████ ██ █████
# ██ ██ ██ ██ ██ ██ ██
# ██████ ███████ ███████ ███████ ██ ███████
delete:
clear
echo "Welche der folgenden Backups möchtest du löschen?"
echo
paste files/backup/name files/backup/list >temp
cat -n temp
rm temp
echo
read -n1 -p "Bitte gebe die Zahl des Backups ein: " delup
delto=$(sed -ne "$delup"'p' files/backup/to)
delname=$(sed -ne "$delup"'p' files/backup/name)
clear
read -n1 -p "Soll Backup-Datei '$delto$delname.tgz' ebenfalls gelöscht werden?! (Y/N) [Empfohlen: (Y)] " delyn
case $delyn in
Y | y | J | j)
rm -r $delto$delname.tgz
sed -i "$delup D" "files/backup/list"
sed -i "$delup D" "files/backup/name"
sed -i "$delup D" "files/backup/to"
;;
*)
echo -n "$red"
echo "Der Ordner wurde nicht gelöscht, du musst dies ggf. selber Löschen!"
echo -n "$reset"
read -t 5 -n 1
;;
esac
clear
echo "Das Backup wurde gelöscht!"
read -t 3 -n 1
jumpto menue
exit
# ██ ██ ██████ ██████ █████ ████████ ███████
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
# ██ ██ ██████ ██ ██ ███████ ██ █████
# ██ ██ ██ ██ ██ ██ ██ ██ ██
# ██████ ██ ██████ ██ ██ ██ ███████
update:
if [ -f $(date +%Y-%m-%d) ]; then
jumpto menue
elif [[ * ]]; then
clear
fi
read -t 2 -n 1
rm 20*
touch $(date +%Y-%m-%d)
clear
echo "$red Die neuste Version wird heruntergeladen"
echo "$reset"
rm backupscript.sh
if [ -f ".alpha" ]; then
echo "$red"
curl --progress-bar https://raw.githubusercontent.com/Mobulos/backup/alpha/backupscript.sh --output backupscript.sh
echo "$reset"
read -t 1
chmod +x backupscript.sh
./backupscript.sh
exit
elif [[ * ]]; then
echo "$red"
curl --progress-bar https://raw.githubusercontent.com/Mobulos/backup/master/backupscript.sh --output backupscript.sh
echo "$reset"
read -t 1
chmod +x backupscript.sh
./backupscript.sh
exit
fi
# ███████ ███████ ████████ ████████ ██ ███ ██ ██████ ███████
# ██ ██ ██ ██ ██ ████ ██ ██ ██
# ███████ █████ ██ ██ ██ ██ ██ ██ ██ ███ ███████
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
# ███████ ███████ ██ ██ ██ ██ ████ ██████ ███████
settings:
dir=$(cd $(dirname 0) && pwd)
rm files/dir
touch files/dir
clear
tmp=($(tput setaf 1))
echo -n "$tmp"
echo "######## #### ## ## ###### ######## ######## ## ## ## ## ## ## ###### ######## ## ##"
tmp=($(tput setaf 2))
echo -n "$tmp"
read -t 0.1
echo "## ## ### ## ## ## ## ## ## ## ## ## ### ## ## ## ## ### ##"
tmp=($(tput setaf 3))
echo -n "$tmp"
read -t 0.1
tmp=($(tput setaf 4))
echo -n "$tmp"
read -t 0.1
echo "###### ## ## ## ## ###### ## ###### ## ## ## ## ## ## ## ## #### ###### ## ## ##"
tmp=($(tput setaf 5))
echo -n "$tmp"
read -t 0.1
echo "## ## ## ### ## ## ## ## ## ## ## ## ## ### ## ## ## ## ###"
tmp=($(tput setaf 6))
echo -n "$tmp"
read -t 0.1
echo "## ## ## ## ## ## ## ## ## ## ## ## ## #### ## ## ## ## ####"
tmp=($(tput setaf 8))
echo -n "$tmp"
read -t 0.1
echo "######## #### ## ## ##### ## ######## ######## ######## ####### ## ## ###### ######## ## ##"
echo
echo
echo "$green"
read -t 0.1
echo "Follgende Einstellungen können geändert werden:"
read -t 0.1
echo "[1] Alpha Updates"
read -t 0.1
echo "[2] Zurück zum Menü"
read -t 0.1
read -n1 -p "Was mächtest du ändern?" set
echo -n "$reset"
case $set in
1)
if [ -f ".alpha" ]; then
clear
echo "Du bist bereits im Alpha ring!"
echo
read -n1 -p "Möchtest du diesen jetzt verlassen? (Y/N) " versionl
case $versionl in
Y | y | J | j)
rm .alpha
rm 20*
clear
echo "Du erhältst nun keine Test-Versionen mehr!"
read -t 3 -n 1
jumpto update
exit
;;
N | n)
touch .alpha
rm 20*
clear
echo "Du erhälstst weiterhin Alpha Updates."
read -t 3
jumpto update
exit
;;
*)
clear
read -n1 "Eingabe nicht erkannt"
jumpto settings
exit
;;
esac
elif [[ * ]]; then
clear
read -n1 -p "Möchtest du jetzt der Alpha beitreten? (Y/N) " versionj
case $versionj in
Y | y | j | J)
touch .alpha
rm 20*
clear
echo "Du erhälst ab jetzt die neuste (Alpha) Version!"
read -t 3 -n 1
jumpto update
exit
;;
N | n)
rm .alpha
rm 20*
clear
echo "Du erhältst weiterhin die offizielle Version!"
read -t 3 -n 1
jumpto update
exit
;;
*)
clear
read -n1 "Eingabe nicht erkannt"
jumpto settings
exit
;;
esac
fi
;;
2)
jumpto menue
exit
;;
*)
clear
read -n1 "Eingabe nicht erkannt"
jumpto settings
exit
;;
esac
exit