-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy path01-check_normal-operation.sh
executable file
·318 lines (222 loc) · 10.4 KB
/
01-check_normal-operation.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
#!/bin/bash -e
#!/usr/bin/env bash
ERROR=0
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. "${DIR}/config"
echo "##########################################################################################"
echo "#"
echo "# 1. C H E C K I N G N O R M A L O P E R A T I O N"
echo "#"
echo "##########################################################################################"
echo
echo
echo "--------------------------------------------------------------------------------"
echo "-"
echo "- 1.1 Test mode"
echo "-"
echo "--------------------------------------------------------------------------------"
echo
echo "----------------------------------------"
echo " 1.1.1 Test mode first run"
echo "----------------------------------------"
echo "\$ ${txtblu}${CMD_TEST}${txtrst}"
mds_remove_logfiles
mds_remove_datadir
if ! eval "${CMD_TEST}"; then ERROR=$((ERROR+1)); echo "${txtpur}===> [FAILED]${txtrst}"; else echo "${txtgrn}===> [OK]${txtrst}"; fi
echo
echo "----------------------------------------"
echo " 1.1.2 Test mode second run"
echo "----------------------------------------"
echo "\$ ${txtblu}${CMD_TEST}${txtrst}"
mds_recreate_datadir
if ! eval "${CMD_TEST}"; then ERROR=$((ERROR+1)); echo "${txtpur}===> [FAILED]${txtrst}"; else echo "${txtgrn}===> [OK]${txtrst}"; fi
echo
echo
echo "--------------------------------------------------------------------------------"
echo "-"
echo "- 1.2 Normal mode"
echo "-"
echo "--------------------------------------------------------------------------------"
echo
echo "----------------------------------------"
echo " 1.2.1 Normal mode first run"
echo "----------------------------------------"
echo "\$ ${txtblu}${CMD_VERB}${txtrst}"
mds_remove_logfiles
mds_remove_datadir
if eval "${CMD_VERB}"; then ERROR=$((ERROR+1)); echo "${txtpur}===> [FAILED] Unexpected OK${txtrst}"; else echo "${txtgrn}===> [OK] Expected not OK${txtrst}"; fi
echo
echo "----------------------------------------"
echo " 1.2.2 Normal mode second run"
echo "----------------------------------------"
echo "\$ ${txtblu}${CMD_VERB}${txtrst}"
mds_recreate_datadir
if ! eval "${CMD_VERB}"; then ERROR=$((ERROR+1)); echo "${txtpur}===> [FAILED]${txtrst}"; else echo "${txtgrn}===> [OK]${txtrst}"; fi
echo
echo "----------------------------------------"
echo " 1.2.3 Normal mode third run (del files)"
echo "----------------------------------------"
echo "\$ ${txtblu}${CMD_VERB}${txtrst}"
mds_recreate_datadir
sudo touch -a -m -t 201512180130.09 ${_INSTALL_PREFIX}/var/mysqldump-secure/delete-me-1.txt && sudo chmod 400 ${_INSTALL_PREFIX}/var/mysqldump-secure/delete-me-1.txt
sudo touch -a -m -t 201512180130.09 ${_INSTALL_PREFIX}/var/mysqldump-secure/delete-me-2.txt && sudo chmod 400 ${_INSTALL_PREFIX}/var/mysqldump-secure/delete-me-2.txt
sudo touch -a -m -t 201512180130.09 ${_INSTALL_PREFIX}/var/mysqldump-secure/delete-me-3.txt && sudo chmod 400 ${_INSTALL_PREFIX}/var/mysqldump-secure/delete-me-3.txt
sudo touch -a -m -t 201512180130.09 ${_INSTALL_PREFIX}/var/mysqldump-secure/delete-me-4.txt && sudo chmod 400 ${_INSTALL_PREFIX}/var/mysqldump-secure/delete-me-4.txt
sudo ls -la ${_INSTALL_PREFIX}/var/mysqldump-secure/
if ! eval "${CMD_VERB}"; then ERROR=$((ERROR+1)); echo "${txtpur}===> [FAILED]${txtrst}"; else echo "${txtgrn}===> [OK]${txtrst}"; fi
sudo ls -la ${_INSTALL_PREFIX}/var/mysqldump-secure/
echo
echo
echo "--------------------------------------------------------------------------------"
echo "-"
echo "- 1.3 Cron mode (--cron)"
echo "-"
echo "--------------------------------------------------------------------------------"
echo "\$ ${txtblu}${CMD_CRON}${txtrst}"
echo
echo "----------------------------------------"
echo " 1.3.1 Cron mode first run"
echo "----------------------------------------"
mds_remove_logfiles
mds_remove_datadir
if eval "${CMD_CRON}"; then ERROR=$((ERROR+1)); echo "${txtpur}===> [FAILED] Unexpected OK${txtrst}"; else echo "${txtgrn}===> [OK] Expected not OK${txtrst}"; fi
echo
echo "----------------------------------------"
echo " 1.3.2 Cron mode second run"
echo "----------------------------------------"
echo "\$ ${txtblu}${CMD_CRON}${txtrst}"
mds_recreate_datadir
if ! eval "${CMD_CRON}"; then ERROR=$((ERROR+1)); echo "${txtpur}===> [FAILED]${txtrst}"; else echo "${txtgrn}===> [OK]${txtrst}"; fi
echo
echo "----------------------------------------"
echo " 1.3.3 Cron mode third run (del files)"
echo "----------------------------------------"
echo "\$ ${txtblu}${CMD_CRON}${txtrst}"
mds_recreate_datadir
sudo touch -a -m -t 201512180130.09 ${_INSTALL_PREFIX}/var/mysqldump-secure/delete-me-1.txt
sudo touch -a -m -t 201512180130.09 ${_INSTALL_PREFIX}/var/mysqldump-secure/delete-me-2.txt
sudo touch -a -m -t 201512180130.09 ${_INSTALL_PREFIX}/var/mysqldump-secure/delete-me-3.txt
sudo touch -a -m -t 201512180130.09 ${_INSTALL_PREFIX}/var/mysqldump-secure/delete-me-4.txt
if ! eval "${CMD_CRON}"; then ERROR=$((ERROR+1)); echo "${txtpur}===> [FAILED]${txtrst}"; else echo "${txtgrn}===> [OK]${txtrst}"; fi
echo
echo
echo "--------------------------------------------------------------------------------"
echo "-"
echo "- 1.4 cmd arguments"
echo "-"
echo "--------------------------------------------------------------------------------"
echo
echo "----------------------------------------"
echo " 1.4.1 --help"
echo "----------------------------------------"
echo "\$ ${txtblu}${CMD_HELP}${txtrst}"
# MUST PASS
mds_recreate_datadir
if ! eval "${CMD_HELP}"; then ERROR=$((ERROR+1)); echo "${txtpur}===> [FAILED]${txtrst}"; else echo "${txtgrn}===> [OK]${txtrst}"; fi
echo
echo "----------------------------------------"
echo " 1.4.2 --conf (does not exist)"
echo "----------------------------------------"
echo "\$ ${txtblu}${CMD_VERB} --conf=${_INSTALL_PREFIX}/etc/nothere${txtrst}"
# MUST FAIL
mds_recreate_datadir
if eval "${CMD_VERB} --conf=${_INSTALL_PREFIX}/etc/nothere"; then ERROR=$((ERROR+1)); echo "${txtpur}===> [FAILED]${txtrst}"; else echo "${txtgrn}===> [OK] Expected error${txtrst}"; fi
echo
echo "----------------------------------------"
echo " 1.4.3 --conf (random file)"
echo "----------------------------------------"
echo "\$ ${txtblu}${CMD_VERB} --conf=${_INSTALL_PREFIX}/etc/mysqldump-secure.cnf${txtrst}"
# MUST FAIL
mds_recreate_datadir
if eval "${CMD_VERB} --conf=${_INSTALL_PREFIX}/etc/mysqldump-secure.cnf"; then ERROR=$((ERROR+1)); echo "${txtpur}===> [FAILED]${txtrst}"; else echo "${txtgrn}===> [OK] Expected error${txtrst}"; fi
echo
echo "----------------------------------------"
echo " 1.4.4 wrong argument"
echo "----------------------------------------"
echo "\$ ${txtblu}${CMD_VERB} --wrong${txtrst}"
# MUST FAIL
mds_recreate_datadir
if eval "${CMD_VERB} --wrong"; then ERROR=$((ERROR+1)); echo "${txtpur}===> [FAILED]${txtrst}"; else echo "${txtgrn}===> [OK] Expected error${txtrst}"; fi
echo
echo
echo "--------------------------------------------------------------------------------"
echo "-"
echo "- 1.5 Importing files back into Database"
echo "-"
echo "--------------------------------------------------------------------------------"
echo
echo "----------------------------------------"
echo " 1.5.1 Compressed & Encrypted"
echo "----------------------------------------"
echo
echo "---------- CRON MODE ----------"
CMD="${CMD_CRON}"
if ! check "1" "1" "PASS" "0" "" "1" "1" "0" "4" "${CMD}"; then ERROR=$((ERROR+1)); fi
echo "---------- NORMAL MODE ----------"
CMD="${CMD_NORM}"
if ! check "1" "1" "PASS" "0" "" "1" "1" "1" "4" "${CMD}"; then ERROR=$((ERROR+1)); fi
echo "---------- NORMAL MODE VERBOSE ----------"
CMD="${CMD_VERB}"
if ! check "1" "1" "PASS" "0" "" "1" "1" "1" "4" "${CMD}"; then ERROR=$((ERROR+1)); fi
echo
echo "----------------------------------------"
echo " 1.5.2 Encrypted"
echo "----------------------------------------"
echo
sed_change_config_file "^COMPRESS=1" "COMPRESS=0"
echo "---------- CRON MODE ----------"
CMD="${CMD_CRON}"
if ! check "1" "1" "PASS" "0" "" "1" "1" "0" "3" "${CMD}"; then ERROR=$((ERROR+1)); fi
echo "---------- NORMAL MODE ----------"
CMD="${CMD_NORM}"
if ! check "1" "1" "PASS" "0" "" "1" "1" "1" "3" "${CMD}"; then ERROR=$((ERROR+1)); fi
echo "---------- NORMAL MODE VERBOSE ----------"
CMD="${CMD_VERB}"
if ! check "1" "1" "PASS" "0" "" "1" "1" "1" "3" "${CMD}"; then ERROR=$((ERROR+1)); fi
sed_change_config_file "^COMPRESS=0" "COMPRESS=1"
echo
echo "----------------------------------------"
echo " 1.5.3 Compressed"
echo "----------------------------------------"
echo
sed_change_config_file "^ENCRYPT=1" "ENCRYPT=0"
echo "---------- CRON MODE ----------"
CMD="${CMD_CRON}"
if ! check "1" "1" "PASS" "0" "" "1" "1" "0" "2" "${CMD}"; then ERROR=$((ERROR+1)); fi
echo "---------- NORMAL MODE ----------"
CMD="${CMD_NORM}"
if ! check "1" "1" "PASS" "0" "" "1" "1" "1" "2" "${CMD}"; then ERROR=$((ERROR+1)); fi
echo "---------- NORMAL MODE VERBOSE ----------"
CMD="${CMD_VERB}"
if ! check "1" "1" "PASS" "0" "" "1" "1" "1" "2" "${CMD}"; then ERROR=$((ERROR+1)); fi
sed_change_config_file "^ENCRYPT=0" "ENCRYPT=1"
echo
echo "----------------------------------------"
echo " 1.5.4 Plain"
echo "----------------------------------------"
echo
sed_change_config_file "^COMPRESS=1" "COMPRESS=0"
sed_change_config_file "^ENCRYPT=1" "ENCRYPT=0"
echo "---------- CRON MODE ----------"
CMD="${CMD_CRON}"
if ! check "1" "1" "PASS" "0" "" "1" "1" "0" "1" "${CMD}"; then ERROR=$((ERROR+1)); fi
echo "---------- NORMAL MODE ----------"
CMD="${CMD_NORM}"
if ! check "1" "1" "PASS" "0" "" "1" "1" "1" "1" "${CMD}"; then ERROR=$((ERROR+1)); fi
echo "---------- NORMAL MODE VERBOSE ----------"
CMD="${CMD_VERB}"
if ! check "1" "1" "PASS" "0" "" "1" "1" "1" "1" "${CMD}"; then ERROR=$((ERROR+1)); fi
sed_change_config_file "^ENCRYPT=0" "ENCRYPT=1"
sed_change_config_file "^COMPRESS=0" "COMPRESS=1"
echo
echo
if [ "$ERROR" = "0" ]; then
echo "${txtgrn}@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@${txtrst}"
echo "${txtgrn}@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ [01] SUCCESS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@${txtrst}"
echo "${txtgrn}@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@${txtrst}"
else
echo "${txtpur}@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@${txtrst}"
echo "${txtpur}@@@@@@@@@@@@@@@@@@@@@@@@ [01] FAILED: ${ERROR} Errors @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@${txtrst}"
echo "${txtpur}@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@${txtrst}"
fi
exit $ERROR