-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathraspiBackupRegression.sh
executable file
·181 lines (155 loc) · 5.84 KB
/
raspiBackupRegression.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
#!/bin/bash
#######################################################################################################################
#
# raspiBackup regression test
#
#######################################################################################################################
#
# Copyright (c) 2013-2025 framp at linux-tips-and-tricks dot de
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#######################################################################################################################
SCRIPT_DIR=$( cd $( dirname ${BASH_SOURCE[0]}); pwd | xargs readlink -f)
source $SCRIPT_DIR/constants.sh
SMARTRECYCLE_TEST=1
BACKUP_TEST=1
RESTORE_TEST=1
EMAIL_NOTIFICATION=1
ATTACH_LOG=1
MESSAGE_TEST=1
UNIT_TEST=1
SHELLCHECK_TEST=1
#ENVIRONMENTS_TO_TEST="sd usb sdbootonly"
ENVIRONMENTS_TO_TEST="sd usb"
TYPES_TO_TEST="dd tar rsync"
MODES_TO_TEST="n p"
BOOTMODE_TO_TEST="d t"
if [[ "$1" == "-h" ]]; then
echo "Environments types modes bootmodes"
exit 42
elif (( $# > 1 )); then
ENVIRONMENTS_TO_TEST=${1:-"$ENVIRONMENTS_TO_TEST"}
TYPES_TO_TEST=${2:-"$TYPES_TO_TEST"}
MODES_TO_TEST=${3:-"$MODES_TO_TEST"}
BOOTMODE_TO_TEST=${4:-"$BOOTMODE_TO_TEST"}
fi
NOTIFY_EMAIL="$(<email.conf)"
function d() {
echo "$(date +%Y%m%d-%H%M%S)"
}
function standardTest() {
local rc
if (( $BACKUP_TEST )); then
echo "$(d) Starting BACKUP $1 $2 $3 $4" >> $LOG_COMPLETED
./raspiBackupTest.sh "$1" "$2" "$3" "$4"
rc=$?
echo "@@@============================================================" >> $LOG_REGRESSION
echo "@@@================== BACKUP raspiBackup.log ==================" >> $LOG_REGRESSION
echo "@@@============================================================" >> $LOG_REGRESSION
cat raspiBackup.log >> $LOG_REGRESSION
echo "@@@================================================================" >> $LOG_REGRESSION
echo "@@@================== BACKUP raspiBackupTest.log ==================" >> $LOG_REGRESSION
echo "@@@================================================================" >> $LOG_REGRESSION
cat raspiBackupTest.log >> $LOG_REGRESSION
if [[ $rc != 0 ]]; then
echo "$(d) Failed BACKUP $1 $2 $3 $4" >> $LOG_COMPLETED
echo "??? Backup regression test failed"
echo "End: $endTime" | mailx -s "??? Backup regression test failed" "$NOTIFY_EMAIL"
exit 127
fi
echo "$(d) Completed BACKUP $1 $2 $3 $4" >> $LOG_COMPLETED
if (( $RESTORE_TEST )); then
echo "$(d) Starting RESTORE $1 $2 $3 $4" >> $LOG_COMPLETED
./raspiRestoreTest.sh
rc=$?
echo "@@@=============================================================" >> $LOG_REGRESSION
echo "@@@================== RESTORE raspiBackup.log ==================" >> $LOG_REGRESSION
echo "@@@=============================================================" >> $LOG_REGRESSION
cat raspiBackup.log >> $LOG_REGRESSION
echo "@@@=================================================================" >> $LOG_REGRESSION
echo "@@@================== RESTORE raspiBackupTest.log ==================" >> $LOG_REGRESSION
echo "@@@=================================================================" >> $LOG_REGRESSION
cat raspiRestoreTest.log >> $LOG_REGRESSION
if [[ $rc != 0 ]]; then
echo "$(d) Failed RESTORE $1 $2 $3 $4" >> $LOG_COMPLETED
echo "??? Restore regression test failed"
echo "End: $endTime" | mailx -s "??? Restore regression test failed" "$NOTIFY_EMAIL"
exit 127
fi
fi
echo "$(d) Completed RESTORE $1 $2 $3 $4" >> $LOG_COMPLETED
losetup -D
fi
}
function smartRecycleTest() {
local rc
./raspiBackup7412Test.sh
rc=$?
echo "@@@=====================================================================" >> $LOG_REGRESSION
echo "@@@================== RECYCLE raspiBackup7412Test.log ==================" >> $LOG_REGRESSION
echo "@@@=====================================================================" >> $LOG_REGRESSION
cat raspiBackup72412Test.log >> $LOG_REGRESSION
if [[ $rc != 0 ]]; then
echo "??? 7412 regression test failed" >> $LOG_COMPLETED
echo "End: $endTime" | mailx -s "??? 7412 regression test failed" "$NOTIFY_EMAIL"
exit 127
fi
}
if (( $UID != 0 )); then
echo "Call me as root"
exit 1
fi
rm *.log >/dev/null
startTime=$(date +%Y-%M-%d/%H:%m:%S)
echo "Start: $startTime"
if (( $EMAIL_NOTIFICATION )); then
echo "Start: $startTime" | mailx -s "--- Backup regression started" "$NOTIFY_EMAIL"
fi
if (( $MESSAGE_TEST )); then
if ! ./checkMessages.sh; then
exit
fi
fi
if (( $SMARTRECYCLE_TEST )); then
if ! smartRecycleTest; then
exit
fi
fi
if (( $UNIT_TEST )); then
if ! ./unitTests.sh; then
exit
fi
fi
if (( SHELLCHECK_TEST )); then
if ! ./shellcheck.sh; then
exit
fi
fi
for environment in $ENVIRONMENTS_TO_TEST; do
for mode in $MODES_TO_TEST; do
for type in $TYPES_TO_TEST; do
[[ $type =~ dd && $mode == "p" ]] && continue # dd not supported for -P
for bootmode in $BOOTMODE_TO_TEST; do
[[ $bootmode == "t" && ( $type =~ dd || $mode == "p" ) ]] && continue # -B+ not supported for -P and dd
standardTest "$environment" "$type" "$mode" "$bootmode"
done
done
done
done
(( $ATTACH_LOG )) && attach="-A $LOG_COMPLETED"
echo ":-) Raspibackup regression test finished successfully"
if (( $EMAIL_NOTIFICATION )); then
echo "" | mailx -s ":-) Raspibackup regression test finished sucessfully" $attach "$NOTIFY_EMAIL"
fi