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
40 MUID=`/usr/bin/id | awk -F= '{print $2}' | awk -F\( '{print $1}'`
41 if [ $MUID != 0 ] ; then
43 echo "You must be root to run this test."
44 echo " ===== !!!! $TestName not run at `date +%R:%S` ==="
45 echo " ===== !!!! $TestName not run at `date +%R:%S` !!!! ===== " >>test.out
53 if test x${TAPE_DRIVE} = x/dev/null ; then
54 echo "$TestName test needs a tape drive, but has none."
59 require_second_drive()
61 if test x${TAPE_DRIVE1} = x/dev/null ; then
62 echo "$JobName needs second drive, but has none."
69 if test x${AUTOCHANGER} = x/dev/null ; then
70 echo "$TestName needs an autochanger, but has none."
77 if test x${USE_VTAPE} = x ; then
78 echo "$TestName test needs the vtape driver."
86 if [ $os != 'Linux' ]; then
87 echo "This test $TestName runs only on Linux"
92 skip_if_no_autochanger()
94 if test x${AUTOCHANGER} = x/dev/null ; then
95 echo "$TestName test skipped. No autochanger."
103 if test "$debug" -eq 1 ; then
112 if test "$debug" -eq 1 ; then
117 check_files_written()
121 FILES=`awk '/FD Files Written:/ { last=$4 } END { print last }' $LOG`
123 if [ "$NB" != "$FILES" ]; then
124 print_debug "Expect $NB files, get $FILES"
129 ################################################################
130 # Get information from logs
136 RET=`awk -F: "BEGIN { jobid=$JOBID } "'/Prev Backup JobId/ { cjid=$2 } /New Backup JobId/ { if (cjid == jobid) { print $2 } }' $LOG`
142 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`
152 if [ "$RET" -$OP "$TIME" ]; then
153 print_debug "Expect $OP than $TIME sec, get $RET"
163 if test "$debug" -eq 1 ; then
164 ${scripts}/bacula-ctl-sd start -m
165 ${scripts}/bacula-ctl-fd start -m $1
166 ${scripts}/bacula-ctl-dir start -m
167 cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf
170 ${bin}/bacula start >/dev/null 2>&1
171 cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf >/dev/null 2>&1
178 bconsole_file=${1:-${tmp}/bconcmds}
179 if test "$debug" -eq 1 ; then
180 cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf
182 cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf 2>&1 >/dev/null
188 if test "$debug" -eq 1 ; then
189 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape | tee ${tmp}/log1.out
191 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape >${tmp}/log1.out 2>&1
197 if test "$debug" -eq 1 ; then
198 ${bin}/bscan $* | tee ${tmp}/log.out
200 ${bin}/bscan $* 2>&1 >/dev/null
206 B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
207 B_D=`echo $B | awk '{print $3}'`
208 B_t=`echo $B | awk '{print $6}'`
209 B_p=`echo $B | awk '{print $9}'`
211 BSCANLIBDBI="${LIBDBI:+1}"
213 if test "$BSCANLIBDBI" = "1" ; then
214 BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
222 if test "$debug" -eq 1 ; then
225 ${bin}/bacula stop 2>&1 >/dev/null
229 check_for_zombie_jobs()
231 ${rscripts}/check_for_zombie_jobs $*
236 if test $# -eq 1; then
244 mv ${conf}/bacula-dir.conf ${bin}/1
245 echo "s%${oldname}%${newname}%g" >${tmp}/1
246 sed -f ${tmp}/1 ${bin}/1 >${conf}/bacula-dir.conf
247 # echo "Job ${oldname} changed to ${newname}"
252 grep "^ Termination: *Backup OK" ${tmp}/log1.out 2>&1 >/dev/null
254 grep "^ Termination: .*Backup Error" ${tmp}/log1.out 2>&1 >/dev/null
255 if test $? -eq 0; then
258 grep "^ Termination: *Restore OK" ${tmp}/log2.out 2>&1 >/dev/null
260 grep "^ Termination: .*Restore Error" ${tmp}/log2.out 2>&1 >/dev/null
261 if test $? -eq 0; then
264 grep "^ Termination: *Restore OK -- warning file count mismatch" ${tmp}/log2.out 2>&1 >/dev/null
265 if test $? -eq 0; then
268 grep "^ Termination: .*Verify Differences" ${tmp}/log2.out 2>&1 >/dev/null
269 if test $? -eq 0; then
272 grep "Encoding error for database" ${tmp}/log1.out > /dev/null
273 if test $? -eq 0; then
274 print_debug "Found database encoding error"
281 if test "$debug" -eq 1 ; then
282 diff -ur ${src} ${tmp}/bacula-restores${src}
284 diff -ur ${src} ${tmp}/bacula-restores${src} 2>&1 >/dev/null
289 check_restore_bin_diff()
291 if test "$debug" -eq 1 ; then
292 diff -ur ${bin} ${tmp}/bacula-restores${bin}
294 diff -ur ${bin} ${tmp}/bacula-restores${bin} 2>&1 >/dev/null
300 check_restore_tmp_build_diff()
302 if test "$debug" -eq 1 ; then
303 diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc}
305 diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc} 2>&1 >/dev/null
310 # bstat is backup error
311 # dstat is diff difference
312 # estat is special error status (shown by print_debug message)
313 # rstat is restore status
314 # zstat is zombie job(s)
318 if [ x$notracedump != xyes ]; then
319 cat ${working}/bacula.*.traceback 2>/dev/null
320 cat ${working}/*.bactrace 2>/dev/null
322 if [ $estat != 0 ] ; then
324 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
325 echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
326 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
327 echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
331 if [ $zstat != 0 ] ; then
333 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
334 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
335 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
336 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
340 if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
343 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
344 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
345 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
346 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
347 if [ $bstat != 0 -o $rstat != 0 ] ; then
348 echo " !!!!! Bad termination status !!!!! "
349 echo " !!!!! Bad termination status !!!!! " >>test.out
351 echo " !!!!! Restored files differ !!!!! "
352 echo " !!!!! Restored files differ !!!!! " >>test.out
354 echo " Status: backup=$bstat restore=$rstat diff=$dstat"
355 echo " Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
356 echo " Test owner of $SITE_NAME is $EMAIL"
357 echo " Test owner of $SITE_NAME is $EMAIL" >>test.out
361 echo " ===== $TestName OK `date +%R:%S` ===== "
362 echo " ===== $TestName OK `date +%R:%S` ===== " >>test.out
363 if test "$debug" -eq 0 ; then
371 ${rscripts}/copy-tape-confs
372 ${rscripts}/cleanup-tape
377 ${rscripts}/copy-test-confs
383 for i in ${conf}/bacula-fd.conf; do
384 sed 's/Plugin/#Plugin/' $i > $tmp/1
391 if test "x${REGRESS_WAIT}" = "x1"; then
392 echo "Start Bacula under debugger and enter anything when ready ..."
401 if test -n "$DRIVE" -a -n "$SLOT"; then
402 if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
404 if [ ! -d "$dir" ]; then
414 if test a$USE_VTAPE = a; then
424 if test a$USE_VTAPE = a; then
431 # Get a tape from slot1
432 slot=`${scripts}/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
435 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
442 rewind_drive ${TAPE_DRIVE}
443 ${scripts}/$MTX ${AUTOCHANGER} unload $slot ${TAPE_DRIVE} $DRIVE1
444 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
451 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
452 # if 2, load 1; if 0 load 1
456 rewind_drive ${TAPE_DRIVE}
459 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
463 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
464 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
468 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
469 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
473 echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
479 # Save current directory
481 if test "x${REGRESS_DEBUG}" = "x1"; then
487 # Source the configuration variables
490 db_name=${db_name:-"regress"}
491 db_user=${db_user:-"regress"}
492 db_password=${db_password:-""}
493 working=${working:-"$cwd/working"}
494 bin=${bin:-"$cwd/bin"}
497 scripts=${scripts:-"$bin"}
503 rscripts=${rscripts:-"$cwd/scripts"}
505 tmp=${tmp:-"$cwd/tmp"}
507 # Bacula source directory when copied here
508 # also build directory
509 src=${src:-"$cwd/build"}
511 # Temp source directory so we don't mess up $src
512 tmpsrc=${tmpsrc:-"$cwd/tmp/build"}
524 touch ${tmp}/dir.out ${tmp}/fd.out ${tmp}/sd.out
528 if [ x$USE_VTAPE = xyes ]; then
529 mkdir -p $working/ach
532 TAPE_DRIVE=$working/ach/drive0
533 TAPE_DRIVE1=$working/ach/drive1
534 AUTOCHANGER=$working/ach/config
535 AUTOCHANGER_SCRIPT=disk-changer
538 cp /dev/null $working/ach/slot$SLOT1
539 cp /dev/null $working/ach/slot$SLOT2
540 cat > $AUTOCHANGER <<EOF
546 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
547 LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
548 export LD_LIBRARY_PATH