2 # A set of useful functions to be sourced in each test
8 ${bin}/bacula-dir -d50 -t -c ${conf}/bacula-dir.conf 2>&1 | grep 'Wanted SQL_ASCII, got UTF8' >/dev/null
10 echo "Found database encoding problem, please modify the database encoding (SQL_ASCII)"
21 echo "s% mail =%# mail = %g" >${outf}
22 echo "s% operator =%# operator =%g" >>${outf}
23 cp ${conf}/bacula-dir.conf ${tmp}/1
24 sed -f ${outf} ${tmp}/1 > ${conf}/bacula-dir.conf
25 if [ x$FORCE_SDCALLS = xyes ]; then
26 $bperl -e 'add_attribute("$conf/bacula-dir.conf", "SD Calls Client", "yes", "Client")'
31 echo " === Starting $TestName at `date +%R:%S` ==="
32 echo " === Starting $TestName at `date +%R:%S` ===" >> ${working}/log
46 MUID=`/usr/bin/id | awk -F= '{print $2}' | awk -F\( '{print $1}'`
47 if [ $MUID != 0 ] ; then
49 echo "You must be root to run this test."
50 echo " ===== !!!! $TestName not run at `date +%R:%S` ==="
51 echo " ===== !!!! $TestName not run at `date +%R:%S` !!!! ===== " >>test.out
59 if test x${TAPE_DRIVE} = x/dev/null ; then
60 echo "$TestName test needs a tape drive, but has none."
65 require_second_drive()
67 if test x${TAPE_DRIVE1} = x/dev/null ; then
68 echo "$JobName needs second drive, but has none."
75 if test x${AUTOCHANGER} = x/dev/null ; then
76 echo "$TestName needs an autochanger, but has none."
83 if test x${USE_VTAPE} = x ; then
84 echo "$TestName test needs the vtape driver."
92 if [ $os != 'Linux' ]; then
93 echo "This test $TestName runs only on Linux"
98 skip_if_no_autochanger()
100 if test x${AUTOCHANGER} = x/dev/null ; then
101 echo "$TestName test skipped. No autochanger."
109 if test "$debug" -eq 1 ; then
118 echo $* | grep ERROR > /dev/null
119 if test $? -eq 0; then
120 echo $* >> $tmp/err.log
122 if test "$debug" -eq 1 ; then
127 check_files_written()
131 FILES=`awk '/FD Files Written:/ { last=$4 } END { print last }' $LOG`
133 if [ "$NB" != "$FILES" ]; then
134 print_debug "ERROR: Expect $NB files, get $FILES"
139 ################################################################
140 # Get information from logs
146 RET=`awk -F: "BEGIN { jobid=$JOBID } "'/Prev Backup JobId/ { cjid=$2 } /New Backup JobId/ { if (cjid == jobid) { print $2 } }' $LOG`
152 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`
162 if [ "$RET" -$OP "$TIME" ]; then
163 print_debug "Expect $OP than $TIME sec, get $RET"
173 if test "$debug" -eq 1 ; then
174 ${scripts}/bacula-ctl-sd start -m
175 ${scripts}/bacula-ctl-fd start -m $1
176 ${scripts}/bacula-ctl-dir start -m
177 cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf
180 ${scripts}/bacula start >/dev/null 2>&1
181 cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf >/dev/null 2>&1
188 bconsole_file=${1:-${tmp}/bconcmds}
189 if test "$debug" -eq 1 ; then
190 cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf
192 cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf 2>&1 >/dev/null
198 if test "$debug" -eq 1 ; then
199 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape | tee ${tmp}/log1.out
201 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape >${tmp}/log1.out 2>&1
207 if test "$debug" -eq 1 ; then
208 ${bin}/bscan $* | tee ${tmp}/log.out
210 ${bin}/bscan $* 2>&1 >/dev/null
216 B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
217 B_D=`echo $B | awk '{print $3}'`
218 B_t=`echo $B | awk '{print $6}'`
219 B_p=`echo $B | awk '{print $9}'`
221 BSCANLIBDBI="${LIBDBI:+1}"
223 if test "$BSCANLIBDBI" = "1" ; then
224 BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
232 if test "$debug" -eq 1 ; then
233 ${scripts}/bacula stop
235 ${scripts}/bacula stop 2>&1 >/dev/null
239 check_for_zombie_jobs()
241 ${rscripts}/check_for_zombie_jobs $*
246 if test $# -eq 1; then
254 mv ${conf}/bacula-dir.conf $tmp/1
255 echo "s%${oldname}%${newname}%g" >$tmp/2
256 sed -f $tmp/2 $tmp/1 >$conf/bacula-dir.conf
257 # echo "Job ${oldname} changed to ${newname}"
262 grep "^ Termination: *Backup OK" ${tmp}/log1.out 2>&1 >/dev/null
264 grep "^ Termination: .*Backup Error" ${tmp}/log1.out 2>&1 >/dev/null
265 if test $? -eq 0; then
268 grep "^ Termination: *Restore OK" ${tmp}/log2.out 2>&1 >/dev/null
270 grep "^ Termination: .*Restore Error" ${tmp}/log2.out 2>&1 >/dev/null
271 if test $? -eq 0; then
274 grep "^ Termination: *Restore OK -- warning file count mismatch" ${tmp}/log2.out 2>&1 >/dev/null
275 if test $? -eq 0; then
278 grep "^ Termination: .*Verify Differences" ${tmp}/log2.out 2>&1 >/dev/null
279 if test $? -eq 0; then
282 grep "Encoding error for database" ${tmp}/log1.out > /dev/null
283 if test $? -eq 0; then
284 print_debug "Found database encoding error"
287 grep "Orphaned buffer" ${tmp}/log1.out ${tmp}/log2.out
288 if test $? -eq 0; then
295 if test "$debug" -eq 1 ; then
296 $rscripts/diff.pl -notop -s ${src} -d ${tmp}/bacula-restores${src} 2>&1 >/tmp/d$$
297 if test $? -ne 0; then
301 ls -Rl ${tmp}/bacula-restores${src}
304 diff -ur ${src} ${tmp}/bacula-restores${src}
306 $rscripts/diff.pl -notop -s ${src} -d ${tmp}/bacula-restores${src} 2>&1 >/dev/null
307 if test $? -ne 0; then
310 diff -ur ${src} ${tmp}/bacula-restores${src} 2>&1 >/dev/null
312 if test $? -ne 0; then
317 check_restore_bin_diff()
319 if test "$debug" -eq 1 ; then
320 $rscripts/diff.pl -notop -s ${bin} -d ${tmp}/bacula-restores${bin} 2>&1 >/tmp/d$$
321 if test $? -ne 0; then
325 ls -Rl ${tmp}/bacula-restores${src}
328 diff -ur ${bin} ${tmp}/bacula-restores${bin}
330 $rscripts/diff.pl -notop -s ${bin} -d ${tmp}/bacula-restores${bin} 2>&1 >/dev/null
331 if test $? -ne 0; then
334 diff -ur ${bin} ${tmp}/bacula-restores${bin} 2>&1 >/dev/null
336 if test $? -ne 0; then
342 check_restore_tmp_build_diff()
344 if test "$debug" -eq 1 ; then
345 $rscripts/diff.pl -notop -s ${tmpsrc} -d ${tmp}/bacula-restores${tmpsrc} 2>&1 >/tmp/d$$
346 if test $? -ne 0; then
350 ls -Rl ${tmp}/bacula-restores${src}
353 diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc}
355 $rscripts/diff.pl -notop -s ${tmpsrc} -d ${tmp}/bacula-restores${tmpsrc} 2>&1 >/dev/null
356 if test $? -ne 0; then
359 diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc} 2>&1 >/dev/null
361 if test $? -ne 0; then
366 # bstat is backup error
367 # dstat is diff difference
368 # estat is special error status (shown by print_debug message)
369 # rstat is restore status
370 # zstat is zombie job(s)
374 if [ x$notracedump != xyes ]; then
375 cat ${working}/bacula.*.traceback 2>/dev/null
376 cp -f ${working}/bacula.*.traceback ${dumps} 2>/dev/null
377 cat ${working}/*.lockdump 2>/dev/null
378 cp -f ${working}/*.lockdump ${dumps} 2>/dev/null
380 if [ -f $tmp/err.log ]; then
385 if [ $estat != 0 ] ; then
387 echo " !!!!! $TestName failed!!! $t $d !!!!! "
388 echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
390 echo " !!!!! $TestName failed!!! $t $d !!!!! " >>test.out
391 echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
395 if [ $zstat != 0 ] ; then
397 echo " !!!!! $TestName failed!!! $t $d !!!!! "
398 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
400 echo " !!!!! $TestName failed!!! $t $d !!!!! " >>test.out
401 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
405 if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
407 echo " !!!!! $TestName failed!!! $t $d !!!!! "
408 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
410 echo " !!!!! $TestName failed!!! $t %d !!!!! " >>test.out
411 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
412 if [ $bstat != 0 -o $rstat != 0 ] ; then
413 echo " !!! Bad termination status !!! "
414 echo " !!! Bad termination status !!! " >>test.out
416 echo " !!! Restored files differ !!! "
417 echo " !!! Restored files differ !!! " >>test.out
419 echo " Status: backup=$bstat restore=$rstat diff=$dstat"
420 echo " Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
421 echo " Test owner of $SITE_NAME is $EMAIL"
422 echo " Test owner of $SITE_NAME is $EMAIL" >>test.out
427 echo " ===== $TestName OK $t $d ===== "
428 echo " ===== $TestName OK $t $d ===== " >>test.out
429 if test "$debug" -eq 0 ; then
437 ${rscripts}/copy-tape-confs
438 ${rscripts}/cleanup-tape
443 ${rscripts}/copy-test-confs
449 for i in ${conf}/bacula-fd.conf; do
450 sed 's/Plugin/#Plugin/' $i > $tmp/1
457 if test "x${REGRESS_WAIT}" = "x1"; then
458 echo "Start Bacula under debugger and enter anything when ready ..."
467 if test -n "$DRIVE" -a -n "$SLOT"; then
468 if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
470 if [ ! -d "$dir" ]; then
480 if test a$USE_VTAPE = a; then
490 if test a$USE_VTAPE = a; then
497 # Get a tape from slot1
498 slot=`${scripts}/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
501 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
508 rewind_drive ${TAPE_DRIVE}
509 ${scripts}/$MTX ${AUTOCHANGER} unload $slot ${TAPE_DRIVE} $DRIVE1
510 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
517 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
518 # if 2, load 1; if 0 load 1
522 rewind_drive ${TAPE_DRIVE}
525 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
529 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
530 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
534 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
535 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
539 echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
546 # Save current directory
548 if test "x${REGRESS_DEBUG}" = "x1"; then
554 # Source the configuration variables
557 db_name=${db_name:-"regress"}
558 db_user=${db_user:-"regress"}
559 db_password=${db_password:-""}
560 working=${working:-"$cwd/working"}
561 dumps=${dumps:-"$cwd/dumps"}
562 bin=${bin:-"$cwd/bin"}
565 scripts=${scripts:-"$cwd/bin"}
568 conf=${conf:-"$cwd/bin"}
571 rscripts=${rscripts:-"$cwd/scripts"}
573 tmp=${tmp:-"$cwd/tmp"}
575 # Bacula source directory when copied here
576 # also build directory
577 src=${src:-"$cwd/build"}
579 # Temp source directory so we don't mess up $src
580 tmpsrc=${tmpsrc:-"$cwd/tmp/build"}
592 bperl="perl -Mscripts::functions"
596 touch ${tmp}/dir.out ${tmp}/fd.out ${tmp}/sd.out
600 if [ x$USE_VTAPE = xyes ]; then
601 mkdir -p $working/ach
604 TAPE_DRIVE=$working/ach/drive0
605 TAPE_DRIVE1=$working/ach/drive1
606 AUTOCHANGER=$working/ach/config
607 AUTOCHANGER_SCRIPT=disk-changer
610 cp /dev/null $working/ach/slot$SLOT1
611 cp /dev/null $working/ach/slot$SLOT2
612 cat > $AUTOCHANGER <<EOF
618 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
619 LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
620 export LD_LIBRARY_PATH
622 trap "{ estat=999; end_test; }" TERM