2 # A set of useful functions to be sourced in each test
8 if ${bin}/bacula-dir -d50 -t -c ${conf}/bacula-dir.conf 2>&1 | grep 'Wanted SQL_ASCII, got UTF8' >/dev/null ; then
9 echo "Found database encoding problem, please modify the database encoding (SQL_ASCII)"
20 # If no or dummy smtp_host, use dummy email handler
21 if [ x${SMTP_HOST} = x -o x${SMTP_HOST} = xdummy ]; then
22 cp scripts/dummy_bsmtp bin/bsmtp
25 # Deactivate all email
27 echo "s% mail =%# mail = %g" >${outf}
28 echo "s% operator =%# operator =%g" >>${outf}
29 cp ${conf}/bacula-dir.conf ${tmp}/1
30 sed -f ${outf} ${tmp}/1 > ${conf}/bacula-dir.conf
35 echo " === Starting $TestName ${variant_name} at `date +%R:%S` ==="
36 echo " === Starting $TestName ${variant_name} at `date +%R:%S` ===" >> ${working}/log
50 MUID=`/usr/bin/id | awk -F= '{print $2}' | awk -F\( '{print $1}'`
51 if [ $MUID != 0 ] ; then
53 echo "You must be root to run this test."
54 echo " ===== !!!! $TestName not run at `date +%R:%S` ==="
55 echo " ===== !!!! $TestName not run at `date +%R:%S` !!!! ===== " >>test.out
63 if test x${TAPE_DRIVE} = x/dev/null ; then
64 echo "$TestName test needs a tape drive, but has none."
69 require_second_drive()
71 if test x${TAPE_DRIVE1} = x/dev/null ; then
72 echo "$JobName needs second drive, but has none."
79 if test x${AUTOCHANGER} = x/dev/null ; then
80 echo "$TestName needs an autochanger, but has none."
87 if test x${USE_VTAPE} = x ; then
88 echo "$TestName test needs the vtape driver."
96 if [ $os != 'Linux' ]; then
97 echo "This test $TestName runs only on Linux"
102 skip_if_no_autochanger()
104 if test x${AUTOCHANGER} = x/dev/null ; then
105 echo "$TestName test skipped. No autochanger."
113 if test "$debug" -eq 1 ; then
122 echo $* | grep ERROR > /dev/null
123 if test $? -eq 0; then
124 echo $* >> $tmp/err.log
126 if test "$debug" -eq 1 ; then
131 check_files_written()
135 FILES=`awk '/FD Files Written:/ { last=$4 } END { print last }' $LOG`
137 if [ "$NB" != "$FILES" ]; then
138 print_debug "ERROR: Expect $NB files, get $FILES"
143 ################################################################
144 # Get information from logs
150 RET=`awk -F: "BEGIN { jobid=$JOBID } "'/Prev Backup JobId/ { cjid=$2 } /New Backup JobId/ { if (cjid == jobid) { print $2 } }' $LOG`
156 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`
166 if [ "$RET" -$OP "$TIME" ]; then
167 print_debug "Error, got $RET $OP $TIME sec on $LOG"
177 if test "$debug" -eq 1 ; then
178 ${scripts}/bacula-ctl-sd start -m
179 ${scripts}/bacula-ctl-fd start -m $1
180 ${scripts}/bacula-ctl-dir start -m
181 cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf
184 ${scripts}/bacula start >/dev/null 2>&1
185 cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf >/dev/null 2>&1
192 bconsole_file=${1:-${tmp}/bconcmds}
193 if test "$debug" -eq 1 ; then
194 cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf
196 cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf 2>&1 >/dev/null
202 if test "$debug" -eq 1 ; then
203 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape | tee ${tmp}/log1.out
205 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape >${tmp}/log1.out 2>&1
211 if test "$debug" -eq 1 ; then
212 ${bin}/bscan $* | tee ${tmp}/log.out
214 ${bin}/bscan $* 2>&1 >/dev/null
220 B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
221 B_D=`echo $B | awk '{print $3}'`
222 B_t=`echo $B | awk '{print $6}'`
223 B_p=`echo $B | awk '{print $9}'`
225 BSCANLIBDBI="${LIBDBI:+1}"
227 if test "$BSCANLIBDBI" = "1" ; then
228 BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
236 if test "$debug" -eq 1 ; then
237 ${scripts}/bacula stop
239 ${scripts}/bacula stop 2>&1 >/dev/null
243 check_for_zombie_jobs()
245 ${rscripts}/check_for_zombie_jobs $*
250 if test $# -eq 1; then
258 mv ${conf}/bacula-dir.conf $tmp/1
259 echo "s%${oldname}%${newname}%g" >$tmp/2
260 sed -f $tmp/2 $tmp/1 >$conf/bacula-dir.conf
261 # echo "Job ${oldname} changed to ${newname}"
266 grep "^ Termination: *Backup OK" ${tmp}/log1.out 2>&1 >/dev/null
268 grep "^ Termination: .*Backup Error" ${tmp}/log1.out 2>&1 >/dev/null
269 if test $? -eq 0; then
272 # Do not check for restart jobs in restart tests
273 echo "$TestName" | grep restart.*-test > /dev/null
274 if [ $? -ne 0 ]; then
275 grep "^ Termination: .*Backup failed" ${tmp}/log1.out 2>&1 >/dev/null
276 if test $? -eq 0; then
280 grep "^ Termination: *Restore OK" ${tmp}/log2.out 2>&1 >/dev/null
282 grep "^ Termination: .*Restore Error" ${tmp}/log2.out 2>&1 >/dev/null
283 if test $? -eq 0; then
286 grep "^ Termination: *Restore OK -- warning file count mismatch" ${tmp}/log2.out 2>&1 >/dev/null
287 if test $? -eq 0; then
290 grep "^ Termination: .*Verify Differences" ${tmp}/log2.out 2>&1 >/dev/null
291 if test $? -eq 0; then
294 grep "Encoding error for database" ${tmp}/log1.out > /dev/null
295 if test $? -eq 0; then
296 print_debug "Found database encoding error"
299 grep "Orphaned buffer" ${tmp}/log1.out ${tmp}/log2.out
300 if test $? -eq 0; then
301 print_debug "Found orphaned buffers"
308 if test "$debug" -eq 1 ; then
309 echo "============================================================"
311 echo "============================================================"
317 test "$debug" -eq 1 && echo $*
320 check_size_interval()
322 # if mi == -1 then then ignore mi (idem for ma)
327 test \( -1 -eq $mi -o $mi -le $value \) -a \( -1 -eq $ma -o $value -le $ma \)
332 if test "$debug" -eq 1 ; then
333 $rscripts/diff.pl -notop -s ${src} -d ${tmp}/bacula-restores${src} 2>&1 >/tmp/d$$
334 if test $? -ne 0; then
338 ls -Rl ${tmp}/bacula-restores${src}
341 diff -ur ${src} ${tmp}/bacula-restores${src}
343 $rscripts/diff.pl -notop -s ${src} -d ${tmp}/bacula-restores${src} 2>&1 >/dev/null
344 if test $? -ne 0; then
347 diff -ur ${src} ${tmp}/bacula-restores${src} 2>&1 >/dev/null
349 if test $? -ne 0; then
354 check_restore_bin_diff()
356 if test "$debug" -eq 1 ; then
357 $rscripts/diff.pl -notop -s ${bin} -d ${tmp}/bacula-restores${bin} 2>&1 >/tmp/d$$
358 if test $? -ne 0; then
362 ls -Rl ${tmp}/bacula-restores${src}
365 diff -ur ${bin} ${tmp}/bacula-restores${bin}
367 $rscripts/diff.pl -notop -s ${bin} -d ${tmp}/bacula-restores${bin} 2>&1 >/dev/null
368 if test $? -ne 0; then
371 diff -ur ${bin} ${tmp}/bacula-restores${bin} 2>&1 >/dev/null
373 if test $? -ne 0; then
379 check_restore_tmp_build_diff()
381 if test "$debug" -eq 1 ; then
382 $rscripts/diff.pl -notop -s ${tmpsrc} -d ${tmp}/bacula-restores${tmpsrc} 2>&1 >/tmp/d$$
383 if test $? -ne 0; then
387 ls -Rl ${tmp}/bacula-restores${src}
390 diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc}
392 $rscripts/diff.pl -notop -s ${tmpsrc} -d ${tmp}/bacula-restores${tmpsrc} 2>&1 >/dev/null
393 if test $? -ne 0; then
396 diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc} 2>&1 >/dev/null
398 if test $? -ne 0; then
403 # bstat is backup error
404 # dstat is diff difference
405 # estat is special error status (shown by print_debug message)
406 # rstat is restore status
407 # zstat is zombie job(s)
411 if [ x$notracedump != xyes ]; then
412 cat ${working}/bacula.*.traceback 2>/dev/null
413 cp -f ${working}/bacula.*.traceback ${dumps} 2>/dev/null
414 cat ${working}/*.lockdump 2>/dev/null
415 cp -f ${working}/*.lockdump ${dumps} 2>/dev/null
417 if [ -f $tmp/err.log ]; then
422 if [ $estat != 0 ] ; then
424 echo " !!!!! $TestName failed!!! $t $d !!!!! "
425 echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
427 echo " !!!!! $TestName failed!!! $t $d !!!!! " >>test.out
428 echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
432 if [ $zstat != 0 ] ; then
434 echo " !!!!! $TestName failed!!! $t $d !!!!! "
435 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
437 echo " !!!!! $TestName failed!!! $t $d !!!!! " >>test.out
438 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
442 if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
444 echo " !!!!! $TestName failed!!! $t $d !!!!! "
445 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
447 echo " !!!!! $TestName failed!!! $t $d !!!!! " >>test.out
448 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
449 if [ $bstat != 0 -o $rstat != 0 ] ; then
450 echo " !!! Bad termination status !!! "
451 echo " !!! Bad termination status !!! " >>test.out
453 echo " !!! Restored files differ !!! "
454 echo " !!! Restored files differ !!! " >>test.out
456 echo " Status: backup=$bstat restore=$rstat diff=$dstat"
457 echo " Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
458 echo " Test owner of $SITE_NAME is $EMAIL"
459 echo " Test owner of $SITE_NAME is $EMAIL" >>test.out
464 echo " ===== $TestName OK $t $d ===== "
465 echo " ===== $TestName OK $t $d ===== " >>test.out
466 if test "$debug" -eq 0 ; then
474 ${rscripts}/copy-tape-confs
475 ${rscripts}/cleanup-tape
480 ${rscripts}/copy-test-confs
486 for i in ${conf}/bacula-fd.conf; do
487 sed 's/Plugin/#Plugin/' $i > $tmp/1
494 if test "x${REGRESS_WAIT}" = "x1"; then
495 echo "Start Bacula under debugger and enter anything when ready ..."
504 if test -n "$DRIVE" -a -n "$SLOT"; then
505 if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
507 if [ ! -d "$dir" ]; then
517 if test a$USE_VTAPE = a; then
527 if test a$USE_VTAPE = a; then
534 # Get a tape from slot1
535 slot=`${scripts}/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
538 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
545 rewind_drive ${TAPE_DRIVE}
546 ${scripts}/$MTX ${AUTOCHANGER} unload $slot ${TAPE_DRIVE} $DRIVE1
547 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
554 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
555 # if 2, load 1; if 0 load 1
559 rewind_drive ${TAPE_DRIVE}
562 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
566 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
567 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
571 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
572 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
576 echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
583 # Save current directory
585 if test "x${REGRESS_DEBUG}" = "x1"; then
591 # Source the configuration variables
594 db_name=${db_name:-"regress"}
595 db_user=${db_user:-"regress"}
596 db_password=${db_password:-""}
597 working=${working:-"$cwd/working"}
598 dumps=${dumps:-"$cwd/dumps"}
599 bin=${bin:-"$cwd/bin"}
602 scripts=${scripts:-"$cwd/bin"}
605 conf=${conf:-"$cwd/bin"}
608 rscripts=${rscripts:-"$cwd/scripts"}
610 tmp=${tmp:-"$cwd/tmp"}
612 # Bacula source directory when copied here
613 # also build directory
614 src=${src:-"$cwd/build"}
616 # Temp source directory so we don't mess up $src
617 tmpsrc=${tmpsrc:-"$cwd/tmp/build"}
629 bperl="perl -Mscripts::functions"
633 touch ${tmp}/dir.out ${tmp}/fd.out ${tmp}/sd.out
637 if [ x$USE_VTAPE = xyes ]; then
638 mkdir -p $working/ach
641 TAPE_DRIVE=$working/ach/drive0
642 TAPE_DRIVE1=$working/ach/drive1
643 AUTOCHANGER=$working/ach/config
644 AUTOCHANGER_SCRIPT=disk-changer
647 cp /dev/null $working/ach/slot$SLOT1
648 cp /dev/null $working/ach/slot$SLOT2
649 cat > $AUTOCHANGER <<EOF
655 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
656 LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
657 export LD_LIBRARY_PATH
659 trap "{ estat=999; end_test; }" TERM