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 if test "$debug" -eq 1 ; then
118 check_files_written()
122 FILES=`awk '/FD Files Written:/ { last=$4 } END { print last }' $LOG`
124 if [ "$NB" != "$FILES" ]; then
125 print_debug "Expect $NB files, get $FILES"
130 ################################################################
131 # Get information from logs
137 RET=`awk -F: "BEGIN { jobid=$JOBID } "'/Prev Backup JobId/ { cjid=$2 } /New Backup JobId/ { if (cjid == jobid) { print $2 } }' $LOG`
143 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`
153 if [ "$RET" -$OP "$TIME" ]; then
154 print_debug "Expect $OP than $TIME sec, get $RET"
164 if test "$debug" -eq 1 ; then
165 ${scripts}/bacula-ctl-sd start -m
166 ${scripts}/bacula-ctl-fd start -m $1
167 ${scripts}/bacula-ctl-dir start -m
168 cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf
171 ${bin}/bacula start >/dev/null 2>&1
172 cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf >/dev/null 2>&1
179 bconsole_file=${1:-${tmp}/bconcmds}
180 if test "$debug" -eq 1 ; then
181 cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf
183 cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf 2>&1 >/dev/null
189 if test "$debug" -eq 1 ; then
190 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape | tee ${tmp}/log1.out
192 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape >${tmp}/log1.out 2>&1
198 if test "$debug" -eq 1 ; then
199 ${bin}/bscan $* | tee ${tmp}/log.out
201 ${bin}/bscan $* 2>&1 >/dev/null
207 B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
208 B_D=`echo $B | awk '{print $3}'`
209 B_t=`echo $B | awk '{print $6}'`
210 B_p=`echo $B | awk '{print $9}'`
212 BSCANLIBDBI="${LIBDBI:+1}"
214 if test "$BSCANLIBDBI" = "1" ; then
215 BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
223 if test "$debug" -eq 1 ; then
226 ${bin}/bacula stop 2>&1 >/dev/null
230 check_for_zombie_jobs()
232 ${rscripts}/check_for_zombie_jobs $*
237 if test $# -eq 1; then
245 mv ${conf}/bacula-dir.conf ${bin}/1
246 echo "s%${oldname}%${newname}%g" >${tmp}/1
247 sed -f ${tmp}/1 ${bin}/1 >${conf}/bacula-dir.conf
248 # echo "Job ${oldname} changed to ${newname}"
253 grep "^ Termination: *Backup OK" ${tmp}/log1.out 2>&1 >/dev/null
255 grep "^ Termination: .*Backup Error" ${tmp}/log1.out 2>&1 >/dev/null
256 if test $? -eq 0; then
259 grep "^ Termination: *Restore OK" ${tmp}/log2.out 2>&1 >/dev/null
261 grep "^ Termination: .*Restore Error" ${tmp}/log2.out 2>&1 >/dev/null
262 if test $? -eq 0; then
265 grep "^ Termination: *Restore OK -- warning file count mismatch" ${tmp}/log2.out 2>&1 >/dev/null
266 if test $? -eq 0; then
269 grep "^ Termination: .*Verify Differences" ${tmp}/log2.out 2>&1 >/dev/null
270 if test $? -eq 0; then
273 grep "Encoding error for database" ${tmp}/log1.out > /dev/null
274 if test $? -eq 0; then
275 print_debug "Found database encoding error"
282 if test "$debug" -eq 1 ; then
283 diff -ur ${src} ${tmp}/bacula-restores${src}
285 diff -ur ${src} ${tmp}/bacula-restores${src} 2>&1 >/dev/null
290 check_restore_bin_diff()
292 if test "$debug" -eq 1 ; then
293 diff -ur ${bin} ${tmp}/bacula-restores${bin}
295 diff -ur ${bin} ${tmp}/bacula-restores${bin} 2>&1 >/dev/null
301 check_restore_tmp_build_diff()
303 if test "$debug" -eq 1 ; then
304 diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc}
306 diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc} 2>&1 >/dev/null
311 # bstat is backup error
312 # dstat is diff difference
313 # estat is special error status (shown by print_debug message)
314 # rstat is restore status
315 # zstat is zombie job(s)
319 if [ x$notracedump != xyes ]; then
320 cat ${working}/bacula.*.traceback 2>/dev/null
321 cp -f ${working}/bacula.*.traceback ${dumps} 2>/dev/null
322 cat ${working}/*.bactrace 2>/dev/null
323 cp -f ${working}/*.bactrace ${dumps} 2>/dev/null
325 if [ $estat != 0 ] ; then
327 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
328 echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
329 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
330 echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
334 if [ $zstat != 0 ] ; then
336 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
337 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
338 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
339 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
343 if [ $dstat != 0 -o $bstat != 0 -o $rstat != 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
350 if [ $bstat != 0 -o $rstat != 0 ] ; then
351 echo " !!!!! Bad termination status !!!!! "
352 echo " !!!!! Bad termination status !!!!! " >>test.out
354 echo " !!!!! Restored files differ !!!!! "
355 echo " !!!!! Restored files differ !!!!! " >>test.out
357 echo " Status: backup=$bstat restore=$rstat diff=$dstat"
358 echo " Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
359 echo " Test owner of $SITE_NAME is $EMAIL"
360 echo " Test owner of $SITE_NAME is $EMAIL" >>test.out
364 echo " ===== $TestName OK `date +%R:%S` ===== "
365 echo " ===== $TestName OK `date +%R:%S` ===== " >>test.out
366 if test "$debug" -eq 0 ; then
374 ${rscripts}/copy-tape-confs
375 ${rscripts}/cleanup-tape
380 ${rscripts}/copy-test-confs
386 for i in ${conf}/bacula-fd.conf; do
387 sed 's/Plugin/#Plugin/' $i > $tmp/1
394 if test "x${REGRESS_WAIT}" = "x1"; then
395 echo "Start Bacula under debugger and enter anything when ready ..."
404 if test -n "$DRIVE" -a -n "$SLOT"; then
405 if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
407 if [ ! -d "$dir" ]; then
417 if test a$USE_VTAPE = a; then
427 if test a$USE_VTAPE = a; then
434 # Get a tape from slot1
435 slot=`${scripts}/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
438 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
445 rewind_drive ${TAPE_DRIVE}
446 ${scripts}/$MTX ${AUTOCHANGER} unload $slot ${TAPE_DRIVE} $DRIVE1
447 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
454 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
455 # if 2, load 1; if 0 load 1
459 rewind_drive ${TAPE_DRIVE}
462 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
466 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
467 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
471 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
472 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
476 echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
482 # Save current directory
484 if test "x${REGRESS_DEBUG}" = "x1"; then
490 # Source the configuration variables
493 db_name=${db_name:-"regress"}
494 db_user=${db_user:-"regress"}
495 db_password=${db_password:-""}
496 working=${working:-"$cwd/working"}
497 dumps=${dumps:-"$cwd/dumps"}
498 bin=${bin:-"$cwd/bin"}
501 scripts=${scripts:-"$bin"}
507 rscripts=${rscripts:-"$cwd/scripts"}
509 tmp=${tmp:-"$cwd/tmp"}
511 # Bacula source directory when copied here
512 # also build directory
513 src=${src:-"$cwd/build"}
515 # Temp source directory so we don't mess up $src
516 tmpsrc=${tmpsrc:-"$cwd/tmp/build"}
528 bperl="perl -Mscripts::functions"
532 touch ${tmp}/dir.out ${tmp}/fd.out ${tmp}/sd.out
536 if [ x$USE_VTAPE = xyes ]; then
537 mkdir -p $working/ach
540 TAPE_DRIVE=$working/ach/drive0
541 TAPE_DRIVE1=$working/ach/drive1
542 AUTOCHANGER=$working/ach/config
543 AUTOCHANGER_SCRIPT=disk-changer
546 cp /dev/null $working/ach/slot$SLOT1
547 cp /dev/null $working/ach/slot$SLOT2
548 cat > $AUTOCHANGER <<EOF
554 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
555 LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
556 export LD_LIBRARY_PATH