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
34 MUID=`/usr/bin/id | awk -F= '{print $2}' | awk -F\( '{print $1}'`
35 if [ $MUID != 0 ] ; then
37 echo "You must be root to run this test."
38 echo " ===== !!!! $TestName not run at `date +%R:%S` ==="
39 echo " ===== !!!! $TestName not run at `date +%R:%S` !!!! ===== " >>test.out
47 if test x${TAPE_DRIVE} = x/dev/null ; then
48 echo "$TestName test needs a tape drive, but has none."
53 require_second_drive()
55 if test x${TAPE_DRIVE1} = x/dev/null ; then
56 echo "$JobName needs second drive, but has none."
63 if test x${AUTOCHANGER} = x/dev/null ; then
64 echo "$TestName needs an autochanger, but has none."
71 if test x${USE_VTAPE} = x ; then
72 echo "$TestName test needs the vtape driver."
80 if [ $os != 'Linux' ]; then
81 echo "This test $TestName runs only on Linux"
86 skip_if_no_autochanger()
88 if test x${AUTOCHANGER} = x/dev/null ; then
89 echo "$TestName test skipped. No autochanger."
97 if test "$debug" -eq 1 ; then
106 if test "$debug" -eq 1 ; then
111 check_files_written()
115 FILES=`awk '/FD Files Written:/ { last=$4 } END { print last }' $LOG`
117 if [ "$NB" != "$FILES" ]; then
118 print_debug "Expect $NB files, get $FILES"
123 ################################################################
124 # Get information from logs
130 RET=`awk -F: "BEGIN { jobid=$JOBID } "'/Prev Backup JobId/ { cjid=$2 } /New Backup JobId/ { if (cjid == jobid) { print $2 } }' $LOG`
136 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`
146 if [ "$RET" -$OP "$TIME" ]; then
147 print_debug "Expect $OP than $TIME sec, get $RET"
156 if test "$debug" -eq 1 ; then
157 ${scripts}/bacula-ctl-sd start
158 ${scripts}/bacula-ctl-fd start $1
159 ${scripts}/bacula-ctl-dir start
160 cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf
163 ${bin}/bacula start >/dev/null 2>&1
164 cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf >/dev/null 2>&1
171 bconsole_file=${1:-${tmp}/bconcmds}
172 if test "$debug" -eq 1 ; then
173 cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf
175 cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf 2>&1 >/dev/null
181 if test "$debug" -eq 1 ; then
182 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf DDS-4 | tee ${tmp}/log1.out
184 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf DDS-4 >${tmp}/log1.out 2>&1
190 if test "$debug" -eq 1 ; then
191 ${bin}/bscan $* | tee ${tmp}/log.out
193 ${bin}/bscan $* 2>&1 >/dev/null
199 B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
200 B_D=`echo $B | awk '{print $3}'`
201 B_t=`echo $B | awk '{print $6}'`
202 B_p=`echo $B | awk '{print $9}'`
204 BSCANLIBDBI="${LIBDBI:+1}"
206 if test "$BSCANLIBDBI" = "1" ; then
207 BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
215 ${bin}/bacula stop 2>&1 >/dev/null
222 check_for_zombie_jobs()
224 ${rscripts}/check_for_zombie_jobs $*
229 if test $# -eq 1; then
237 mv ${conf}/bacula-dir.conf ${bin}/1
238 echo "s%${oldname}%${newname}%g" >${tmp}/1
239 sed -f ${tmp}/1 ${bin}/1 >${conf}/bacula-dir.conf
240 # echo "Job ${oldname} changed to ${newname}"
245 grep "^ Termination: *Backup OK" ${tmp}/log1.out 2>&1 >/dev/null
247 grep "^ Termination: .*Backup Error" ${tmp}/log1.out 2>&1 >/dev/null
248 if test $? -eq 0; then
251 grep "^ Termination: *Restore OK" ${tmp}/log2.out 2>&1 >/dev/null
253 grep "^ Termination: .*Restore Error" ${tmp}/log2.out 2>&1 >/dev/null
254 if test $? -eq 0; then
257 grep "^ Termination: *Restore OK -- warning file count mismatch" ${tmp}/log2.out 2>&1 >/dev/null
258 if test $? -eq 0; then
261 grep "^ Termination: .*Verify Differences" ${tmp}/log2.out 2>&1 >/dev/null
262 if test $? -eq 0; then
265 grep "Encoding error for database" ${tmp}/log1.out > /dev/null
266 if test $? -eq 0; then
267 print_debug "Found database encoding error"
274 if test "$debug" -eq 1 ; then
275 diff -ur ${src} ${tmp}/bacula-restores${src}
277 diff -ur ${src} ${tmp}/bacula-restores${src} 2>&1 >/dev/null
282 check_restore_bin_diff()
284 if test "$debug" -eq 1 ; then
285 diff -ur ${bin} ${tmp}/bacula-restores${bin}
287 diff -ur ${bin} ${tmp}/bacula-restores${bin} 2>&1 >/dev/null
293 check_restore_tmp_build_diff()
295 if test "$debug" -eq 1 ; then
296 diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc}
298 diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc} 2>&1 >/dev/null
305 if [ $zstat != 0 ] ; then
307 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
308 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
309 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
310 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
314 if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
317 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
318 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
319 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
320 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
321 if [ $bstat != 0 -o $rstat != 0 ] ; then
322 echo " !!!!! Bad termination status !!!!! "
323 echo " !!!!! Bad termination status !!!!! " >>test.out
325 echo " !!!!! Restored files differ !!!!! "
326 echo " !!!!! Restored files differ !!!!! " >>test.out
328 echo " Status: backup=$bstat restore=$rstat diff=$dstat"
329 echo " Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
333 echo " ===== $TestName OK `date +%R:%S` ===== "
334 echo " ===== $TestName OK `date +%R:%S` ===== " >>test.out
335 if test "$debug" -eq 0 ; then
343 ${rscripts}/copy-tape-confs
344 ${rscripts}/cleanup-tape
349 ${rscripts}/copy-test-confs
355 if test "x${REGRESS_WAIT}" = "x1"; then
356 echo "Start Bacula under debugger and enter anything when ready ..."
365 if test -n "$DRIVE" -a -n "$SLOT"; then
366 if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
368 if [ ! -d "$dir" ]; then
378 if test a$USE_VTAPE = a; then
388 if test a$USE_VTAPE = a; then
395 # Get a tape from slot1
396 slot=`${scripts}/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
399 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
406 rewind_drive ${TAPE_DRIVE}
407 ${scripts}/$MTX ${AUTOCHANGER} unload $slot ${TAPE_DRIVE} $DRIVE1
408 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
415 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
416 # if 2, load 1; if 0 load 1
420 rewind_drive ${TAPE_DRIVE}
423 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
427 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
428 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
432 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
433 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
437 echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
443 # Save current directory
445 if test "x${REGRESS_DEBUG}" = "x1"; then
451 # Source the configuration variables
454 db_name=${db_name:-"regress"}
455 db_user=${db_user:-"regress"}
456 db_password=${db_password:-""}
457 working=${working:-"$cwd/working"}
458 bin=${bin:-"$cwd/bin"}
461 scripts=${scripts:-"$bin"}
467 rscripts=${rscripts:-"$cwd/scripts"}
469 tmp=${tmp:-"$cwd/tmp"}
471 # Bacula source directory when copied here
472 # also build directory
473 src=${src:-"$cwd/build"}
475 # Temp source directory so we don't mess up $src
476 tmpsrc=${tmpsrc:-"$cwd/tmp/build"}
487 touch ${tmp}/dir.out ${tmp}/fd.out ${tmp}/sd.out
491 if [ x$USE_VTAPE = xyes ]; then
492 mkdir -p $working/ach
495 TAPE_DRIVE=$working/ach/drive0
496 TAPE_DRIVE1=$working/ach/drive1
497 AUTOCHANGER=$working/ach/config
498 AUTOCHANGER_SCRIPT=disk-changer
501 cp /dev/null $working/ach/slot$SLOT1
502 cp /dev/null $working/ach/slot$SLOT2
503 cat > $AUTOCHANGER <<EOF
509 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
510 LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
511 export LD_LIBRARY_PATH