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 cat ${working}/*.bactrace 2>/dev/null
323 if [ $estat != 0 ] ; then
325 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
326 echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
327 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
328 echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
332 if [ $zstat != 0 ] ; then
334 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
335 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
336 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
337 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
341 if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
344 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
345 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
346 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
347 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
348 if [ $bstat != 0 -o $rstat != 0 ] ; then
349 echo " !!!!! Bad termination status !!!!! "
350 echo " !!!!! Bad termination status !!!!! " >>test.out
352 echo " !!!!! Restored files differ !!!!! "
353 echo " !!!!! Restored files differ !!!!! " >>test.out
355 echo " Status: backup=$bstat restore=$rstat diff=$dstat"
356 echo " Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
357 echo " Test owner of $SITE_NAME is $EMAIL"
358 echo " Test owner of $SITE_NAME is $EMAIL" >>test.out
362 echo " ===== $TestName OK `date +%R:%S` ===== "
363 echo " ===== $TestName OK `date +%R:%S` ===== " >>test.out
364 if test "$debug" -eq 0 ; then
372 ${rscripts}/copy-tape-confs
373 ${rscripts}/cleanup-tape
378 ${rscripts}/copy-test-confs
384 for i in ${conf}/bacula-fd.conf; do
385 sed 's/Plugin/#Plugin/' $i > $tmp/1
392 if test "x${REGRESS_WAIT}" = "x1"; then
393 echo "Start Bacula under debugger and enter anything when ready ..."
402 if test -n "$DRIVE" -a -n "$SLOT"; then
403 if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
405 if [ ! -d "$dir" ]; then
415 if test a$USE_VTAPE = a; then
425 if test a$USE_VTAPE = a; then
432 # Get a tape from slot1
433 slot=`${scripts}/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
436 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
443 rewind_drive ${TAPE_DRIVE}
444 ${scripts}/$MTX ${AUTOCHANGER} unload $slot ${TAPE_DRIVE} $DRIVE1
445 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
452 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
453 # if 2, load 1; if 0 load 1
457 rewind_drive ${TAPE_DRIVE}
460 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
464 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
465 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
469 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
470 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
474 echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
480 # Save current directory
482 if test "x${REGRESS_DEBUG}" = "x1"; then
488 # Source the configuration variables
491 db_name=${db_name:-"regress"}
492 db_user=${db_user:-"regress"}
493 db_password=${db_password:-""}
494 working=${working:-"$cwd/working"}
495 bin=${bin:-"$cwd/bin"}
498 scripts=${scripts:-"$bin"}
504 rscripts=${rscripts:-"$cwd/scripts"}
506 tmp=${tmp:-"$cwd/tmp"}
508 # Bacula source directory when copied here
509 # also build directory
510 src=${src:-"$cwd/build"}
512 # Temp source directory so we don't mess up $src
513 tmpsrc=${tmpsrc:-"$cwd/tmp/build"}
524 bperl="perl -Mscripts::functions"
528 touch ${tmp}/dir.out ${tmp}/fd.out ${tmp}/sd.out
532 if [ x$USE_VTAPE = xyes ]; then
533 mkdir -p $working/ach
536 TAPE_DRIVE=$working/ach/drive0
537 TAPE_DRIVE1=$working/ach/drive1
538 AUTOCHANGER=$working/ach/config
539 AUTOCHANGER_SCRIPT=disk-changer
542 cp /dev/null $working/ach/slot$SLOT1
543 cp /dev/null $working/ach/slot$SLOT2
544 cat > $AUTOCHANGER <<EOF
550 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
551 LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
552 export LD_LIBRARY_PATH