]> git.sur5r.net Git - bacula/bacula/blob - regress/scripts/functions
Check Restore Error status + fix virtual-backup-test script
[bacula/bacula] / regress / scripts / functions
1 #
2 # A set of useful functions to be sourced in each test
3 #
4
5
6 start_test()
7 {
8    # Turn off email
9    outf="tmp/sed_tmp"
10    echo "s%  mail =%# mail = %g" >${outf}
11    echo "s%  operator =%# operator =%g" >>${outf}
12    cp bin/bacula-dir.conf tmp/1
13    sed -f ${outf} tmp/1 >bin/bacula-dir.conf
14    echo " "
15    echo " "
16    echo " === Starting $TestName at `date +%R:%S` ==="
17    echo " === Starting $TestName at `date +%R:%S` ===" >>working/log
18    echo " "
19    export zstat
20 }
21
22 require_root()
23 {
24 MUID=`/usr/bin/id | awk -F= '{print $2}' | awk -F\( '{print $1}'`
25 if [ $MUID != 0 ] ; then
26    echo " "
27    echo "You must be root to run this test."
28    echo "  ===== !!!! $TestName not run at `date +%R:%S` ==="
29    echo "  ===== !!!! $TestName not run at `date +%R:%S` !!!! ===== " >>test.out
30    echo " "
31    exit 1
32 fi
33 }
34
35 require_tape_drive() 
36 {
37 if test x${TAPE_DRIVE} = x/dev/null ; then
38    echo "$TestName test needs a tape drive, but has none."
39    exit 1
40 fi
41 }
42
43 require_second_drive()
44
45 if test x${TAPE_DRIVE1} = x/dev/null ; then
46    echo "$JobName needs second drive, but has none."
47    exit 1
48 fi
49 }
50
51 require_autochanger()
52 {
53 if test x${AUTOCHANGER} = x/dev/null ; then
54    echo "$TestName needs an autochanger, but has none."
55    exit 1
56 fi
57 }
58
59 require_vtape() 
60 {
61 if test x${USE_VTAPE} = x ; then
62    echo "$TestName test needs the vtape driver."
63    exit 0
64 fi
65 }
66
67 require_linux()
68 {
69 os=`uname`
70 if [ $os != 'Linux' ]; then
71    echo "This test $TestName runs only on Linux"
72    exit 0
73 fi
74 }
75
76 skip_if_no_autochanger()
77 {
78 if test x${AUTOCHANGER} = x/dev/null ; then
79    echo "$TestName test skipped. No autochanger."
80    exit
81 fi
82 }
83
84 set_debug()
85 {
86    debug=$1
87    if test "$debug" -eq 1 ; then
88      out="tee"
89    else
90      out="output"
91    fi
92
93
94 print_debug()
95 {
96    if test "$debug" -eq 1 ; then
97      echo $*
98    fi
99 }
100
101 run_bacula()
102 {
103    debug_wait
104    zstat=0
105    if test "$debug" -eq 1 ; then
106      bin/bacula-ctl-sd start
107      bin/bacula-ctl-fd start
108      bin/bacula-ctl-dir start
109      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
110      return $?
111    else
112      bin/bacula start 2>&1 >/dev/null
113      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
114      return $?
115    fi
116 }
117
118 run_bconsole()
119 {
120    if test "$debug" -eq 1 ; then
121      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
122    else
123      cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf  2>&1 >/dev/null
124    fi
125 }
126
127 run_btape()
128 {
129    if test "$debug" -eq 1 ; then
130      cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 | tee tmp/log1.out
131    else
132      cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 2>&1 >tmp/log1.out
133    fi
134 }
135
136 run_bscan()
137 {
138    if test "$debug" -eq 1 ; then
139       bin/bscan $* | tee tmp/log.out
140    else
141       bin/bscan $* 2>&1 >/dev/null
142    fi
143 }
144
145 bscan_libdbi()
146 {   
147    B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
148    B_D=`echo $B | awk '{print $3}'`
149    B_t=`echo $B | awk '{print $6}'`
150    B_p=`echo $B | awk '{print $9}'`
151
152    BSCANLIBDBI="${LIBDBI:+1}"
153                 
154    if test "$BSCANLIBDBI" = "1" ; then
155       BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
156    else
157       BSCANLIBDBI=" "
158    fi
159 }
160
161 stop_bacula()
162 {
163    bin/bacula stop 2>&1 >/dev/null
164 }
165
166 check_for_zombie_jobs()
167 {
168    scripts/check_for_zombie_jobs $*
169 }
170
171 change_jobname()
172 {
173    if test $# -eq 1; then
174       oldname=NightlySave
175       newname=$1
176    else
177       oldname=$1
178       newname=$2
179    fi
180    rm -f bin/1
181    mv bin/bacula-dir.conf bin/1
182    echo "s%${oldname}%${newname}%g" >tmp/1
183    sed -f tmp/1 bin/1 >bin/bacula-dir.conf
184 #  echo "Job ${oldname} changed to ${newname}"
185 }
186
187 check_two_logs()
188 {
189    grep "^  Termination: *Backup OK" tmp/log1.out 2>&1 >/dev/null
190    bstat=$?
191    grep "^  Termination: .*Backup Error" tmp/log1.out 2>&1 >/dev/null
192    if test $? -eq 0; then
193       bstat=2
194    fi
195    grep "^  Termination: *Restore OK" tmp/log2.out 2>&1 >/dev/null
196    rstat=$?
197    grep "^  Termination: .*Restore Error" tmp/log2.out 2>&1 >/dev/null
198    if test $? -eq 0; then
199       rstat=2
200    fi
201    grep "^  Termination: *Restore OK -- warning file count mismatch" tmp/log2.out 2>&1 >/dev/null
202    if test $? -eq 0; then
203       rstat=3
204    fi
205    grep "^  Termination: .*Verify Differences" tmp/log2.out 2>&1 >/dev/null
206    if test $? -eq 0; then
207       rstat=4
208    fi
209 }
210
211 check_restore_diff()
212 {
213    if test "$debug" -eq 1 ; then
214       diff -ur build tmp/bacula-restores${cwd}/build
215    else 
216       diff -r build tmp/bacula-restores${cwd}/build 2>&1 >/dev/null
217    fi
218    dstat=$?
219 }
220
221 check_restore_tmp_build_diff()
222 {
223    if test "$debug" -eq 1 ; then
224       diff -ur tmp/build tmp/bacula-restores${cwd}/tmp/build
225    else
226       diff -r tmp/build tmp/bacula-restores${cwd}/tmp/build 2>&1 >/dev/null
227    fi
228    dstat=$?
229 }
230
231 end_test()
232 {
233    if [ $zstat != 0 ] ; then
234       echo " "
235       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
236       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
237       echo "   Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
238       echo " "
239       exit 1
240    fi
241    if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
242       echo " "
243       echo " "
244       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
245       echo "  !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
246       if [ $bstat != 0 -o $rstat != 0 ] ; then
247          echo "  !!!!! Bad termination status       !!!!! "
248          echo "  !!!!! Bad termination status       !!!!! " >>test.out
249       else
250          echo "  !!!!! Restored files differ          !!!!! "
251          echo "  !!!!! Restored files differ          !!!!! " >>test.out
252       fi
253       echo "   Status: backup=$bstat restore=$rstat diff=$dstat"
254       echo "   Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
255       echo " "
256       exit 1
257    else
258       echo "  ===== $TestName OK `date +%R:%S` ===== "
259       echo "  ===== $TestName OK `date +%R:%S` ===== " >>test.out
260       if test "$debug" -eq 0 ; then
261          scripts/cleanup
262       fi
263    fi
264 }
265
266 copy_tape_confs()
267 {
268    scripts/copy-tape-confs
269    scripts/cleanup-tape
270 }
271
272 copy_test_confs()
273 {
274    scripts/copy-test-confs
275    scripts/cleanup
276 }
277
278 debug_wait()
279 {
280   if test "x${REGRESS_WAIT}" = "x1"; then
281      echo "Start Bacula under debugger and enter anything when ready ..."
282      read a
283   fi
284 }
285
286 init_slot()
287 {
288    DRIVE=$1
289    SLOT=$2
290    if test -n "$DRIVE" -a -n "$SLOT"; then
291       if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
292          dir=`dirname $DRIVE`
293          touch $dir/slot$SLOT
294       fi
295    fi
296 }
297
298 init_drive()
299 {
300   if test a$USE_VTAPE = a; then
301     mt -f $1 rewind
302     mt -f $1 weof
303   else
304     cp /dev/null $1
305   fi
306 }
307
308 rewind_drive()
309 {
310   if test a$USE_VTAPE = a; then
311     mt -f $1 rewind
312   fi
313 }
314
315 load_slot1() 
316 {
317 # Get a tape from slot1
318 slot=`bin/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
319 case $slot in
320  0)
321     bin/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
322     slot=$SLOT1
323     ;;
324  $SLOT1)
325     slot=$SLOT1
326     ;;
327  *)
328     rewind_drive ${TAPE_DRIVE}
329     bin/$MTX ${AUTOCHANGER} unload $slot  ${TAPE_DRIVE} $DRIVE1
330     bin/$MTX ${AUTOCHANGER} load   $SLOT1 ${TAPE_DRIVE} $DRIVE1
331     slot=$SLOT1
332     ;;
333 esac
334 }
335
336 #
337 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
338 #    if 2, load 1; if 0 load 1
339 #
340 load_other_slot()
341 {
342 rewind_drive ${TAPE_DRIVE}
343 case $1 in
344  0)
345     bin/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
346     slot=1
347     ;;
348  $SLOT1)
349     bin/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
350     bin/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
351     slot=2
352     ;;
353  $SLOT2)
354     bin/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
355     bin/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
356     slot=1
357     ;;
358  *)
359     echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
360     exit 1
361     ;;
362 esac
363 }
364
365
366 # Save current directory
367 cwd=`pwd`
368 if test "x${REGRESS_DEBUG}" = "x1"; then
369    set_debug 1
370 else
371    set_debug 0
372 fi
373
374 # Source the configuration variables
375 . ${cwd}/config
376
377 db_name=${db_name:-"regress"}
378 db_user=${db_user:-"regress"}
379 db_password=${db_password:-""}
380
381 CLIENT=${HOST}-fd
382
383 if [ x$USE_VTAPE = xyes ]; then
384    mkdir -p $cwd/working/ach
385    SLOT1=1
386    SLOT2=2
387    TAPE_DRIVE=$cwd/working/ach/drive1
388    TAPE_DRIVE1=$cwd/working/ach/drive1
389    AUTOCHANGER=$cwd/working/ach/config
390    AUTOCHANGER_SCRIPT=disk-changer
391    DRIVE1=0
392    DRIVE2=1
393    cat > $AUTOCHANGER <<EOF
394 maxdrive=2
395 maxslot=10
396 EOF
397 fi
398
399 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}