]> git.sur5r.net Git - bacula/bacula/blob - regress/scripts/functions
Make out of freespace non-fatal for removable devices -- i.e. behaves like tape
[bacula/bacula] / regress / scripts / functions
1 #
2 # Copyright (C) 2000-2017 Kern Sibbald
3 # License: BSD 2-Clause; see file LICENSE-FOSS
4 #
5 # A set of useful functions to be sourced in each test
6 #
7
8 . ./config
9
10 check_encoding()
11 {
12    if ${bin}/bacula-dir -d50 -t -c ${conf}/bacula-dir.conf 2>&1 | grep 'Wanted SQL_ASCII, got UTF8' >/dev/null ; then
13        echo "Found database encoding problem, please modify the database encoding (SQL_ASCII)"
14        exit 1
15    fi
16 }
17
18 start_test()
19 {
20    check_encoding
21    rm -rf ${working}/@*
22    variant_name=""
23    devicetype=0
24    # If no or dummy smtp_host, use dummy email handler
25    if [ x${SMTP_HOST} = x -o x${SMTP_HOST} = xdummy ]; then
26       cp scripts/dummy_bsmtp bin/bsmtp
27       chmod 755 bin/bsmtp
28    else
29       # Deactivate all email
30       outf="tmp/sed_tmp2"
31       echo "s%  mail =%# mail = %g" >${outf}
32       echo "s%  operator =%# operator =%g" >>${outf}
33       cp ${conf}/bacula-dir.conf ${tmp}/1
34       sed -f ${outf} ${tmp}/1 > ${conf}/bacula-dir.conf
35    fi
36    echo $TestName | grep aligned > /dev/null
37    if [ $? -eq 0 -o x$FORCE_ALIGNED = xyes ]; then
38       make -C build/src/stored install-aligned > /dev/null 2>&1
39       $bperl -e 'add_attribute("$conf/bacula-sd.conf", "Device Type", "Aligned", "Device")'
40       $bperl -e 'add_attribute("$conf/bacula-sd.conf", "Plugin Directory", "$plugins", "Storage")'
41       variant_name="Aligned"
42       devicetype=`expr $devicetype + 1`
43    fi
44    if [ x$FORCE_CLOUD = xyes ]; then
45       make -C build/src/stored install-cloud > /dev/null 2>&1
46       grep DummyCloud $conf/bacula-sd.conf > /dev/null
47       if [ $? != 0 ]; then
48          $bperl -e 'extract_resource("$rscripts/test-bacula-sd.conf", "Cloud", "DummyCloud")' >> $conf/bacula-sd.conf
49       fi
50       $bperl -e 'add_attribute("$conf/bacula-sd.conf", "Device Type", "Cloud", "Device")'
51       $bperl -e 'add_attribute("$conf/bacula-sd.conf", "Cloud", "DummyCloud", "Device")'
52       $bperl -e 'add_attribute("$conf/bacula-sd.conf", "Plugin Directory", "$plugins", "Storage")'
53       mkdir -p $tmp/cloud
54       if [ "$CLOUD_HOSTNAME" ]; then
55           $bperl -e "add_attribute('$conf/bacula-sd.conf', 'HostName', '\"$CLOUD_HOSTNAME\"', 'Cloud')"
56       fi
57       if [ "$CLOUD_BUCKETNAME" ]; then
58           $bperl -e "add_attribute('$conf/bacula-sd.conf', 'BucketName', '\"$CLOUD_BUCKETNAME\"', 'Cloud')"
59       fi
60       if [ "$CLOUD_ACCESSKEY" ]; then
61           $bperl -e "add_attribute('$conf/bacula-sd.conf', 'AccessKey', '\"$CLOUD_ACCESSKEY\"', 'Cloud')"
62       fi
63       if [ "$CLOUD_SECRETKEY" ]; then
64           $bperl -e "add_attribute('$conf/bacula-sd.conf', 'SecretKey', '\"$CLOUD_SECRETKEY\"', 'Cloud')"
65       fi
66       if [ "$CLOUD_REGION" ]; then
67           $bperl -e "add_attribute('$conf/bacula-sd.conf', 'Region', '\"$CLOUD_REGION\"', 'Cloud')"
68       fi
69       if [ "$CLOUD_PROTOCOL" ]; then
70           $bperl -e "add_attribute('$conf/bacula-sd.conf', 'Protocol', '$CLOUD_PROTOCOL', 'Cloud')"
71       fi
72       if [ "$CLOUD_URISTYLE" ]; then
73           $bperl -e "add_attribute('$conf/bacula-sd.conf', 'UriStyle', '$CLOUD_URISTYLE', 'Cloud')"
74       fi
75       if [ "$CLOUD_DRIVER" ]; then
76           driver=`echo $CLOUD_DRIVER | tr 'A-Z' 'a-z'`
77           # FakeS3 is useful but keeps big parts in memory. So we must limit parts.
78           if [ "$driver" = "fakes3" ]; then
79              if [ "$CLOUD_MAXIMUM_PART_SIZE" = "" ]; then
80                 CLOUD_MAXIMUM_PART_SIZE=50MB
81              fi
82              CLOUD_DRIVER=S3
83           fi
84           $bperl -e "add_attribute('$conf/bacula-sd.conf', 'Driver', '\"$CLOUD_DRIVER\"', 'Cloud')"
85       fi
86       if [ "$CLOUD_MAXIMUM_PART_SIZE" ]; then
87           $bperl -e "add_attribute('$conf/bacula-sd.conf', 'MaximumPartSize', '$CLOUD_MAXIMUM_PART_SIZE', 'Device')"
88       fi
89
90       variant_name="Cloud"
91       devicetype=`expr $devicetype + 1`
92    fi
93    if [ x$FORCE_SDCALLS = xyes ]; then
94       $bperl -e 'add_attribute("$conf/bacula-dir.conf", "SD Calls Client", "yes", "Client")'
95       variant_name="${variant_name} SDcall"
96    fi
97    if [ $devicetype -gt 1 ]; then
98        echo "ERROR: Found multiple FORCE_XXX switches"
99        set | awk '/^FORCE_/ { print $0 }'
100        exit 1
101    fi
102    ./test_starttime
103    echo " "
104    echo " "
105    echo " === Start $TestName ${variant_name} at `date +%R:%S` ==="
106    echo " === Start $TestName ${variant_name} at `date +%R:%S` ===" >> ${working}/log
107    echo " "
108    export TestName
109    export zstat
110    export estat
111    estat=0
112    zstat=0
113    bstat=0
114    rstat=0
115    vstat=0
116    dstat=0
117 }
118
119 # Change setup so that we run with shared storage plugin
120 setup_shstore()
121 {
122 if test x${USE_SHSTORE} = xyes ; then
123    require_tape_drive
124    /bin/cp -f ${rscripts}/bacula-sd-lock-changer.conf ${scripts}/bacula-sd.conf
125    scripts/cleanup-tape
126
127    # install the shstore plugin
128    rm -f bin/plugins/shstore-sd.so
129    make -C build/src/plugins/sd install-shstore-plugin >/dev/null
130 fi
131 }
132
133 require_cloud()
134 {
135     if [ "$FORCE_CLOUD" != yes ]; then
136        echo "$TestName can run only with FORCE_CLOUD"
137        exit 0
138     fi
139 }
140
141 require_root()
142 {
143 MUID=`/usr/bin/id | awk -F= '{print $2}' | awk -F\( '{print $1}'`
144 if [ $MUID != 0 ] ; then
145    echo " "
146    echo "You must be root to run this test."
147    echo "  ===== !!!! $TestName not run at `date +%R:%S` ==="
148    echo "  ===== !!!! $TestName not run at `date +%R:%S` !!!! ===== " >>test.out
149    echo " "
150    exit 1
151 fi
152 }
153
154 require_tape_drive() 
155 {
156 #  tape not comptible with aligned
157 if test x$FORCE_ALIGNED = xyes; then
158    echo "$TestName test not compatible with FORCE_ALIGNED."
159    exit 0
160 fi
161 #  tape not comptible with cloud
162 if test x$FORCE_CLOUD = xyes; then
163    echo "$TestName test not compatible with FORCE_CLOUD."
164    exit 0
165 fi
166 if test x${TAPE_DRIVE} = x/dev/null ; then
167    echo "$TestName test needs a tape drive, but has none."
168    exit 1
169 fi
170 }
171
172 require_second_drive()
173
174 if test x${TAPE_DRIVE1} = x/dev/null ; then
175    echo "$JobName needs second drive, but has none."
176    exit 1
177 fi
178 }
179
180 require_autochanger()
181 {
182 if test x${AUTOCHANGER} = x/dev/null ; then
183    echo "$TestName needs an autochanger, but has none."
184    exit 1
185 fi
186 }
187
188 require_vtape() 
189 {
190 #  vtape not comptible with aligned
191 if test x$FORCE_ALIGNED = xyes; then
192    echo "$TestName test not compatible with FORCE_ALIGNED."
193    exit 0
194 fi
195 #  vtape not comptible with cloud
196 if test x$FORCE_CLOUD = xyes; then
197    echo "$TestName test not compatible with FORCE_CLOUD."
198    exit 0
199 fi
200 if test x${USE_VTAPE} = x ; then
201    echo "$TestName test needs the vtape driver."
202    exit 0
203 fi
204 }
205
206 require_disk() 
207 {
208 #  vtape not comptible with aligned
209 if test x$FORCE_ALIGNED = xyes; then
210    echo "$TestName test not compatible with FORCE_ALIGNED."
211    exit 0
212 fi
213 #  vtape not comptible with cloud
214 if test x$FORCE_CLOUD = xyes; then
215    echo "$TestName test not compatible with FORCE_CLOUD."
216    exit 0
217 fi
218 if test x${USE_VTAPE} = xyes ; then
219    echo "$TestName test not compatible with FORCE_VTAPE."
220    exit 0
221 fi
222 }
223
224 require_changer() 
225 {
226 #  disk changer not comptible with cloud
227 if test x$FORCE_CLOUD = xyes; then
228    echo "$TestName test not compatible with FORCE_CLOUD."
229    exit 0
230 fi
231 }
232
233 require_linux()
234 {
235 os=`uname`
236 if [ $os != 'Linux' ]; then
237    echo "$TestName test runs only on Linux"
238    exit 0
239 fi
240 }
241
242 skip_if_no_autochanger()
243 {
244 if test x${AUTOCHANGER} = x/dev/null ; then
245    echo "$TestName test skipped. No autochanger."
246    exit
247 fi
248 }
249
250 set_debug()
251 {
252    debug=$1
253    if test "$debug" -eq 1 ; then
254      out="tee"
255    else
256      out="output"
257    fi
258
259
260 print_debug()
261 {
262    echo $* | grep ERROR > /dev/null
263    if test $? -eq 0; then
264      echo $* >> $tmp/err.log
265    fi
266    if test "$debug" -eq 1 ; then
267      echo $*
268    fi
269 }
270
271 check_files_written()
272 {
273     LOG=$1
274     NB=$2
275     FILES=`awk '/FD Files Written:/ { last=$4 } END { print last }' $LOG`
276
277     if [ "$NB" != "$FILES" ]; then
278         print_debug "ERROR: Expect $NB files, get $FILES"
279         bstat=2
280     fi
281 }
282
283 ################################################################
284 # Get information from logs
285 get_mig_info()
286 {
287     # Prev Backup JobId
288     JOBID=$1
289     LOG=$2
290     RET=`awk -F: "BEGIN { jobid=$JOBID } "'/Prev Backup JobId/ { cjid=$2 } /New Backup JobId/  { if (cjid == jobid) { print $2 } }' $LOG`
291 }
292
293 get_duration()
294 {
295    LOG=$1
296    RET=`awk 'BEGIN {t["secs"]=1;t["sec"]=1;t["min"]=60;t["mins"]=60}; /Elapsed time:/ { last=$3*t[$4] } END { print last }' $LOG`
297 }
298
299 check_duration()
300 {
301    LOG=$1
302    TIME=$2
303    OP=${3:-gt}
304
305    get_duration $LOG
306    if [ "$RET" -$OP "$TIME" ]; then
307        print_debug "Error, got $RET $OP $TIME sec on $LOG"
308        bstat=2
309    fi
310 }
311
312 run_bacula()
313 {
314    debug_wait
315    zstat=0
316    estat=0
317    if test "$debug" -eq 1 ; then
318
319      ${scripts}/bacula-ctl-sd start -m
320      ${scripts}/bacula-ctl-fd start -m $1
321      ${scripts}/bacula-ctl-dir start -m
322      cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf
323      return $?
324    else
325      ${scripts}/bacula start >/dev/null 2>&1
326      cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf >/dev/null 2>&1
327      return $?
328    fi
329 }
330
331 run_bconsole()
332 {
333    bconsole_file=${1:-${tmp}/bconcmds}
334    if test "$debug" -eq 1 ; then
335      cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf
336    else
337      cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf  2>&1 >/dev/null
338    fi
339 }
340
341 run_btape()
342 {
343    if test "$debug" -eq 1 ; then
344      cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape | tee ${tmp}/log1.out
345    else
346      cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape >${tmp}/log1.out 2>&1
347    fi
348 }
349
350 run_bscan()
351 {
352    if test "$debug" -eq 1 ; then
353       ${bin}/bscan $* | tee ${tmp}/log.out
354    else
355       ${bin}/bscan $* 2>&1 >/dev/null
356    fi
357 }
358
359 bscan_libdbi()
360 {   
361    B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
362    B_D=`echo $B | awk '{print $3}'`
363    B_t=`echo $B | awk '{print $6}'`
364    B_p=`echo $B | awk '{print $9}'`
365
366    BSCANLIBDBI="${LIBDBI:+1}"
367                 
368    if test "$BSCANLIBDBI" = "1" ; then
369       BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
370    else
371       BSCANLIBDBI=" "
372    fi
373 }
374
375 stop_bacula()
376 {
377    if [ "$CHECK_JOBMEDIA" != 0 ]; then
378       $bperl -e 'check_jobmedia()'
379       if [ $? -ne 0 ]; then
380          echo " "
381          echo "  !!!!! $TestName ${variant_name} failed!!! `date +%R:%S` !!!!! "
382          echo "     JobMedia is corrupted"
383          echo " " >>test.out
384          echo " " >>test.out
385          echo "  !!!!! $TestName ${variant_name} failed!!! `date +%R:%S` !!!!! " >>test.out
386          echo "     JobMedia is corrupted" >>test.out
387          echo " "
388          exit 1
389       fi
390    fi
391    if [ "$FORCE_CLOUD" = yes ]; then
392       $bperl -e 'check_parts()'
393       if [ $? -ne 0 ]; then
394          estat=1
395       fi
396    fi
397    if test "$debug" -eq 1 ; then
398       ${scripts}/bacula stop
399    else
400       ${scripts}/bacula stop 2>&1 >/dev/null
401    fi
402    # Any File/Dir with @ as the first character is a lock file
403    ls ${working}/@* 2>/dev/null 1>/dev/null
404    if test $? -eq 0 ; then
405       echo " "
406       echo "  !!!!! $TestName ${variant_name} failed!!! `date +%R:%S` !!!!! "
407       echo "     SCSI lock still set"
408       echo " " >>test.out
409       echo " " >>test.out
410       echo "  !!!!! $TestName ${variant_name} failed!!! `date +%R:%S` !!!!! " >>test.out
411       echo "     SCSI lock still set" >>test.out
412       echo " "
413       exit 1
414    fi
415 }
416
417 check_for_zombie_jobs()
418 {
419    ${rscripts}/check_for_zombie_jobs $*
420 }
421
422 change_jobname()
423 {
424    if test $# -eq 1; then
425       oldname=NightlySave
426       newname=$1
427    else
428       oldname=$1
429       newname=$2
430    fi
431    rm -f $tmp/1 $tmp/2
432    mv ${conf}/bacula-dir.conf $tmp/1
433    echo "s%${oldname}%${newname}%g" >$tmp/2
434    sed -f $tmp/2 $tmp/1 >$conf/bacula-dir.conf
435 #  echo "Job ${oldname} changed to ${newname}"
436 }
437
438 check_two_logs()
439 {
440    bstat=${bstat:-99}   # We must find at least one job in log1.out
441    grep "^  Termination: *Backup OK" ${tmp}/log1.out 2>&1 >/dev/null
442    if test $? -ne 0; then
443       bstat=2
444    fi
445    grep "^  Termination: .*Backup Error" ${tmp}/log1.out 2>&1 >/dev/null
446    if test $? -eq 0; then
447       bstat=2
448    fi
449    # Do not check for restart jobs in restart tests
450    echo "$TestName" | grep restart.*-test > /dev/null
451    if [ $? -ne 0 ]; then
452       grep "^  Termination: .*Backup failed" ${tmp}/log1.out 2>&1 >/dev/null
453       if test $? -eq 0; then
454          bstat=3
455       fi
456    fi
457    grep "^  Termination: *Restore OK" ${tmp}/log2.out 2>&1 >/dev/null
458    rstat=${rstat:-$?}
459    grep "^  Termination: .*Restore Error" ${tmp}/log2.out 2>&1 >/dev/null
460    if test $? -eq 0; then
461       rstat=2
462    fi
463    grep "^  Termination: *Restore OK -- warning file count mismatch" ${tmp}/log2.out 2>&1 >/dev/null
464    if test $? -eq 0; then
465       rstat=3
466    fi
467    grep "^  Termination: .*Verify Differences" ${tmp}/log2.out 2>&1 >/dev/null
468    if test $? -eq 0; then
469       vstat=4
470    fi
471    grep "Encoding error for database" ${tmp}/log1.out > /dev/null
472    if test $? -eq 0; then
473       print_debug "Found database encoding error"
474       bstat=2
475    fi
476    grep "Orphaned buffer" ${tmp}/log1.out ${tmp}/log2.out
477    if test $? -eq 0; then
478       print_debug "Found orphaned buffers"
479       estat=1
480    fi
481    if [ x$REGRESS_CHECK_CORRUPTION = xyes ]; then
482        perl -Mscripts::functions -e "check_volumes('$tmp/log1.out', '$tmp/log2.out')" 2>&1 >/dev/null
483        if test $? -ne 0; then
484            print_debug "Found volume corruption"
485            estat=1
486        fi
487    fi
488 }
489
490 die_test()
491 {
492    code=$1
493    msg=$2
494
495    print_debug $msg
496    stop_bacula
497
498    if test "$code" -gt "$estat" ; then
499       estat=$code
500    fi
501    end_test
502    exit 1
503 }
504
505 dtitle()
506 {
507    if test "$debug" -eq 1 ; then
508       echo "============================================================"
509       echo $*
510       echo "============================================================"
511    fi
512 }
513
514 dmsg()
515 {
516    test "$debug" -eq 1 && echo $*
517 }
518
519 check_size_interval()
520 {
521    # if mi == -1 then then ignore mi (idem for ma)
522    mi=$1        
523    value=$2
524    ma=$3
525    
526    test \( -1 -eq $mi -o $mi -le $value \) -a \( -1 -eq $ma -o $value -le $ma \) 
527 }
528
529 check_restore_diff()
530 {
531    if test "$debug" -eq 1 ; then
532       $rscripts/diff.pl -notop -s ${src} -d ${tmp}/bacula-restores${src} 2>&1 >/tmp/d$$
533       if test $? -ne 0; then
534          dstat=1
535          cat /tmp/d$$
536          ls -Rl ${src}
537          ls -Rl ${tmp}/bacula-restores${src}
538       fi
539       rm -f /tmp/d$$
540       diff -ur ${src} ${tmp}/bacula-restores${src}
541    else 
542       $rscripts/diff.pl -notop -s ${src} -d ${tmp}/bacula-restores${src} 2>&1 >/dev/null
543       if test $? -ne 0; then
544          dstat=1
545       fi
546       diff -ur ${src} ${tmp}/bacula-restores${src} 2>&1 >/dev/null
547    fi
548    if test $? -ne 0; then
549      dstat=1
550    fi
551 }
552
553 check_restore_bin_diff()
554 {
555    if test "$debug" -eq 1 ; then
556       $rscripts/diff.pl -notop -s ${bin} -d ${tmp}/bacula-restores${bin} 2>&1 >/tmp/d$$
557       if test $? -ne 0; then
558          dstat=1
559          cat /tmp/d$$
560          ls -Rl ${src}
561          ls -Rl ${tmp}/bacula-restores${src}
562       fi
563       rm -f /tmp/d$$
564       diff -ur ${bin} ${tmp}/bacula-restores${bin}
565    else 
566       $rscripts/diff.pl -notop -s ${bin} -d ${tmp}/bacula-restores${bin} 2>&1 >/dev/null
567       if test $? -ne 0; then
568          dstat=1
569       fi
570       diff -ur ${bin} ${tmp}/bacula-restores${bin} 2>&1 >/dev/null
571    fi
572    if test $? -ne 0; then
573       dstat=1
574    fi
575 }
576
577
578 check_restore_tmp_build_diff()
579 {
580    if test "$debug" -eq 1 ; then
581       $rscripts/diff.pl -notop -s ${tmpsrc} -d ${tmp}/bacula-restores${tmpsrc} 2>&1 >/tmp/d$$
582       if test $? -ne 0; then
583          dstat=1
584          cat /tmp/d$$
585          ls -Rl ${src}
586          ls -Rl ${tmp}/bacula-restores${src}
587       fi
588       rm -f /tmp/d$$
589       diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc}
590    else
591       $rscripts/diff.pl -notop -s ${tmpsrc} -d ${tmp}/bacula-restores${tmpsrc} 2>&1 >/dev/null
592       if test $? -ne 0; then
593          dstat=1
594       fi
595       diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc} 2>&1 >/dev/null
596    fi
597    if test $? -ne 0; then
598       dstat=1
599    fi
600 }
601
602 # bstat is backup error
603 # dstat is diff difference
604 # estat is special error status (shown by print_debug message)
605 # rstat is restore status
606 # zstat is zombie job(s)
607 # vstat is verify status
608 #
609 end_test()
610 {
611    if [ x$notracedump != xyes ]; then 
612       cat ${working}/bacula.*.traceback 2>/dev/null
613       cp -f  ${working}/bacula.*.traceback ${dumps} 2>/dev/null
614    fi
615    if [ -f $tmp/err.log ]; then
616       cat $tmp/err.log
617    fi
618    d=`./test_duration`
619    t=`date +%R:%S`
620    if [ $estat != 0 ] ; then
621       echo " "
622       echo "  !!!!! $TestName ${variant_name} failed!!! $t $d !!!!! "
623       echo "     Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat verify=$vstat"
624       echo " " >>test.out
625       echo "  !!!!! $TestName ${variant_name} failed!!! $t $d !!!!! " >>test.out
626       echo "     Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat verify=$vstat" >>test.out
627       echo " "
628       exit 1
629    fi
630    if [ $zstat != 0 ] ; then
631       echo " "
632       echo "  !!!!! $TestName ${variant_name} failed!!! $t $d !!!!! "
633       echo "     Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat verify=$vstat"
634       echo " " >>test.out
635       echo "  !!!!! $TestName ${variant_name} failed!!! $t $d !!!!! " >>test.out
636       echo "     Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat verify=$vstat" >>test.out
637       echo " "
638       exit 1
639    fi
640    if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 -o $vstat != 0 ] ; then
641       echo " "
642       echo "  !!!!! $TestName ${variant_name} failed!!! $t $d !!!!! "
643       echo "     Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat verify=$vstat"
644       echo " " >>test.out
645       echo "  !!!!! $TestName ${variant_name} failed!!! $t $d !!!!! " >>test.out
646       echo "     Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat verify=$vstat" >>test.out
647       if [ $bstat != 0 -o $rstat != 0 -o $vstat != 0 ] ; then
648          echo "     !!! Bad termination status       !!! "
649          echo "     !!! Bad termination status       !!! " >>test.out
650       else
651          echo "     !!! Restored files differ        !!! "
652          echo "     !!! Restored files differ        !!! " >>test.out
653       fi
654       echo "     Status: backup=$bstat restore=$rstat diff=$dstat verify=$vstat"
655       echo "     Status: backup=$bstat restore=$rstat diff=$dstat verify=$vstat" >>test.out
656       echo "     Test owner of $SITE_NAME is $EMAIL"
657       echo "     Test owner of $SITE_NAME is $EMAIL" >>test.out
658       echo " " >>test.out
659       echo " "
660       exit 1
661    else
662       # KES -- remove variant to make line fit in 80 chars
663       echo "  ===== End $TestName OK $t $d ===== "
664       echo "  ===== End $TestName OK $t $d ===== " >>test.out
665       if test "$debug" -eq 0 ; then
666          ${rscripts}/cleanup
667       fi
668    fi
669 }
670
671 copy_tape_confs()
672 {
673    ${rscripts}/copy-tape-confs
674    ${rscripts}/cleanup-tape
675 }
676
677 copy_test_confs()
678 {
679    ${rscripts}/copy-test-confs
680    ${rscripts}/cleanup
681 }
682
683 disable_plugins()
684 {
685    for i in ${conf}/bacula-fd.conf; do
686       sed 's/Plugin/#Plugin/' $i > $tmp/1
687       cp -f $tmp/1 $i
688    done
689 }
690
691 update_win32()
692 {
693    if [ -d $cwd/build/src/win32/release32   \
694      -o -d $cwd/build/src/win32/release64 ] \
695    || [ -d $cwd/release32 -o -d $cwd/release64 ] \
696    || [ -d $cwd/../bacula/src/win32/release32 \
697      -o -d $cwd/../bacula/src/win32/release64 ]
698    then
699        echo "Try to upgrade the FileDaemon:\t"
700        wget -qO - "$WIN32_ADDR:8091/install"
701    else 
702        echo "Windows binaries not found, skiping upgrade"
703    fi
704 }
705
706 debug_wait()
707 {
708   if test "x${REGRESS_WAIT}" = "x1"; then
709      echo "Start Bacula under debugger and enter anything when ready ..."
710      read a
711   fi
712 }
713
714 init_slot()
715 {
716    DRIVE=$1
717    SLOT=$2
718    if test -n "$DRIVE" -a -n "$SLOT"; then
719       if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
720          dir=`dirname $DRIVE`
721          if [ ! -d "$dir" ]; then
722             mkdir -p "$dir"
723          fi
724          touch $dir/slot$SLOT
725       fi
726    fi
727 }
728
729 init_drive()
730 {
731   if test a$USE_VTAPE = a; then
732     mt -f $1 rewind
733     mt -f $1 weof
734   else
735     cp /dev/null $1
736   fi
737 }
738
739 rewind_drive()
740 {
741   if test a$USE_VTAPE = a; then
742     mt -f $1 rewind
743   fi
744 }
745
746 load_slot1() 
747 {
748 # Get a tape from slot1
749 slot=`${scripts}/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
750 case $slot in
751  0)
752     ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
753     slot=$SLOT1
754     ;;
755  $SLOT1)
756     slot=$SLOT1
757     ;;
758  *)
759     rewind_drive ${TAPE_DRIVE}
760     ${scripts}/$MTX ${AUTOCHANGER} unload $slot  ${TAPE_DRIVE} $DRIVE1
761     ${scripts}/$MTX ${AUTOCHANGER} load   $SLOT1 ${TAPE_DRIVE} $DRIVE1
762     slot=$SLOT1
763     ;;
764 esac
765 }
766
767 #
768 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
769 #    if 2, load 1; if 0 load 1
770 #
771 load_other_slot()
772 {
773 rewind_drive ${TAPE_DRIVE}
774 case $1 in
775  0)
776     ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
777     slot=1
778     ;;
779  $SLOT1)
780     ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
781     ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
782     slot=2
783     ;;
784  $SLOT2)
785     ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
786     ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
787     slot=1
788     ;;
789  *)
790     echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
791     exit 1
792     ;;
793 esac
794 }
795
796
797 # Save current directory
798 cwd=`pwd`
799 if test "x${REGRESS_DEBUG}" = "x1"; then
800    set_debug 1
801 else
802    set_debug 0
803 fi
804
805 # Source the configuration variables
806 . ${cwd}/config
807
808 db_name=${db_name:-"regress"}
809 db_user=${db_user:-"regress"}
810 db_password=${db_password:-""}
811 working=${working:-"$cwd/working"}
812 dumps=${dumps:-"$cwd/dumps"}
813 bin=${bin:-"$cwd/bin"}
814 PERL5LIB=${PERL5LIB}:$cwd
815
816 # Bacula scripts
817 scripts=${scripts:-"$cwd/bin"}
818
819 # Bacula conf files
820 conf=${conf:-"$cwd/bin"}
821
822 # Regress scripts
823 rscripts=${rscripts:-"$cwd/scripts"}
824
825 tmp=${tmp:-"$cwd/tmp"}
826
827 # Bacula source directory when copied here
828 #  also build directory
829 src=${src:-"$cwd/build"}
830
831 # Temp source directory so we don't mess up $src
832 tmpsrc=${tmpsrc:-"$cwd/tmp/build"}
833
834 export bin
835 export conf
836 export working
837 export dumps
838 export scripts
839 export rscripts
840 export tmp
841 export src
842 export tmpsrc
843 export PERL5LIB
844
845 bperl="perl -Mscripts::functions"
846 export bperl
847
848 mkdir -p ${tmp}
849 touch ${tmp}/dir.out ${tmp}/fd.out ${tmp}/sd.out
850
851 CLIENT=${HOST}-fd
852
853 if [ x$USE_VTAPE = xyes ]; then
854    mkdir -p $working/ach
855    SLOT1=1
856    SLOT2=2
857    TAPE_DRIVE=$working/ach/drive0
858    TAPE_DRIVE1=$working/ach/drive1
859    AUTOCHANGER=$working/ach/config
860    AUTOCHANGER_SCRIPT=disk-changer
861    DRIVE1=0
862    DRIVE2=1
863    cp /dev/null $working/ach/slot$SLOT1
864    cp /dev/null $working/ach/slot$SLOT2
865    cat > $AUTOCHANGER <<EOF
866 maxdrive=8
867 maxslot=80
868 EOF
869 fi
870
871 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
872 LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
873 export LD_LIBRARY_PATH
874
875 trap "{ estat=999; end_test; }" TERM