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 cat ${working}/bacula.*.traceback 2>/dev/null
319 cat ${working}/*.bactrace 2>/dev/null
320 if [ $estat != 0 ] ; then
322 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
323 echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
324 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
325 echo " Status: estat=$estat zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
329 if [ $zstat != 0 ] ; then
331 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
332 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
333 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
334 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
338 if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
341 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
342 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
343 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
344 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
345 if [ $bstat != 0 -o $rstat != 0 ] ; then
346 echo " !!!!! Bad termination status !!!!! "
347 echo " !!!!! Bad termination status !!!!! " >>test.out
349 echo " !!!!! Restored files differ !!!!! "
350 echo " !!!!! Restored files differ !!!!! " >>test.out
352 echo " Status: backup=$bstat restore=$rstat diff=$dstat"
353 echo " Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
354 echo " Test owner of $SITE_NAME is $EMAIL"
355 echo " Test owner of $SITE_NAME is $EMAIL" >>test.out
359 echo " ===== $TestName OK `date +%R:%S` ===== "
360 echo " ===== $TestName OK `date +%R:%S` ===== " >>test.out
361 if test "$debug" -eq 0 ; then
369 ${rscripts}/copy-tape-confs
370 ${rscripts}/cleanup-tape
375 ${rscripts}/copy-test-confs
381 for i in ${conf}/bacula-fd.conf; do
382 sed 's/Plugin/#Plugin/' $i > $tmp/1
389 if test "x${REGRESS_WAIT}" = "x1"; then
390 echo "Start Bacula under debugger and enter anything when ready ..."
399 if test -n "$DRIVE" -a -n "$SLOT"; then
400 if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
402 if [ ! -d "$dir" ]; then
412 if test a$USE_VTAPE = a; then
422 if test a$USE_VTAPE = a; then
429 # Get a tape from slot1
430 slot=`${scripts}/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
433 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
440 rewind_drive ${TAPE_DRIVE}
441 ${scripts}/$MTX ${AUTOCHANGER} unload $slot ${TAPE_DRIVE} $DRIVE1
442 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
449 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
450 # if 2, load 1; if 0 load 1
454 rewind_drive ${TAPE_DRIVE}
457 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
461 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
462 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
466 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
467 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
471 echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
477 # Save current directory
479 if test "x${REGRESS_DEBUG}" = "x1"; then
485 # Source the configuration variables
488 db_name=${db_name:-"regress"}
489 db_user=${db_user:-"regress"}
490 db_password=${db_password:-""}
491 working=${working:-"$cwd/working"}
492 bin=${bin:-"$cwd/bin"}
495 scripts=${scripts:-"$bin"}
501 rscripts=${rscripts:-"$cwd/scripts"}
503 tmp=${tmp:-"$cwd/tmp"}
505 # Bacula source directory when copied here
506 # also build directory
507 src=${src:-"$cwd/build"}
509 # Temp source directory so we don't mess up $src
510 tmpsrc=${tmpsrc:-"$cwd/tmp/build"}
522 touch ${tmp}/dir.out ${tmp}/fd.out ${tmp}/sd.out
526 if [ x$USE_VTAPE = xyes ]; then
527 mkdir -p $working/ach
530 TAPE_DRIVE=$working/ach/drive0
531 TAPE_DRIVE1=$working/ach/drive1
532 AUTOCHANGER=$working/ach/config
533 AUTOCHANGER_SCRIPT=disk-changer
536 cp /dev/null $working/ach/slot$SLOT1
537 cp /dev/null $working/ach/slot$SLOT2
538 cat > $AUTOCHANGER <<EOF
544 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
545 LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
546 export LD_LIBRARY_PATH