2 # Copyright (C) 2000-2017 Kern Sibbald
3 # License: BSD 2-Clause; see file LICENSE-FOSS
5 # A set of useful functions to be sourced in each test
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)"
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
29 # Deactivate all email
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
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`
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
48 $bperl -e 'extract_resource("$rscripts/test-bacula-sd.conf", "Cloud", "DummyCloud")' >> $conf/bacula-sd.conf
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")'
54 if [ "$CLOUD_HOSTNAME" ]; then
55 $bperl -e "add_attribute('$conf/bacula-sd.conf', 'HostName', '\"$CLOUD_HOSTNAME\"', 'Cloud')"
57 if [ "$CLOUD_BUCKETNAME" ]; then
58 $bperl -e "add_attribute('$conf/bacula-sd.conf', 'BucketName', '\"$CLOUD_BUCKETNAME\"', 'Cloud')"
60 if [ "$CLOUD_ACCESSKEY" ]; then
61 $bperl -e "add_attribute('$conf/bacula-sd.conf', 'AccessKey', '\"$CLOUD_ACCESSKEY\"', 'Cloud')"
63 if [ "$CLOUD_SECRETKEY" ]; then
64 $bperl -e "add_attribute('$conf/bacula-sd.conf', 'SecretKey', '\"$CLOUD_SECRETKEY\"', 'Cloud')"
66 if [ "$CLOUD_REGION" ]; then
67 $bperl -e "add_attribute('$conf/bacula-sd.conf', 'Region', '\"$CLOUD_REGION\"', 'Cloud')"
69 if [ "$CLOUD_PROTOCOL" ]; then
70 $bperl -e "add_attribute('$conf/bacula-sd.conf', 'Protocol', '$CLOUD_PROTOCOL', 'Cloud')"
72 if [ "$CLOUD_URISTYLE" ]; then
73 $bperl -e "add_attribute('$conf/bacula-sd.conf', 'UriStyle', '$CLOUD_URISTYLE', 'Cloud')"
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
84 $bperl -e "add_attribute('$conf/bacula-sd.conf', 'Driver', '\"$CLOUD_DRIVER\"', 'Cloud')"
86 if [ "$CLOUD_MAXIMUM_PART_SIZE" ]; then
87 $bperl -e "add_attribute('$conf/bacula-sd.conf', 'MaximumPartSize', '$CLOUD_MAXIMUM_PART_SIZE', 'Device')"
91 devicetype=`expr $devicetype + 1`
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"
97 if [ $devicetype -gt 1 ]; then
98 echo "ERROR: Found multiple FORCE_XXX switches"
99 set | awk '/^FORCE_/ { print $0 }'
105 echo " === Start $TestName ${variant_name} at `date +%R:%S` ==="
106 echo " === Start $TestName ${variant_name} at `date +%R:%S` ===" >> ${working}/log
119 # Change setup so that we run with shared storage plugin
122 if test x${USE_SHSTORE} = xyes ; then
124 /bin/cp -f ${rscripts}/bacula-sd-lock-changer.conf ${scripts}/bacula-sd.conf
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
135 if [ "$FORCE_CLOUD" != yes ]; then
136 echo "$TestName can run only with FORCE_CLOUD"
143 MUID=`/usr/bin/id | awk -F= '{print $2}' | awk -F\( '{print $1}'`
144 if [ $MUID != 0 ] ; then
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
156 # tape not comptible with aligned
157 if test x$FORCE_ALIGNED = xyes; then
158 echo "$TestName test not compatible with FORCE_ALIGNED."
161 # tape not comptible with cloud
162 if test x$FORCE_CLOUD = xyes; then
163 echo "$TestName test not compatible with FORCE_CLOUD."
166 if test x${TAPE_DRIVE} = x/dev/null ; then
167 echo "$TestName test needs a tape drive, but has none."
172 require_second_drive()
174 if test x${TAPE_DRIVE1} = x/dev/null ; then
175 echo "$JobName needs second drive, but has none."
180 require_autochanger()
182 if test x${AUTOCHANGER} = x/dev/null ; then
183 echo "$TestName needs an autochanger, but has none."
190 # vtape not comptible with aligned
191 if test x$FORCE_ALIGNED = xyes; then
192 echo "$TestName test not compatible with FORCE_ALIGNED."
195 # vtape not comptible with cloud
196 if test x$FORCE_CLOUD = xyes; then
197 echo "$TestName test not compatible with FORCE_CLOUD."
200 if test x${USE_VTAPE} = x ; then
201 echo "$TestName test needs the vtape driver."
208 # vtape not comptible with aligned
209 if test x$FORCE_ALIGNED = xyes; then
210 echo "$TestName test not compatible with FORCE_ALIGNED."
213 # vtape not comptible with cloud
214 if test x$FORCE_CLOUD = xyes; then
215 echo "$TestName test not compatible with FORCE_CLOUD."
218 if test x${USE_VTAPE} = xyes ; then
219 echo "$TestName test not compatible with FORCE_VTAPE."
226 # disk changer not comptible with cloud
227 if test x$FORCE_CLOUD = xyes; then
228 echo "$TestName test not compatible with FORCE_CLOUD."
236 if [ $os != 'Linux' ]; then
237 echo "$TestName test runs only on Linux"
242 skip_if_no_autochanger()
244 if test x${AUTOCHANGER} = x/dev/null ; then
245 echo "$TestName test skipped. No autochanger."
253 if test "$debug" -eq 1 ; then
262 echo $* | grep ERROR > /dev/null
263 if test $? -eq 0; then
264 echo $* >> $tmp/err.log
266 if test "$debug" -eq 1 ; then
271 check_files_written()
275 FILES=`awk '/FD Files Written:/ { last=$4 } END { print last }' $LOG`
277 if [ "$NB" != "$FILES" ]; then
278 print_debug "ERROR: Expect $NB files, get $FILES"
283 ################################################################
284 # Get information from logs
290 RET=`awk -F: "BEGIN { jobid=$JOBID } "'/Prev Backup JobId/ { cjid=$2 } /New Backup JobId/ { if (cjid == jobid) { print $2 } }' $LOG`
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`
306 if [ "$RET" -$OP "$TIME" ]; then
307 print_debug "Error, got $RET $OP $TIME sec on $LOG"
317 if test "$debug" -eq 1 ; then
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
325 ${scripts}/bacula start >/dev/null 2>&1
326 cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf >/dev/null 2>&1
333 bconsole_file=${1:-${tmp}/bconcmds}
334 if test "$debug" -eq 1 ; then
335 cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf
337 cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf 2>&1 >/dev/null
343 if test "$debug" -eq 1 ; then
344 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape | tee ${tmp}/log1.out
346 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape >${tmp}/log1.out 2>&1
352 if test "$debug" -eq 1 ; then
353 ${bin}/bscan $* | tee ${tmp}/log.out
355 ${bin}/bscan $* 2>&1 >/dev/null
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}'`
366 BSCANLIBDBI="${LIBDBI:+1}"
368 if test "$BSCANLIBDBI" = "1" ; then
369 BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
377 if [ "$CHECK_JOBMEDIA" != 0 ]; then
378 $bperl -e 'check_jobmedia()'
379 if [ $? -ne 0 ]; then
381 echo " !!!!! $TestName ${variant_name} failed!!! `date +%R:%S` !!!!! "
382 echo " JobMedia is corrupted"
385 echo " !!!!! $TestName ${variant_name} failed!!! `date +%R:%S` !!!!! " >>test.out
386 echo " JobMedia is corrupted" >>test.out
391 if [ "$FORCE_CLOUD" = yes ]; then
392 $bperl -e 'check_parts()'
393 if [ $? -ne 0 ]; then
397 if test "$debug" -eq 1 ; then
398 ${scripts}/bacula stop
400 ${scripts}/bacula stop 2>&1 >/dev/null
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
406 echo " !!!!! $TestName ${variant_name} failed!!! `date +%R:%S` !!!!! "
407 echo " SCSI lock still set"
410 echo " !!!!! $TestName ${variant_name} failed!!! `date +%R:%S` !!!!! " >>test.out
411 echo " SCSI lock still set" >>test.out
417 check_for_zombie_jobs()
419 ${rscripts}/check_for_zombie_jobs $*
424 if test $# -eq 1; then
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}"
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
445 grep "^ Termination: .*Backup Error" ${tmp}/log1.out 2>&1 >/dev/null
446 if test $? -eq 0; then
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
457 grep "^ Termination: *Restore OK" ${tmp}/log2.out 2>&1 >/dev/null
459 grep "^ Termination: .*Restore Error" ${tmp}/log2.out 2>&1 >/dev/null
460 if test $? -eq 0; then
463 grep "^ Termination: *Restore OK -- warning file count mismatch" ${tmp}/log2.out 2>&1 >/dev/null
464 if test $? -eq 0; then
467 grep "^ Termination: .*Verify Differences" ${tmp}/log2.out 2>&1 >/dev/null
468 if test $? -eq 0; then
471 grep "Encoding error for database" ${tmp}/log1.out > /dev/null
472 if test $? -eq 0; then
473 print_debug "Found database encoding error"
476 grep "Orphaned buffer" ${tmp}/log1.out ${tmp}/log2.out
477 if test $? -eq 0; then
478 print_debug "Found orphaned buffers"
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"
498 if test "$code" -gt "$estat" ; then
507 if test "$debug" -eq 1 ; then
508 echo "============================================================"
510 echo "============================================================"
516 test "$debug" -eq 1 && echo $*
519 check_size_interval()
521 # if mi == -1 then then ignore mi (idem for ma)
526 test \( -1 -eq $mi -o $mi -le $value \) -a \( -1 -eq $ma -o $value -le $ma \)
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
537 ls -Rl ${tmp}/bacula-restores${src}
540 diff -ur ${src} ${tmp}/bacula-restores${src}
542 $rscripts/diff.pl -notop -s ${src} -d ${tmp}/bacula-restores${src} 2>&1 >/dev/null
543 if test $? -ne 0; then
546 diff -ur ${src} ${tmp}/bacula-restores${src} 2>&1 >/dev/null
548 if test $? -ne 0; then
553 check_restore_bin_diff()
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
561 ls -Rl ${tmp}/bacula-restores${src}
564 diff -ur ${bin} ${tmp}/bacula-restores${bin}
566 $rscripts/diff.pl -notop -s ${bin} -d ${tmp}/bacula-restores${bin} 2>&1 >/dev/null
567 if test $? -ne 0; then
570 diff -ur ${bin} ${tmp}/bacula-restores${bin} 2>&1 >/dev/null
572 if test $? -ne 0; then
578 check_restore_tmp_build_diff()
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
586 ls -Rl ${tmp}/bacula-restores${src}
589 diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc}
591 $rscripts/diff.pl -notop -s ${tmpsrc} -d ${tmp}/bacula-restores${tmpsrc} 2>&1 >/dev/null
592 if test $? -ne 0; then
595 diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc} 2>&1 >/dev/null
597 if test $? -ne 0; then
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
611 if [ x$notracedump != xyes ]; then
612 cat ${working}/bacula.*.traceback 2>/dev/null
613 cp -f ${working}/bacula.*.traceback ${dumps} 2>/dev/null
615 if [ -f $tmp/err.log ]; then
620 if [ $estat != 0 ] ; then
622 echo " !!!!! $TestName ${variant_name} failed!!! $t $d !!!!! "
623 echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat verify=$vstat"
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
630 if [ $zstat != 0 ] ; then
632 echo " !!!!! $TestName ${variant_name} failed!!! $t $d !!!!! "
633 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat verify=$vstat"
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
640 if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 -o $vstat != 0 ] ; then
642 echo " !!!!! $TestName ${variant_name} failed!!! $t $d !!!!! "
643 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat verify=$vstat"
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
651 echo " !!! Restored files differ !!! "
652 echo " !!! Restored files differ !!! " >>test.out
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
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
673 ${rscripts}/copy-tape-confs
674 ${rscripts}/cleanup-tape
679 ${rscripts}/copy-test-confs
685 for i in ${conf}/bacula-fd.conf; do
686 sed 's/Plugin/#Plugin/' $i > $tmp/1
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 ]
699 echo "Try to upgrade the FileDaemon:\t"
700 wget -qO - "$WIN32_ADDR:8091/install"
702 echo "Windows binaries not found, skiping upgrade"
708 if test "x${REGRESS_WAIT}" = "x1"; then
709 echo "Start Bacula under debugger and enter anything when ready ..."
718 if test -n "$DRIVE" -a -n "$SLOT"; then
719 if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
721 if [ ! -d "$dir" ]; then
731 if test a$USE_VTAPE = a; then
741 if test a$USE_VTAPE = a; then
748 # Get a tape from slot1
749 slot=`${scripts}/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
752 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
759 rewind_drive ${TAPE_DRIVE}
760 ${scripts}/$MTX ${AUTOCHANGER} unload $slot ${TAPE_DRIVE} $DRIVE1
761 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
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
773 rewind_drive ${TAPE_DRIVE}
776 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
780 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
781 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
785 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
786 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
790 echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
797 # Save current directory
799 if test "x${REGRESS_DEBUG}" = "x1"; then
805 # Source the configuration variables
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
817 scripts=${scripts:-"$cwd/bin"}
820 conf=${conf:-"$cwd/bin"}
823 rscripts=${rscripts:-"$cwd/scripts"}
825 tmp=${tmp:-"$cwd/tmp"}
827 # Bacula source directory when copied here
828 # also build directory
829 src=${src:-"$cwd/build"}
831 # Temp source directory so we don't mess up $src
832 tmpsrc=${tmpsrc:-"$cwd/tmp/build"}
845 bperl="perl -Mscripts::functions"
849 touch ${tmp}/dir.out ${tmp}/fd.out ${tmp}/sd.out
853 if [ x$USE_VTAPE = xyes ]; then
854 mkdir -p $working/ach
857 TAPE_DRIVE=$working/ach/drive0
858 TAPE_DRIVE1=$working/ach/drive1
859 AUTOCHANGER=$working/ach/config
860 AUTOCHANGER_SCRIPT=disk-changer
863 cp /dev/null $working/ach/slot$SLOT1
864 cp /dev/null $working/ach/slot$SLOT2
865 cat > $AUTOCHANGER <<EOF
871 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
872 LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
873 export LD_LIBRARY_PATH
875 trap "{ estat=999; end_test; }" TERM