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)"
20 echo "s% mail =%# mail = %g" >${outf}
21 echo "s% operator =%# operator =%g" >>${outf}
22 cp ${conf}/bacula-dir.conf ${tmp}/1
23 sed -f ${outf} ${tmp}/1 > ${conf}/bacula-dir.conf
26 echo " === Starting $TestName at `date +%R:%S` ==="
27 echo " === Starting $TestName at `date +%R:%S` ===" >> ${working}/log
41 MUID=`/usr/bin/id | awk -F= '{print $2}' | awk -F\( '{print $1}'`
42 if [ $MUID != 0 ] ; then
44 echo "You must be root to run this test."
45 echo " ===== !!!! $TestName not run at `date +%R:%S` ==="
46 echo " ===== !!!! $TestName not run at `date +%R:%S` !!!! ===== " >>test.out
54 if test x${TAPE_DRIVE} = x/dev/null ; then
55 echo "$TestName test needs a tape drive, but has none."
60 require_second_drive()
62 if test x${TAPE_DRIVE1} = x/dev/null ; then
63 echo "$JobName needs second drive, but has none."
70 if test x${AUTOCHANGER} = x/dev/null ; then
71 echo "$TestName needs an autochanger, but has none."
78 if test x${USE_VTAPE} = x ; then
79 echo "$TestName test needs the vtape driver."
87 if [ $os != 'Linux' ]; then
88 echo "This test $TestName runs only on Linux"
93 skip_if_no_autochanger()
95 if test x${AUTOCHANGER} = x/dev/null ; then
96 echo "$TestName test skipped. No autochanger."
104 if test "$debug" -eq 1 ; then
113 echo $* | grep ERROR > /dev/null
114 if test $? -eq 0; then
115 echo $* >> $tmp/err.log
117 if test "$debug" -eq 1 ; then
122 check_files_written()
126 FILES=`awk '/FD Files Written:/ { last=$4 } END { print last }' $LOG`
128 if [ "$NB" != "$FILES" ]; then
129 print_debug "ERROR: Expect $NB files, get $FILES"
134 ################################################################
135 # Get information from logs
141 RET=`awk -F: "BEGIN { jobid=$JOBID } "'/Prev Backup JobId/ { cjid=$2 } /New Backup JobId/ { if (cjid == jobid) { print $2 } }' $LOG`
147 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`
157 if [ "$RET" -$OP "$TIME" ]; then
158 print_debug "Expect $OP than $TIME sec, get $RET"
168 if test "$debug" -eq 1 ; then
169 ${scripts}/bacula-ctl-sd start -m
170 ${scripts}/bacula-ctl-fd start -m $1
171 ${scripts}/bacula-ctl-dir start -m
172 cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf
175 ${scripts}/bacula start >/dev/null 2>&1
176 cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf >/dev/null 2>&1
183 bconsole_file=${1:-${tmp}/bconcmds}
184 if test "$debug" -eq 1 ; then
185 cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf
187 cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf 2>&1 >/dev/null
193 if test "$debug" -eq 1 ; then
194 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape | tee ${tmp}/log1.out
196 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape >${tmp}/log1.out 2>&1
202 if test "$debug" -eq 1 ; then
203 ${bin}/bscan $* | tee ${tmp}/log.out
205 ${bin}/bscan $* 2>&1 >/dev/null
211 B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
212 B_D=`echo $B | awk '{print $3}'`
213 B_t=`echo $B | awk '{print $6}'`
214 B_p=`echo $B | awk '{print $9}'`
216 BSCANLIBDBI="${LIBDBI:+1}"
218 if test "$BSCANLIBDBI" = "1" ; then
219 BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
227 if test "$debug" -eq 1 ; then
228 ${scripts}/bacula stop
230 ${scripts}/bacula stop 2>&1 >/dev/null
234 check_for_zombie_jobs()
236 ${rscripts}/check_for_zombie_jobs $*
241 if test $# -eq 1; then
249 mv ${conf}/bacula-dir.conf $tmp/1
250 echo "s%${oldname}%${newname}%g" >$tmp/2
251 sed -f $tmp/2 $tmp/1 >$conf/bacula-dir.conf
252 # echo "Job ${oldname} changed to ${newname}"
257 grep "^ Termination: *Backup OK" ${tmp}/log1.out 2>&1 >/dev/null
259 grep "^ Termination: .*Backup Error" ${tmp}/log1.out 2>&1 >/dev/null
260 if test $? -eq 0; then
263 grep "^ Termination: *Restore OK" ${tmp}/log2.out 2>&1 >/dev/null
265 grep "^ Termination: .*Restore Error" ${tmp}/log2.out 2>&1 >/dev/null
266 if test $? -eq 0; then
269 grep "^ Termination: *Restore OK -- warning file count mismatch" ${tmp}/log2.out 2>&1 >/dev/null
270 if test $? -eq 0; then
273 grep "^ Termination: .*Verify Differences" ${tmp}/log2.out 2>&1 >/dev/null
274 if test $? -eq 0; then
277 grep "Encoding error for database" ${tmp}/log1.out > /dev/null
278 if test $? -eq 0; then
279 print_debug "Found database encoding error"
286 if test "$debug" -eq 1 ; then
287 $rscripts/diff.pl -s ${src} -d ${tmp}/bacula-restores${src}
288 diff -ur ${src} ${tmp}/bacula-restores${src}
290 diff -ur ${src} ${tmp}/bacula-restores${src} 2>&1 >/dev/null
295 check_restore_bin_diff()
297 if test "$debug" -eq 1 ; then
298 $rscripts/diff.pl -s ${bin} -d ${tmp}/bacula-restores${bin}
299 diff -ur ${bin} ${tmp}/bacula-restores${bin}
301 diff -ur ${bin} ${tmp}/bacula-restores${bin} 2>&1 >/dev/null
307 check_restore_tmp_build_diff()
309 if test "$debug" -eq 1 ; then
310 $rscripts/diff.pl -s ${tmpsrc} -d ${tmp}/bacula-restores${tmpsrc}
311 diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc}
313 diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc} 2>&1 >/dev/null
318 # bstat is backup error
319 # dstat is diff difference
320 # estat is special error status (shown by print_debug message)
321 # rstat is restore status
322 # zstat is zombie job(s)
326 if [ x$notracedump != xyes ]; then
327 cat ${working}/bacula.*.traceback 2>/dev/null
328 cp -f ${working}/bacula.*.traceback ${dumps} 2>/dev/null
329 cat ${working}/*.bactrace 2>/dev/null
330 cp -f ${working}/*.bactrace ${dumps} 2>/dev/null
332 if [ -f $tmp/err.log ]; then
335 if [ $estat != 0 ] ; then
337 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
338 echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
339 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
340 echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
344 if [ $zstat != 0 ] ; then
346 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
347 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
348 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
349 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
353 if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
356 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
357 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
358 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
359 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
360 if [ $bstat != 0 -o $rstat != 0 ] ; then
361 echo " !!!!! Bad termination status !!!!! "
362 echo " !!!!! Bad termination status !!!!! " >>test.out
364 echo " !!!!! Restored files differ !!!!! "
365 echo " !!!!! Restored files differ !!!!! " >>test.out
367 echo " Status: backup=$bstat restore=$rstat diff=$dstat"
368 echo " Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
369 echo " Test owner of $SITE_NAME is $EMAIL"
370 echo " Test owner of $SITE_NAME is $EMAIL" >>test.out
374 echo " ===== $TestName OK `date +%R:%S` ===== "
375 echo " ===== $TestName OK `date +%R:%S` ===== " >>test.out
376 if test "$debug" -eq 0 ; then
384 ${rscripts}/copy-tape-confs
385 ${rscripts}/cleanup-tape
390 ${rscripts}/copy-test-confs
396 for i in ${conf}/bacula-fd.conf; do
397 sed 's/Plugin/#Plugin/' $i > $tmp/1
404 if [ -d $cwd/build/src/win32/release32 \
405 -a -d $cwd/build/src/win32/release64 ] \
406 || [ -d $cwd/release32 -a -d $cwd/release64 ]
408 echo -ne "Try to upgrade the FileDaemon:\t"
409 wget -qO - "$WIN32_ADDR:8091/install"
415 if test "x${REGRESS_WAIT}" = "x1"; then
416 echo "Start Bacula under debugger and enter anything when ready ..."
425 if test -n "$DRIVE" -a -n "$SLOT"; then
426 if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
428 if [ ! -d "$dir" ]; then
438 if test a$USE_VTAPE = a; then
448 if test a$USE_VTAPE = a; then
455 # Get a tape from slot1
456 slot=`${scripts}/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
459 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
466 rewind_drive ${TAPE_DRIVE}
467 ${scripts}/$MTX ${AUTOCHANGER} unload $slot ${TAPE_DRIVE} $DRIVE1
468 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
475 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
476 # if 2, load 1; if 0 load 1
480 rewind_drive ${TAPE_DRIVE}
483 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
487 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
488 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
492 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
493 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
497 echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
503 # Save current directory
505 if test "x${REGRESS_DEBUG}" = "x1"; then
511 # Source the configuration variables
514 db_name=${db_name:-"regress"}
515 db_user=${db_user:-"regress"}
516 db_password=${db_password:-""}
517 working=${working:-"$cwd/working"}
518 dumps=${dumps:-"$cwd/dumps"}
519 bin=${bin:-"$cwd/bin"}
522 scripts=${scripts:-"$cwd/bin"}
525 conf=${conf:-"$cwd/bin"}
528 rscripts=${rscripts:-"$cwd/scripts"}
530 tmp=${tmp:-"$cwd/tmp"}
532 # Bacula source directory when copied here
533 # also build directory
534 src=${src:-"$cwd/build"}
536 # Temp source directory so we don't mess up $src
537 tmpsrc=${tmpsrc:-"$cwd/tmp/build"}
549 bperl="perl -Mscripts::functions"
553 touch ${tmp}/dir.out ${tmp}/fd.out ${tmp}/sd.out
557 if [ x$USE_VTAPE = xyes ]; then
558 mkdir -p $working/ach
561 TAPE_DRIVE=$working/ach/drive0
562 TAPE_DRIVE1=$working/ach/drive1
563 AUTOCHANGER=$working/ach/config
564 AUTOCHANGER_SCRIPT=disk-changer
567 cp /dev/null $working/ach/slot$SLOT1
568 cp /dev/null $working/ach/slot$SLOT2
569 cat > $AUTOCHANGER <<EOF
575 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
576 LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
577 export LD_LIBRARY_PATH