-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackupmon-1.8.22.sh
6363 lines (5683 loc) · 323 KB
/
backupmon-1.8.22.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
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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# Original functional backup script by: @Jeffrey Young, August 9, 2023
# BACKUPMON heavily modified and restore functionality added by @Viktor Jaep, 2023-2024
#
# BACKUPMON is a shell script that provides backup and restore capabilities for your Asus-Merlin firmware router's JFFS,
# NVRAM and external USB drive environment. By creating a network share off a NAS, server, or other device, BACKUPMON can
# point to your location of choice, and perform a daily backup to this mounted drive. To perform daily, unattended backups,
# simply schedule a daily job through BACKUPMON, which will automatically get added to your CRON schedule. During a
# situation of need, where a backup would need to be restored after a catastrophic event with either your router or
# attached USB storage, simply copy the backupmon.sh + backupmon.cfg files over to a newly formatted /jffs/scripts folder,
# ensuring that your external USB storage was formatted with the same exact name (how-to's are all retrievable from the
# instructions.txt in your backup folder), and perform the restore by running the "backupmon.sh -restore" command,
# selecting the backup you want to use, and going through the prompts to complete the restoration of both your /jffs, NVRAM
# and external USB drive environments.
#
# Please use the 'backupmon.sh -setup' command to configure the necessary parameters that match your environment the best!
# Last Modified: 2024-Nov-28
######################################################################################
# Variable list -- please do not change any of these
Version="1.8.22" # Current version
Beta=0 # Beta release Y/N
CFGPATH="/jffs/addons/backupmon.d/backupmon.cfg" # Path to the backupmon config file
DLVERPATH="/jffs/addons/backupmon.d/version.txt" # Path to the backupmon version file
LOGFILE="/jffs/addons/backupmon.d/backupmon.log" # Path to the local logfile
ERRORLOGFILE="/jffs/addons/backupmon.d/backupmonerrors.log" # Path to the local errors logfile
ERRORFILE="/jffs/addons/backupmon.d/errors.txt" # Path to the local error flag file
PFEXCLUSION="/jffs/addons/backupmon.d/pfexclusion.txt" # Path to pagefile exclusion file
WDAY="$(date +%a)" # Current day # of the week
MDAY="$(date +%d)" # Current day # of the month
YDAY="$(date +%j)" # Current day # of the year
EXTDRIVE="/tmp/mnt/$(nvram get usb_path_sda1_label)" # Grabbing the default External USB Drive path
EXTLABEL="$(nvram get usb_path_sda1_label)" # Grabbing the default External USB Label name
PRIMARYUNCUPDATED="False" # Tracking if the Primary UNC was updated or not
SECONDARYUNCUPDATED="False" # Tracking if the Secondary UNC was updated or not
UpdateNotify=0 # Tracking whether a new update is available
BSWITCH="False" # Tracking -backup switch to eliminate timer
USBSOURCE="FALSE" # Tracking switch
USBTARGET="FALSE" # Tracking switch
SMBTARGET="FALSE" # Tracking switch
SECONDARYUSBTARGET="FALSE" # Tracking switch
TESTUSBTARGET="FALSE" # Tracking switch
SECONDARYSWITCH="False" # Tracking switch
##-------------------------------------##
## Added by Martinski W. [2024-Aug-10] ##
##-------------------------------------##
_EscapeUNCPathBackslashes_()
{
if [ $# -eq 0 ] || [ -z "$1" ] ; then echo "" ; return 1 ; fi
if echo "$1" | grep -qE "^\\\\\\\\\\\\\\\\.*"
then echo "$1"
else echo "$1" | sed -e 's,\\,\\\\,g'
fi
return 0
}
##-------------------------------------##
## Added by Martinski W. [2024-Aug-11] ##
##-------------------------------------##
readonly mainLAN_IPaddr="$(nvram get lan_ipaddr)"
readonly mainLAN_IP_Def="${mainLAN_IPaddr%.*}.25"
ROUTERMODEL="$(nvram get odmpid)"
[ -z "$ROUTERMODEL" ] && ROUTERMODEL="$(nvram get productid)"
readonly BKUP_Dir_Def1="/router/${ROUTERMODEL}_Backups"
readonly BKUP_Dir_Def2="/router/${ROUTERMODEL}_2ndBackups"
readonly UNC_Drive_Def1="/tmp/mnt/backups"
readonly UNC_Drive_Def2="/tmp/mnt/secondarybackups"
readonly UNC_NFS_Path_Def1="${mainLAN_IP_Def}:/Backups"
readonly UNC_NFS_Path_Def2="${mainLAN_IP_Def}:/SecondaryBackups"
readonly UNC_NET_Path_Def1="$(_EscapeUNCPathBackslashes_ "\\\\${mainLAN_IP_Def}\\Backups")"
readonly UNC_NET_Path_Def2="$(_EscapeUNCPathBackslashes_ "\\\\${mainLAN_IP_Def}\\SecondaryBackups")"
readonly ActionNeededStr="<-- Action Needed!"
# Default Config variables #
BTUSERNAME="admin"
BTPASSWORD="YWRtaW4K"
UNC="$UNC_NET_Path_Def1"
UNCDRIVE="$UNC_Drive_Def1"
BKDIR="$BKUP_Dir_Def1"
BACKUPMEDIA="Network"
EXCLUSION=""
BACKUPSWAP=0
SMBVER="2.1"
SCHEDULE=0
SCHEDULEHRS=2
SCHEDULEMIN=30
SCHEDULEMODE="BackupOnly"
FREQUENCY="M"
MODE="Basic"
PURGE=0
PURGELIMIT=0
AMTMEMAIL=0
AMTMEMAILSUCCESS=0
AMTMEMAILFAILURE=0
SECONDARYSTATUS=0
SECONDARYUSER="admin"
SECONDARYPWD="YWRtaW4K"
SECONDARYUNC="$UNC_NET_Path_Def2"
SECONDARYUNCDRIVE="$UNC_Drive_Def2"
SECONDARYBKDIR="$BKUP_Dir_Def2"
SECONDARYBACKUPMEDIA="Network"
SECONDARYEXCLUSION=""
SECONDARYFREQUENCY="M"
SECONDARYMODE="Basic"
SECONDARYPURGE=0
SECONDARYPURGELIMIT=0
##----------------------------------------##
## Modified by Martinski W. [2024-Jul-09] ##
##----------------------------------------##
# Custom Email Library Script Variables #
readonly scriptFileName="${0##*/}"
readonly scriptFileNTag="${scriptFileName%.*}"
readonly CEMAIL_LIB_BRANCH="master"
readonly CEMAIL_LIB_URL1="https://raw.githubusercontent.com/MartinSkyW/CustomMiscUtils/${CEMAIL_LIB_BRANCH}/EMail"
readonly CEMAIL_LIB_URL2="https://raw.githubusercontent.com/Martinski4GitHub/CustomMiscUtils/${CEMAIL_LIB_BRANCH}/EMail"
readonly CEMAIL_LIB_URL3="https://raw.githubusercontent.com/ViktorJp/BACKUPMON/main/CustomMiscUtils/${CEMAIL_LIB_BRANCH}/EMail"
readonly CEMAIL_LIB_LOCAL_DIR="/jffs/addons/shared-libs"
readonly CEMAIL_LIB_FILE_NAME="CustomEMailFunctions.lib.sh"
readonly CEMAIL_LIB_FILE_PATH="${CEMAIL_LIB_LOCAL_DIR}/$CEMAIL_LIB_FILE_NAME"
# Color variables
CBlack="\e[1;30m"
InvBlack="\e[1;40m"
CRed="\e[1;31m"
InvRed="\e[1;41m"
CGreen="\e[1;32m"
InvGreen="\e[1;42m"
CDkGray="\e[1;90m"
InvDkGray="\e[1;100m"
InvLtGray="\e[1;47m"
CYellow="\e[1;33m"
InvYellow="\e[1;43m"
CBlue="\e[1;34m"
InvBlue="\e[1;44m"
CMagenta="\e[1;35m"
CCyan="\e[1;36m"
InvCyan="\e[1;46m"
CWhite="\e[1;37m"
InvWhite="\e[1;107m"
CClear="\e[0m"
#Preferred standard router binaries path
export PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH"
# -------------------------------------------------------------------------------------------------------------------------
# Functions
# -------------------------------------------------------------------------------------------------------------------------
# LogoNM is a function that displays the BACKUPMON script name in a cool ASCII font without menu options
logoNM () {
clear
echo ""
echo ""
echo ""
echo -e "${CDkGray} ____ ___ ________ ____ ______ __ _______ _ __"
echo -e " / __ )/ | / ____/ //_/ / / / __ \/ |/ / __ \/ | / /"
echo -e " / __ / /| |/ / / ,< / / / / /_/ / /|_/ / / / / |/ /"
echo -e " / /_/ / ___ / /___/ /| / /_/ / ____/ / / / /_/ / /| /"
echo -e " /_____/_/ |_\____/_/ |_\____/_/ /_/ /_/\____/_/ |_/ v$Version"
echo ""
echo ""
printf "\r ${CGreen} [ INITIALIZING ] ${CClear}"
sleep 1
clear
echo ""
echo ""
echo ""
echo -e "${CYellow} ____ ___ ________ ____ ______ __ _______ _ __"
echo -e " / __ )/ | / ____/ //_/ / / / __ \/ |/ / __ \/ | / /"
echo -e " / __ / /| |/ / / ,< / / / / /_/ / /|_/ / / / / |/ /"
echo -e " / /_/ / ___ / /___/ /| / /_/ / ____/ / / / /_/ / /| /"
echo -e " /_____/_/ |_\____/_/ |_\____/_/ /_/ /_/\____/_/ |_/ v$Version"
echo ""
echo ""
printf "\r ${CGreen}[ INITIALIZING ... DONE ]${CClear}"
sleep 1
printf "\r ${CGreen} [ LOADING... ] ${CClear}"
sleep 1
}
logoNMexit () {
clear
echo ""
echo ""
echo ""
echo -e "${CYellow} ____ ___ ________ ____ ______ __ _______ _ __"
echo -e " / __ )/ | / ____/ //_/ / / / __ \/ |/ / __ \/ | / /"
echo -e " / __ / /| |/ / / ,< / / / / /_/ / /|_/ / / / / |/ /"
echo -e " / /_/ / ___ / /___/ /| / /_/ / ____/ / / / /_/ / /| /"
echo -e " /_____/_/ |_\____/_/ |_\____/_/ /_/ /_/\____/_/ |_/ v$Version"
echo ""
echo ""
printf "\r ${CGreen} [ SHUTTING DOWN ] ${CClear}"
sleep 1
clear
echo ""
echo ""
echo ""
echo -e "${CDkGray} ____ ___ ________ ____ ______ __ _______ _ __"
echo -e " / __ )/ | / ____/ //_/ / / / __ \/ |/ / __ \/ | / /"
echo -e " / __ / /| |/ / / ,< / / / / /_/ / /|_/ / / / / |/ /"
echo -e " / /_/ / ___ / /___/ /| / /_/ / ____/ / / / /_/ / /| /"
echo -e " /_____/_/ |_\____/_/ |_\____/_/ /_/ /_/\____/_/ |_/ v$Version"
echo ""
echo ""
printf "\r ${CGreen} [ SHUTTING DOWN ] ${CClear}"
sleep 1
printf "\r ${CDkGray} [ GOODBYE... ] ${CClear}\n\n"
sleep 1
}
# -------------------------------------------------------------------------------------------------------------------------
# Promptyn is a simple function that accepts y/n input
promptyn () { # No defaults, just y or n
while true; do
read -p '[y/n]? ' YESNO
case "$YESNO" in
[Yy]* ) return 0 ;;
[Nn]* ) return 1 ;;
* ) echo -e "\nPlease answer y or n.";;
esac
done
}
# -------------------------------------------------------------------------------------------------------------------------
# blackwhite is a simple function that removes all color attributes
blackwhite () {
# Color variables
CBlack=""
InvBlack=""
CRed=""
InvRed=""
CGreen=""
InvGreen=""
CDkGray=""
InvDkGray=""
InvLtGray=""
CYellow=""
InvYellow=""
CBlue=""
InvBlue=""
CMagenta=""
CCyan=""
InvCyan=""
CWhite=""
InvWhite=""
CClear=""
}
# -------------------------------------------------------------------------------------------------------------------------
# teelogger provides an easy way to append logging info to an existing log entry
teelogger() {
log=$1
while read line ; do
echo -e "$(date +'%b %d %Y %X') $(nvram get lan_hostname) BACKUPMON[$$] - $line" | tee -a $log
done
}
# -------------------------------------------------------------------------------------------------------------------------
# errorcheck looks for the existence of an error file and provides an on-screen warning about it
errorcheck() {
if [ -f $ERRORFILE ]; then
echo ""
errordate=$(cat $ERRORFILE | awk 'NR==2 {print $1}') >/dev/null 2>&1
errordate=$(date -d @${errordate})
echo -e "${InvRed}${CWhite} WARNING: Errors were detected during last backup on $errordate.${CClear}"
echo -e "${InvRed}${CWhite} Please review error logs from the setup/configuration menu.${CClear}"
echo ""
fi
}
# -------------------------------------------------------------------------------------------------------------------------
# Preparebar and Progressbaroverride is a script that provides a nice progressbar to show script activity
##----------------------------------------##
## Modified by Martinski W. [2024-Nov-01] ##
##----------------------------------------##
preparebar()
{
# $1 - bar length
# $2 - bar char
barlen="$1"
barspaces="$(printf "%*s" "$1" ' ')"
barchars="$(printf "%*s" "$1" ' ' | tr ' ' "$2")"
}
progressbaroverride()
{
insertspc=" "
if [ "$1" -eq -1 ]
then
printf "\r $barspaces\r"
else
barch="$(($1*barlen/$2))"
barsp="$((barlen-barch))"
percnt="$((100*$1/$2))"
fi
if [ $# -gt 5 ] && [ -n "$6" ]; then AltNum="$6" ; else AltNum="$1" ; fi
printf " ${CWhite}${InvDkGray}$AltNum${4} / ${percnt}%%${CClear} ${CGreen}[ e=Exit / Selection? ${InvGreen} ${CClear}${CGreen}]\r${CClear}" "$barchars" "$barspaces"
# Borrowed this wonderful keypress capturing mechanism from @Eibgrad... thank you! :)
key_press=''; read -rsn1 -t 1 key_press < "$(tty 0>&2)"
if [ "$key_press" ]
then
case "$key_press" in
[Xx]) echo ""; echo ""; sleep 1; restore;;
[Ss]) (vsetup); source "$CFGPATH" ; echo ""; sleep 1; exit 0;;
[Ee]) # Exit gracefully
echo ""
echo -e "${CClear}"
exit 0
;;
esac
fi
}
# -------------------------------------------------------------------------------------------------------------------------
# updatecheck is a function that downloads the latest update version file, and compares it with what's currently installed
updatecheck () {
# Download the latest version file from the source repository
curl --silent --retry 3 "https://raw.githubusercontent.com/ViktorJp/backupmon/master/version.txt" -o "/jffs/addons/backupmon.d/version.txt"
if [ -f $DLVERPATH ]
then
# Read in its contents for the current version file
DLVersion=$(cat $DLVERPATH)
# Compare the new version with the old version and log it
if [ "$Beta" == "1" ]; then # Check if Dev/Beta Mode is enabled and disable notification message
UpdateNotify=0
elif [ "$DLVersion" != "$Version" ]; then
UpdateNotify=1
echo -e "$(date +'%b %d %Y %X') $(nvram get lan_hostname) BACKUPMON[$$] - INFO: A new update (v$DLVersion) is available to download" >> $LOGFILE
else
UpdateNotify=0
fi
fi
}
# -------------------------------------------------------------------------------------------------------------------------
# vlogs is a function that calls the nano text editor to view the BACKUPMON log file
vlogs () {
export TERM=linux
nano +999999 --linenumbers $LOGFILE
}
# -------------------------------------------------------------------------------------------------------------------------
# velogs is a function that calls the nano text editor to view the BACKUPMON error log file
velogs () {
export TERM=linux
nano +999999 --linenumbers $ERRORLOGFILE
}
# -------------------------------------------------------------------------------------------------------------------------
# Trimlogs is a function that forces the logs down to a certain number of rows to give you some history
trimlogs () {
#trim regular logs
CURRLOGSIZE=$(wc -l $LOGFILE | awk '{ print $1 }' ) # Determine the number of rows in the log
if [ $CURRLOGSIZE -gt 5000 ] # If it's bigger than the max allowed, tail/trim it!
then
echo "$(tail -5000 $LOGFILE)" > $LOGFILE
fi
#trim error logs
CURRERRLOGSIZE=$(wc -l $ERRORLOGFILE | awk '{ print $1 }' ) # Determine the number of rows in the log
if [ $CURRERRLOGSIZE -gt 5000 ] # If it's bigger than the max allowed, tail/trim it!
then
echo "$(tail -5000 $ERRORLOGFILE)" > $ERRORLOGFILE
fi
}
# -------------------------------------------------------------------------------------------------------------------------
# vconfig is a function that guides you through the various configuration options for backupmon
vconfig () {
if [ -f /jffs/scripts/backupmon.cfg ]; then
source /jffs/scripts/backupmon.cfg
cp /jffs/scripts/backupmon.cfg "$CFGPATH"
fi
if [ -f "$CFGPATH" ]; then #Making sure file exists before proceeding
source "$CFGPATH"
if [ -z "$SECONDARYPURGE" ]; then SECONDARYPURGE=0; fi
# Check for the Swap File Exclusion
if [ "$BACKUPSWAP" == "0" ]; then
excludeswap
fi
CHANGES=0 #track notification to save your changes
while true; do
clear
DLVersionPF=$(printf "%-8s" $DLVersion)
LCLVersionPF=$(printf "%-8s" $Version)
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON Primary Backup Configuration Menu ${CClear}"
if [ "$UpdateNotify" == "1" ]; then
echo -e "${InvYellow} ${InvDkGray}${CWhite} Update available: v$LCLVersionPF -> v$DLVersionPF ${CClear}"
fi
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} Please choose from the various options below, which allow you to modify certain${CClear}"
echo -e "${InvGreen} ${CClear} customizable parameters that affect the operation of the primary backup.${CClear}"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite} ${CClear} : BACKUPMON Version : ${CGreen}$Version"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite} ${CClear} : Source Router Model : ${CGreen}$ROUTERMODEL"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite} ${CClear} : Source Router Firmware/Build : ${CGreen}$FWBUILD"
if [ "$EXTDRIVE" == "/tmp/mnt/<selectusbdrive>" ]; then
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(1) ${CClear} : Source EXT USB Drive Mount Point : ${CWhite}${InvRed}${ActionNeededStr} ${CClear}"
else
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(1) ${CClear} : Source EXT USB Drive Mount Point : ${CGreen}$EXTDRIVE"
fi
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(2) ${CClear} : Backup Target Media Type : ${CGreen}$BACKUPMEDIA"
if [ "$BACKUPMEDIA" = "USB" ]
then
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(3) ${CClear}${CDkGray} : Backup Target Username : ${CDkGray}$BTUSERNAME"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(4) ${CClear}${CDkGray} : Backup Target Password (ENC) : ${CDkGray}$BTPASSWORD"
if [ "$PRIMARYUNCUPDATED" = "True" ]; then
echo -en "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(5) ${CClear}${CDkGray} : Backup Target Path : ${CDkGray}"; _EscapeUNCPathBackslashes_ "${UNC}"
else
echo -en "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(5) ${CClear}${CDkGray} : Backup Target Path : ${CDkGray}"; _EscapeUNCPathBackslashes_ "${UNC}"
fi
elif [ "$BACKUPMEDIA" = "Network" ]
then
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(3) ${CClear} : Backup Target Username : ${CGreen}$BTUSERNAME"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(4) ${CClear} : Backup Target Password (ENC) : ${CGreen}$BTPASSWORD"
if [ -z "${UNC}" ]
then
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(5) ${CClear} : Backup Target Path : ${CWhite}${InvRed}${ActionNeededStr} ${CClear}"
else
if [ "$PRIMARYUNCUPDATED" = "True" ]; then
echo -en "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(5) ${CClear} : Backup Target Path : ${CGreen}"; _EscapeUNCPathBackslashes_ "${UNC}"
else
echo -en "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(5) ${CClear} : Backup Target Path : ${CGreen}"; _EscapeUNCPathBackslashes_ "${UNC}"
fi
fi
elif [ "$BACKUPMEDIA" = "Network-NFS" ]
then
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(3) ${CClear}${CDkGray} : Backup Target Username : ${CDkGray}$BTUSERNAME"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(4) ${CClear}${CDkGray} : Backup Target Password (ENC) : ${CDkGray}$BTPASSWORD"
if [ -z "${UNC}" ]
then
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(5) ${CClear} : Backup Target Path : ${CWhite}${InvRed}${ActionNeededStr} ${CClear}"
else
if [ "$PRIMARYUNCUPDATED" = "True" ]; then
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(5) ${CClear} : Backup Target Path : ${CGreen}${UNC}"
else
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(5) ${CClear} : Backup Target Path : ${CGreen}${UNC}"
fi
fi
fi
if [ "$BACKUPMEDIA" = "Network-NFS" ]; then
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite} |--${CClear}-- NFS Mount Options? : ${CGreen}$NFSMOUNTOPT"
else
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite} |--${CClear}${CDkGray}-- NFS Mount Options? : N/A"
fi
if [ "$UNCDRIVE" == "" ] || [ -z "$UNCDRIVE" ]; then
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(6) ${CClear} : Backup Target Mount Point : ${CWhite}${InvRed}${ActionNeededStr} ${CClear}"
else
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(6) ${CClear} : Backup Target Mount Point : ${CGreen}$UNCDRIVE"
fi
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(7) ${CClear} : Backup Target Directory Path : ${CGreen}$BKDIR"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(8) ${CClear} : Backup Exclusion File : ${CGreen}$EXCLUSION"
echo -en "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(9) ${CClear} : Backup Swap File : ${CGreen}"
if [ "$BACKUPSWAP" == "0" ]; then
printf "No"; printf "%s\n";
elif [ "$BACKUPSWAP" == "1" ]; then
printf "Yes"; printf "%s\n";fi
if [ "$BACKUPMEDIA" = "Network" ]; then
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(10)${CClear} : Backup CIFS/SMB Version : ${CGreen}$SMBVER"
else
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(10)${CClear}${CDkGray} : Backup CIFS/SMB Version : ${CDkGray}$SMBVER"
fi
echo -en "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(11)${CClear} : Backup Retention : ${CGreen}"
if [ "$FREQUENCY" == "W" ]; then
printf "Weekly"; printf "%s\n";
elif [ "$FREQUENCY" == "M" ]; then
printf "Monthly"; printf "%s\n";
elif [ "$FREQUENCY" == "Y" ]; then
printf "Yearly"; printf "%s\n";
elif [ "$FREQUENCY" == "P" ]; then
printf "Perpetual"; printf "%s\n"; fi
if [ "$FREQUENCY" == "P" ]; then
echo -en "${InvGreen} ${CClear} ${InvDkGray}${CWhite} |--${CClear}-- Purge Backups : ${CGreen}"
if [ "$PURGE" == "0" ]; then
printf "No"; printf "%s\n";
elif [ "$PURGE" == "1" ]; then
printf "Yes"; printf "%s\n";fi
echo -en "${InvGreen} ${CClear} ${InvDkGray}${CWhite} |--${CClear}-- Purge older than (days) : ${CGreen}"
if [ "$PURGELIMIT" == "0" ]; then
printf "N/A"; printf "%s\n";
else
printf $PURGELIMIT; printf "%s\n";
fi
else
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite} |--${CClear}${CDkGray}-- Purge Backups : ${CDkGray}No"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite} |--${CClear}${CDkGray}-- Purge older than (days) : ${CDkGray}N/A"
fi
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(12)${CClear} : Backup/Restore Mode : ${CGreen}$MODE"
echo -en "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(13)${CClear} : Schedule Backups : ${CGreen}"
if [ "$SCHEDULE" == "0" ]; then
printf "No"; printf "%s\n";
else printf "Yes"; printf "%s\n"; fi
if [ "$SCHEDULE" == "1" ]; then
MINS=$(printf "%02.0f\n" $SCHEDULEMIN)
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite} |--${CClear}-- Time: : ${CGreen}$SCHEDULEHRS:$MINS"
echo -en "${InvGreen} ${CClear} ${InvDkGray}${CWhite} |--${CClear}-- Scheduled Backup Mode : ${CGreen}"
if [ "$SCHEDULEMODE" == "BackupOnly" ]; then
printf "Backup Only"; printf "%s\n";
elif [ "$SCHEDULEMODE" == "BackupAutoPurge" ]; then
printf "Backup + Autopurge"; printf "%s\n"; fi
else
MINS=$(printf "%02.0f\n" $SCHEDULEMIN)
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite} |--${CClear}${CDkGray}-- Time: : ${CDkGray}$SCHEDULEHRS:$MINS"
echo -en "${InvGreen} ${CClear} ${InvDkGray}${CWhite} |--${CClear}${CDkGray}-- Scheduled Backup Mode : ${CDkGray}"
if [ "$SCHEDULEMODE" == "BackupOnly" ]; then
printf "Backup Only"; printf "%s\n";
elif [ "$SCHEDULEMODE" == "BackupAutoPurge" ]; then
printf "Backup + Autopurge"; printf "%s\n"; fi
fi
echo -en "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(14)${CClear} : AMTM Email Notifications : ${CGreen}"
if [ "$AMTMEMAIL" == "0" ]; then
printf "No"; printf "%s\n";
else printf "Yes"; printf "%s\n"; fi
if [ "$AMTMEMAILSUCCESS" == "1" ]; then
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite} |--${CClear}-- On Success : ${CGreen}Yes"
else
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite} |--${CClear}${CDkGray}-- On Success : ${CDkGray}No"
fi
if [ "$AMTMEMAILFAILURE" == "1" ]; then
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite} |--${CClear}-- On Failure : ${CGreen}Yes"
else
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite} | ${CClear}${CDkGray}-- On Failure : ${CDkGray}No"
fi
echo -en "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(15)${CClear} : Secondary Backup Config Options : ${CGreen}"
if [ "$SECONDARYSTATUS" != "0" ] && [ "$SECONDARYSTATUS" != "1" ]; then SECONDARYSTATUS=0; fi
if [ "$SECONDARYSTATUS" == "0" ]; then
printf "Disabled"; printf "%s\n";
else printf "Enabled"; printf "%s\n"; fi
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite} | ${CClear}"
if [ $CHANGES -eq 0 ]; then
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(s) ${CClear} : Save Config & Exit"
else
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(s) ${CClear} : Save Config & Exit ${CWhite}${InvRed}<-- Save your changes! ${CClear}"
fi
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(e) ${CClear} : Exit & Discard Changes"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
CHANGES=1
printf "Selection: "
read -r ConfigSelection
# Execute chosen selections
case "$ConfigSelection" in
1) # -----------------------------------------------------------------------------------------
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON - SOURCE Mount Point ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} Please choose the SOURCE Mount Point of your attached external USB Drive that contains${CClear}"
echo -e "${InvGreen} ${CClear} data that you want to have backed up. In most cases, whatever is attached to your sda1${CClear}"
echo -e "${InvGreen} ${CClear} partition should be selected. Should there be only one mount point available, it will${CClear}"
echo -e "${InvGreen} ${CClear} be automatically selected.${CClear}"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
printf "${CClear}Recommended Mount Point: ${CGreen}"
_GetDefaultMountPoint_ USBmp
USBSOURCE="TRUE"
echo -e "${CClear}"
_GetMountPoint_ USBmp "Select an EXT USB Drive Mount Point: "
read -rsp $'Press any key to acknowledge...\n' -n1 key
checkusbexclusion
;;
2) # -----------------------------------------------------------------------------------------
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON - TARGET Backup Media Type ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} What is the TARGET Backup Media Type? This is the type of device that you want your${CClear}"
echo -e "${InvGreen} ${CClear} backups copied to. Please indicate whether the media is a network device (accessible${CClear}"
echo -e "${InvGreen} ${CClear} via UNC path using the common CIFS/SMB network protocol) a local attached USB device${CClear}"
echo -e "${InvGreen} ${CClear} (connected to router), or a network device (accessible via an NFS share). PLEASE NOTE:${CClear}"
echo -e "${InvGreen} ${CClear} If the USB or Network-NFS option is chosen, there will be no need to complete further${CClear}"
echo -e "${InvGreen} ${CClear} information for the Target username or password, and will be grayed out.${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} (Network=${CGreen}1${CClear}, USB=${CGreen}2${CClear}, Network-NFS=${CGreen}3${CClear}) (Default: 1)"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo
printf "Current Target Media Type: ${CGreen}${BACKUPMEDIA}${CClear}\n"
while true
do
printf "\nEnter selection [${CGreen}1${CClear}-${CGreen}3${CClear}]: " ; read -r BKUPMEDIA1st
case $BKUPMEDIA1st in
1) BACKUPMEDIA="Network"; break ;;
2) BACKUPMEDIA="USB"; break ;;
3) BACKUPMEDIA="Network-NFS"; break ;;
"") printf "\nPlease enter 1, 2 or 3.\n" ;;
*) printf "\nERROR: INVALID entry [$BKUPMEDIA1st]."
printf "\nPlease enter 1, 2 or 3.\n" ;;
esac
done
UNC=""
if [ "$BACKUPMEDIA" = "Network" ] && [ "$EXTDRIVE" = "$UNCDRIVE" ]; then
UNCDRIVE=""
fi
if [ "$BACKUPMEDIA" = "USB" ] && [ "$EXTDRIVE" = "$UNCDRIVE" ]; then
UNCDRIVE=""
fi
if [ "$BACKUPMEDIA" = "Network-NFS" ] && [ "$EXTDRIVE" = "$UNCDRIVE" ]; then
UNCDRIVE=""
fi
;;
3) # -----------------------------------------------------------------------------------------
if [ "$BACKUPMEDIA" = "Network" ]
then
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON - TARGET Network Backup Username ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} What is the TARGET Network Backup Username?${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} (Default: admin)"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
echo -e "${CClear}Current Username: ${CGreen}$BTUSERNAME"; echo -e "${CClear}"
read -p 'Username: ' BTUSERNAME1
if [ "$BTUSERNAME1" == "" ] || [ -z "$BTUSERNAME1" ]; then BTUSERNAME="admin"; else BTUSERNAME="$BTUSERNAME1"; fi # Using default value on enter keypress
fi
;;
4) # -----------------------------------------------------------------------------------------
if [ "$BACKUPMEDIA" = "Network" ]
then
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON - TARGET Network Backup Password ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} What is the TARGET Network Backup Password?${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} (Default: admin)"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
if [ $BTPASSWORD == "admin" ]; then
echo -e "${CClear}Old Password (Unencoded): ${CGreen}admin"
else
echo -en "${CClear}Old Password (Unencoded): ${CGreen}"; echo "$BTPASSWORD" | openssl enc -d -base64 -A
fi
echo -e "${CClear}"
read -rp 'New Password: ' BTPASSWORD1
if [ "$BTPASSWORD1" != "" ] || [ ! -z "$BTPASSWORD1" ]; then BTPASSWORD=`echo $BTPASSWORD1 | openssl enc -base64 -A`; else BTPASSWORD="$BTPASSWORD1"; fi # Using default value on enter keypress
fi
;;
5) # -----------------------------------------------------------------------------------------
if [ "$BACKUPMEDIA" = "Network" ]
then
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON - TARGET Backup UNC Path ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} What is the TARGET Backup UNC Path? This is the path of a local network backup device${CClear}"
echo -e "${InvGreen} ${CClear} that has a share made available for backups to be pushed to. Please note: Use proper${CClear}"
echo -en "${InvGreen} ${CClear} notation for the network path by starting with 4 backslashes "; printf "%s" "(\\\\\\\\)"; echo -e " and using two${CClear}"
echo -en "${InvGreen} ${CClear} backslashes "; printf "%s" "(\\\\)"; echo -e " between any additional folders. Example below:"
echo -e "${InvGreen} ${CClear}"
echo -en "${InvGreen} ${CClear} (Default: ${CGreen}" ; printf "%s" "$(_EscapeUNCPathBackslashes_ "$UNC_NET_Path_Def1")" ; echo -e "${CClear})"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo
echo -en "Current UNC Path: ${CGreen}" ; _EscapeUNCPathBackslashes_ "${UNC}" ; echo -e "${CClear}"
read -rp 'Target Backup UNC Path: ' UNC_NET_PATH1st
if [ -n "$UNC_NET_PATH1st" ]
then UNC="$(_EscapeUNCPathBackslashes_ "$UNC_NET_PATH1st")"
elif [ -z "$UNC" ]
then UNC="$UNC_NET_Path_Def1"
fi
PRIMARYUNCUPDATED="True"
elif [ "$BACKUPMEDIA" = "Network-NFS" ]
then
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON - TARGET Backup NFS Path ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} What is the TARGET Backup NFS Path? This is the path of a local network backup device${CClear}"
echo -e "${InvGreen} ${CClear} that has an NFS share made available for backups to be pushed to. Please note: Use${CClear}"
echo -e "${InvGreen} ${CClear} proper notation for the NFS network path by using the example below:${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} (Default: ${CGreen}${UNC_NFS_Path_Def1}${CClear})"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo
echo -e "Current NFS Path: ${CGreen}${UNC}${CClear}" ; echo
read -rp 'Target Backup NFS Path: ' UNC_NFS_PATH1st
if [ -n "$UNC_NFS_PATH1st" ]
then UNC="$UNC_NFS_PATH1st"
else UNC="${UNC:=$UNC_NFS_Path_Def1}"
fi
PRIMARYUNCUPDATED="True"
echo ""; echo ""
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON - TARGET Backup NFS Mount Options ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} What optional NFS Mount Options would you like to use (if any)? These options are${CClear}"
echo -e "${InvGreen} ${CClear} custom settings that may be needed to establish a successful connection to your NFS${CClear}"
echo -e "${InvGreen} ${CClear} share. Please follow format of example below:${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} (ex: nfsvers=3,nolock,_netdev,rsize=8192,wsize=8192)"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
echo -e "${CClear}Current NFS Mount Options: ${CGreen}$NFSMOUNTOPT"; echo -e "${CClear}"
read -rp 'NFS Mount Options: ' NFSMOUNTOPT1
if [ "$NFSMOUNTOPT1" == "" ] || [ -z "$NFSMOUNTOPT1" ]; then NFSMOUNTOPT=""; else NFSMOUNTOPT="$NFSMOUNTOPT1"; fi # Using default value on enter keypress
fi
;;
6) # -----------------------------------------------------------------------------------------
if [ "$BACKUPMEDIA" = "Network" ] || [ "$BACKUPMEDIA" = "Network-NFS" ]
then
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON - TARGET Backup Drive Mount Point ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} What would you like to name the TARGET Network Backup Drive Mount Point? This mount${CClear}"
echo -e "${InvGreen} ${CClear} path will be created for you, and is the local path on your router typically located${CClear}"
echo -e "${InvGreen} ${CClear} under /tmp/mnt which provides a physical directory that is mounted to the network${CClear}"
echo -e "${InvGreen} ${CClear} backup location. Please note: Use proper notation for the path by using single${CClear}"
echo -e "${InvGreen} ${CClear} forward slashes between directories. Example below:${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} (Default: ${CGreen}${UNC_Drive_Def1}${CClear})"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ; echo -e "Current Backup Drive Mount Point: ${CGreen}${UNCDRIVE}${CClear}" ; echo
read -p 'Target Network Backup Drive Mount Point: ' UNC_DRIVE1st
if [ -n "$UNC_DRIVE1st" ]
then UNCDRIVE="$UNC_DRIVE1st"
else UNCDRIVE="${UNCDRIVE:=$UNC_Drive_Def1}"
fi
##OFF##SMBTARGET="TRUE"
##OFF##_GetMountPoint_ SMBmp "Select an existing Target CIFS/SMB Backup Drive Mount Point: "
##OFF##read -rsp $'Press any key to acknowledge...\n' -n1 key
if [ "$EXTDRIVE" == "$UNCDRIVE" ]; then
UNCDRIVE=""
echo ""
echo -e "${CYellow}WARNING: Your TARGET Network Backup Drive Mount Point cannot be named the same as your"
echo -e "${CYellow}SOURCE External USB Drive Mount. Please choose a mount point name that is unique for"
echo -e "${CYellow}this network target.${CClear}\n"
read -rsp $'Press any key to acknowledge...\n' -n1 key
fi
elif [ "$BACKUPMEDIA" = "USB" ]
then
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON - TARGET Backup USB Drive Mount Point ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} Please choose the TARGET USB Backup Drive Mount Point assigned to your external USB${CClear}"
echo -e "${InvGreen} ${CClear} Drive where you want backups to be stored. Should there be only one drive available,${CClear}"
echo -e "${InvGreen} ${CClear} it will be automatically selected. PLEASE NOTE: It is highly recommended not to use${CClear}"
echo -e "${InvGreen} ${CClear} the same USB drive to both be a SOURCE and TARGET for backups.${CClear}"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
USBTARGET="TRUE"
_GetMountPoint_ USBmp "Select a Target USB Backup Drive Mount Point: "
read -rsp $'Press any key to acknowledge...\n' -n1 key
checkusbexclusion
fi
;;
7) # -----------------------------------------------------------------------------------------
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON - TARGET Backup Directory Path ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} What is the TARGET Backup Directory Path? This is the path that is created on your${CClear}"
echo -e "${InvGreen} ${CClear} network backup location in order to store and order the backups by day. Please note:${CClear}"
echo -e "${InvGreen} ${CClear} Use proper notation for the path by using single forward slashes between directories.${CClear}"
echo -e "${InvGreen} ${CClear} Example below:${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} (Default: ${CGreen}${BKUP_Dir_Def1}${CClear})"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ; echo -e "Current Backup Directory Path: ${CGreen}${BKDIR}${CClear}" ; echo
read -p 'Enter Target Backup Directory Path: ' BKUP_DIR1st
if [ -n "$BKUP_DIR1st" ]
then BKDIR="$BKUP_DIR1st"
else BKDIR="${BKDIR:=$BKUP_Dir_Def1}"
fi
checkusbexclusion
;;
8) # -----------------------------------------------------------------------------------------
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON - Backup Exclusion Path + File Name ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} Would you like to use a Backup Exclusion File Name? This file contains a list of${CClear}"
echo -e "${InvGreen} ${CClear} certain files that you want to exclude from the backup, such as your swap file.${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} ${CRed}WARNING:${CClear} If you do not use an Exclusion file with the necessary entries to exlude${CClear}"
echo -e "${InvGreen} ${CClear} your swap file (or others), your backup size and time it takes to complete the backup${CClear}"
echo -e "${InvGreen} ${CClear} will increase greatly. Examples of what to include in the exlusions.txt file below${CClear}"
echo -e "${InvGreen} ${CClear} entered in a simple list format:${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear}${CBlue} myswap.swp${CClear}"
echo -e "${InvGreen} ${CClear}${CBlue} entware/var/log/*${CClear}"
echo -e "${InvGreen} ${CClear}${CBlue} skynet/skynet.log${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} Please note: Use proper notation for the path to this file by using single forward ${CClear}"
echo -e "${InvGreen} ${CClear} slashes between directories. Example below:${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} (ex: ${CGreen}/jffs/addons/backupmon.d/exclusions.txt${CClear})"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
echo -e "${CClear}Current Exclusion File Path: ${CGreen}$EXCLUSION"; echo -e "${CClear}"
read -p 'Backup Exclusion Path + File Name: ' EXCLUSION1
if [ "$EXCLUSION1" == "" ] || [ -z "$EXCLUSION1" ]; then EXCLUSION=""; else EXCLUSION="$EXCLUSION1"; fi # Using default value on enter keypress
if [ "$BACKUPSWAP" == "0" ] && [ "$EXCLUSION" == "" ]; then EXCLUSION="$PFEXCLUSION"; fi
;;
9) # -----------------------------------------------------------------------------------------
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON - Backup Your Swap File? ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} Would you like to back up your Swap File? This file usually ranges in the 1GB, 2GB or${CClear}"
echo -e "${InvGreen} ${CClear} 4GB range. It is not a file that is required to be backed up, and may cause issues${CClear}"
echo -e "${InvGreen} ${CClear} when restoring backups. Due to the size, it will also substantially increase backup${CClear}"
echo -e "${InvGreen} ${CClear} target size and time it takes to run backups.${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} NOTE: It is highly recommended to leave this setting DISABLED.${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} (No=0, Yes=1) (Default: 0)"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
if [ "$BACKUPSWAP" == 0 ]; then BACKUPSWAPFB="No"; else BACKUPSWAPFB="Yes"; fi
echo -e "${CClear}Currently backing up Swap File?: ${CGreen}$BACKUPSWAPFB"; echo -e "${CClear}"
read -p 'Backup Swap? (0/1): ' SWAP1
if [ "$SWAP1" == "" ] || [ -z "$SWAP1" ]; then BACKUPSWAP=0; else BACKUPSWAP="$SWAP1"; fi # Using default value on enter keypress
if [ "$BACKUPSWAP" == "1" ]; then
swapname=$(cat /proc/swaps | awk 'NR==2 {print $1}' | sed 's|.*/||') >/dev/null 2>&1
sed -i -e '/'$swapname'/d' "$EXCLUSION" >/dev/null 2>&1
sed -i -e '/'$swapname'/d' "$SECONDARYEXCLUSION" >/dev/null 2>&1
fi
;;
10) # -----------------------------------------------------------------------------------------
if [ "$BACKUPMEDIA" = "Network" ]
then
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON - CIFS/SMB Protocol Version ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} What version of the CIFS/SMB protocol would you like to use? This protocol is used by${CClear}"
echo -e "${InvGreen} ${CClear} BACKUPMON to connect to other network devices in order to transfer files and backups${CClear}"
echo -e "${InvGreen} ${CClear} from source to target. While BACKUPMON supports the latest SMB protocol available${CClear}"
echo -e "${InvGreen} ${CClear} (v3.02), you can choose older versions for backwards compatibility purposes, for${CClear}"
echo -e "${InvGreen} ${CClear} example, if the target hardware is not able to support a more recent version.${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} (v2.1=1, v2.0=2, v1.0=3, v3.0=4, v3.02=5) (Default: 1)"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
echo -e "${CClear}Current CIFS/SMB Protocol Version: ${CGreen}$SMBVER"; echo -e "${CClear}"
while true; do
read -p 'CIFS/SMB Version (1/2/3/4/5)?: ' SMBVER
case $SMBVER in
[1] ) SMBVER="2.1"; break ;;
[2] ) SMBVER="2.0"; break ;;
[3] ) SMBVER="1.0"; break ;;
[4] ) SMBVER="3.0"; break ;;
[5] ) SMBVER="3.02"; break ;;
"" ) echo -e "\nError: Please use either 1, 2, 3, 4 or 5\n";;
* ) echo -e "\nError: Please use either 1, 2, 3, 4 or 5\n";;
esac
done
fi
;;
11) # -----------------------------------------------------------------------------------------
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON - Backup Retention ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} What backup retention would you like BACKUPMON to use for daily backup jobs each day?${CClear}"
echo -e "${InvGreen} ${CClear} There are 4 different choices -- Weekly, Monthly, Yearly and Perpetual. Backup${CClear}"
echo -e "${InvGreen} ${CClear} folders based on the week, month, year, or perpetual are created under your network${CClear}"
echo -e "${InvGreen} ${CClear} share. Explained below:${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}WEEKLY:"
echo -e "${InvGreen} ${CClear} 7 different folders for each day of the week are created (ex: Mon, Tue... Sun)."
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}MONTHLY:"
echo -e "${InvGreen} ${CClear} 31 different folders for each day are created (ex: 01, 02, 03... 30, 31)."
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}YEARLY:"
echo -e "${InvGreen} ${CClear} 365 different folders are created for each day (ex: 001, 002, 003... 364, 365)."
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}PERPETUAL:"
echo -e "${InvGreen} ${CClear} A unique backup folder is created each time it runs based on the date-time"
echo -e "${InvGreen} ${CClear} (ex: 20230909-084322). NOTE: When using the Perpetual backup retention option, you"
echo -e "${InvGreen} ${CClear} may only use BASIC mode."
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} (Weekly=W, Monthly=M, Yearly=Y, Perpetual=P) (Default: M)"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
if [ "$FREQUENCY" == "W" ]; then
FREQUENCYDP="Weekly"
elif [ "$FREQUENCY" == "M" ]; then
FREQUENCYDP="Monthly"
elif [ "$FREQUENCY" == "Y" ]; then
FREQUENCYDP="Yearly"
elif [ "$FREQUENCY" == "P" ]; then
FREQUENCYDP="Perpetual"
fi
echo -e "${CClear}Current Backup Retention: ${CGreen}$FREQUENCYDP"; echo -e "${CClear}"
while true; do
read -p 'Retention (W/M/Y/P)?: ' FREQUENCY
case $FREQUENCY in
[Ww] ) FREQUENCY="W"; PURGE=0; PURGELIMIT=0; break ;;
[Mm] ) FREQUENCY="M"; PURGE=0; PURGELIMIT=0; break ;;
[Yy] ) FREQUENCY="Y"; PURGE=0; PURGELIMIT=0; break ;;
[Pp] ) FREQUENCY="P"; MODE="Basic" break ;;
"" ) echo -e "\nError: Please use either M, W, Y or P\n";;
* ) echo -e "\nError: Please use either M, W, Y or P\n";;
esac
done
if [ $FREQUENCY == "P" ]; then
echo ""; echo ""
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON - Purging Perpetual Backups ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} Would you like to purge perpetual backups after a certain age? This can help trim your${CClear}"
echo -e "${InvGreen} ${CClear} backups and reclaim disk space, but also gives you more flexibility on the length of${CClear}"
echo -e "${InvGreen} ${CClear} time you can keep your backups. Purging backups can be run manually from the setup${CClear}"
echo -e "${InvGreen} ${CClear} menu, and gives you the ability to see which backups will be purged before they are${CClear}"
echo -e "${InvGreen} ${CClear} deleted permanently. It will also run automatically when calling BACKUPMON with the${CClear}"
echo -e "${InvGreen} ${CClear} '-backup' switch. If you run 'sh backupmon.sh -backup', it will complete a backup,${CClear}"
echo -e "${InvGreen} ${CClear} and then run an auto purge based on your criteria. Running 'sh backupmon.sh' without${CClear}"
echo -e "${InvGreen} ${CClear} the '-backup' switch will run a normal backup without an auto purge, even if purge is${CClear}"
echo -e "${InvGreen} ${CClear} enabled below.${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} PLEASE NOTE: If there are any backups you wish to save permanently, please move these"
echo -e "${InvGreen} ${CClear} to a SAFE, separate folder that BACKUPMON does not interact with."
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} (No=0, Yes=1) (Default: 0)"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
if [ "$PURGE" == "0" ]; then PURGEDP="No"; else PURGEDP="Yes"; fi
echo -e "${CClear}Current Purge Perpetual Backups Option?: ${CGreen}$PURGEDP"; echo -e "${CClear}"
read -p 'Purge Perpetual Backups? (0/1): ' PURGE1
if [ "$PURGE1" == "" ] || [ -z "$PURGE1" ]; then PURGE=0; else PURGE="$PURGE1"; fi # Using default value on enter keypress
if [ "$PURGE" == "0" ]; then
PURGELIMIT=0
elif [ "$PURGE" == "1" ]; then
echo ""; echo ""
echo -e "${InvGreen} ${InvDkGray}${CWhite} BACKUPMON - Keeping Perpetual Backups ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} How many days would you like to keep your perpetual backups? Example (in days): 90${CClear}"
echo -e "${InvGreen} ${CClear} This would cause all perpetual backups older than 90 days would be permanently${CClear}"
echo -e "${InvGreen} ${CClear} deleted.${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} PLEASE NOTE: If there are any backups you wish to save permanently, please move${CClear}"
echo -e "${InvGreen} ${CClear} these to a SAFE, separate folder that BACKUPMON does not interact with.${CClear}"