-
Notifications
You must be signed in to change notification settings - Fork 2
/
bmm-media_backup
executable file
·179 lines (169 loc) · 5.34 KB
/
bmm-media_backup
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
#!/bin/bash
## rsync script to backup all 'goodies'
## requires source and destination folders
## set up in .env file. --help for more info.
## Tarso Galvao 03/04/23 Debian 11
#load enviroment variables
if [ -f $HOME/bmm/.env ]; then
. $HOME/bmm/.env
else
echo -e "FATAL ERROR: .env not found.$\n
Use bmm-setup_enviroment to create one.\nAborting...";
exit 1;
fi
#TODO: log stuff
#backup task ($1-source $2-dest $3-echo name)
execute_backup (){
local source_dir="$1"
local dest_dir="$2"
local backup_name="$3"
# Clear screen and show banner
clear && echo ''
if ! command -v $BANNER >> /dev/null; then echo -e "${WARN}BASH MEDIA MANAGER${NC}"; else eval $BANNER; fi
echo -e "${HEAD}Media Backup${NC}"
echo '----------------------------------------------------------'
echo -e "Backing up: ${OK}$backup_name${NC}"
#check for rsync
dep_check rsync;
#check if folders exist
dir_check "$source_dir";
dir_check "$dest_dir";
echo '----------------------------------------------------------'
# User reaction timer
echo -e "Now running: ${ERROR}rsync -avz ${OK}"$source_dir"* ${WARN}"$dest_dir" ${ERROR}--delete${NC}\n"
echo -e "Press ${WARN}"Control + C"${NC} to abort.\n"
for (( i=3; i>0; i--)); do sleep 1 & printf " $i \r"; wait; done
# Start backup sync
if [ "$4" == '--menu' ]; then
rsync -avzP "$source_dir"* "$dest_dir" --delete | dialog --colors --no-lines --backtitle "\Z7Bash Media Manager" --progressbox 42 76;
dialog --colors --no-lines \
--backtitle "\Z7Bash Media Manager" \
--infobox "Task complete." 3 19
read
else
rsync -avz "$source_dir"* "$dest_dir" --delete
echo -e "\nBackup complete."
fi
}
# --no-gui interactive mode menu
nogui_menu (){
echo -e 'Choose media to backup: (1-7)'
select bkp in Series Movies Concerts Audio Stand-up ALL Quit
do
case $bkp in
"Series")
execute_backup "$SERIESROOT" "$SERIESBACKUP" "SERIES"
break;;
"Movies")
execute_backup "$MOVIESROOT" "$MOVIESBACKUP" "MOVIES"
break;;
"Concerts")
execute_backup "$CONCERTSROOT" "$CONCERTSBACKUP" "CONCERTS"
break;;
"Audio")
execute_backup "$AUDIOROOT" "$AUDIOBACKUP" "AUDIO"
break;;
"Stand-up")
execute_backup "$STANDUPROOT" "$STANDUPBACKUP" "STAND-UP"
break;;
"ALL")
execute_backup "$SERIESROOT" "$SERIESBACKUP" "SERIES"
execute_backup "$MOVIESROOT" "$MOVIESBACKUP" "MOVIES"
execute_backup "$CONCERTSROOT" "$CONCERTSBACKUP" "CONCERTS"
execute_backup "$STANDUPROOT" "$STANDUPBACKUP" "STAND-UP"
execute_backup "$AUDIOROOT" "$AUDIOBACKUP" "AUDIO"
break;;
"Quit")
exit 1
;;
*)
echo -e 'Not a valid choice. Use (1-7)';;
esac
done
}
## dialog interactive move menu (checklist)
main_menu () {
checklist=(dialog --no-lines --separate-output --colors \
--backtitle "\Z7Bash Media Manager" \
--checklist "Select a preset: (use spacebar)" 22 0 16)
options=(1 "Audio $AUDIOROOT -> $AUDIOBACKUP" off
2 "Series $SERIESROOT -> $SERIESBACKUP" off
3 "Movies $MOVIESROOT -> $MOVIESBACKUP" off
4 "Concerts $CONCERTSROOT -> $CONCERTSBACKUP" off
5 "Stand-up $STANDUPROOT -> $STANDUPBACKUP" off)
choices=$("${checklist[@]}" "${options[@]}" 2>&1 >/dev/tty)
clear
for choice in $choices
do
case $choice in
1)
execute_backup "$AUDIOROOT" "$AUDIOBACKUP" "AUDIO" --menu;
;;
2)
execute_backup "$SERIESROOT" "$SERIESBACKUP" "SERIES" --menu;
;;
3)
execute_backup "$MOVIESROOT" "$MOVIESBACKUP" "MOVIES" --menu;
;;
4)
execute_backup "$CONCERTSROOT" "$CONCERTSBACKUP" "CONCERTS" --menu;
;;
5)
execute_backup "$STANDUPROOT" "$STANDUPBACKUP" "STAND-UP" --menu;
;;
esac
done
if [ $? -ne 1 ]; then
clear && eval bmm-launcher; exit 0;
else
clear && eval bmm-launcher; exit 1;
fi
}
## check command arguements
print_help() {
if ! command -v $BANNER >> /dev/null; then echo -e "${WARN}BASH MEDIA MANAGER${NC}"; else eval $BANNER; fi
echo -e "${HEAD}Media Backup"
echo -e "${OK}Backup manager for server media.\n${NC}"
echo -e "Use with no arguments to enter the GUI."
echo -e "Usage: bmm-media_backup [-arg] [--arg]\n"
echo -e " -s [--series] -> Backup series library."
echo -e " -m [--movies] -> Backup movies library."
echo -e " -c [--concerts] -> Backup concerts library."
echo -e " -a [--audio] -> Backup audio library."
echo -e " -u [--stand-up] -> Backup stand-up library"
echo -e " -f [--full] -> Backup all libraries."
echo -e " -n [--no-gui] -> Interactive mode without a GUI.\n"
echo -e " -h [--help] -> Shows this screen."
}
case "$1" in
'-s' | '--series')
echo '1' | nogui_menu
;;
'-m' | '--movies')
echo '2' | nogui_menu
;;
'-c' | '--concerts')
echo '3' | nogui_menu
;;
'-a' | '--audio')
echo '4' | nogui_menu
;;
'-u' | '--stand-up')
echo '5' | nogui_menu
;;
'-f' | '--full')
echo '6' | nogui_menu
;;
'-n' | '--no-gui')
if ! command -v $BANNER >> /dev/null; then echo -e "${WARN}BASH MEDIA MANAGER${NC}"; else eval $BANNER; fi
echo -e "${OK}Media Backup${NC}"
echo -e "${WARN}Entering no-GUI interactive mode${NC}"
nogui_menu
;;
'-h' | '--help')
print_help
;;
*)
main_menu
;;
esac