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
38 MUID=`/usr/bin/id | awk -F= '{print $2}' | awk -F\( '{print $1}'`
39 if [ $MUID != 0 ] ; then
41 echo "You must be root to run this test."
42 echo " ===== !!!! $TestName not run at `date +%R:%S` ==="
43 echo " ===== !!!! $TestName not run at `date +%R:%S` !!!! ===== " >>test.out
51 if test x${TAPE_DRIVE} = x/dev/null ; then
52 echo "$TestName test needs a tape drive, but has none."
57 require_second_drive()
59 if test x${TAPE_DRIVE1} = x/dev/null ; then
60 echo "$JobName needs second drive, but has none."
67 if test x${AUTOCHANGER} = x/dev/null ; then
68 echo "$TestName needs an autochanger, but has none."
75 if test x${USE_VTAPE} = x ; then
76 echo "$TestName test needs the vtape driver."
84 if [ $os != 'Linux' ]; then
85 echo "This test $TestName runs only on Linux"
90 skip_if_no_autochanger()
92 if test x${AUTOCHANGER} = x/dev/null ; then
93 echo "$TestName test skipped. No autochanger."
101 if test "$debug" -eq 1 ; then
110 if test "$debug" -eq 1 ; then
115 check_files_written()
119 FILES=`awk '/FD Files Written:/ { last=$4 } END { print last }' $LOG`
121 if [ "$NB" != "$FILES" ]; then
122 print_debug "Expect $NB files, get $FILES"
127 ################################################################
128 # Get information from logs
134 RET=`awk -F: "BEGIN { jobid=$JOBID } "'/Prev Backup JobId/ { cjid=$2 } /New Backup JobId/ { if (cjid == jobid) { print $2 } }' $LOG`
140 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`
150 if [ "$RET" -$OP "$TIME" ]; then
151 print_debug "Expect $OP than $TIME sec, get $RET"
160 if test "$debug" -eq 1 ; then
161 ${scripts}/bacula-ctl-sd start
162 ${scripts}/bacula-ctl-fd start $1
163 ${scripts}/bacula-ctl-dir start
164 cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf
167 ${bin}/bacula start >/dev/null 2>&1
168 cat ${tmp}/bconcmds | ${bin}/bconsole -c ${conf}/bconsole.conf >/dev/null 2>&1
175 bconsole_file=${1:-${tmp}/bconcmds}
176 if test "$debug" -eq 1 ; then
177 cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf
179 cat $bconsole_file | ${bin}/bconsole -c ${conf}/bconsole.conf 2>&1 >/dev/null
185 if test "$debug" -eq 1 ; then
186 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf DDS-4 | tee ${tmp}/log1.out
188 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf DDS-4 >${tmp}/log1.out 2>&1
194 if test "$debug" -eq 1 ; then
195 ${bin}/bscan $* | tee ${tmp}/log.out
197 ${bin}/bscan $* 2>&1 >/dev/null
203 B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
204 B_D=`echo $B | awk '{print $3}'`
205 B_t=`echo $B | awk '{print $6}'`
206 B_p=`echo $B | awk '{print $9}'`
208 BSCANLIBDBI="${LIBDBI:+1}"
210 if test "$BSCANLIBDBI" = "1" ; then
211 BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
219 ${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 for i in ${conf}/bacula-fd.conf; do
356 sed 's/Plugin/#Plugin/' $i > $tmp/1
363 if test "x${REGRESS_WAIT}" = "x1"; then
364 echo "Start Bacula under debugger and enter anything when ready ..."
373 if test -n "$DRIVE" -a -n "$SLOT"; then
374 if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
376 if [ ! -d "$dir" ]; then
386 if test a$USE_VTAPE = a; then
396 if test a$USE_VTAPE = a; then
403 # Get a tape from slot1
404 slot=`${scripts}/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
407 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
414 rewind_drive ${TAPE_DRIVE}
415 ${scripts}/$MTX ${AUTOCHANGER} unload $slot ${TAPE_DRIVE} $DRIVE1
416 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
423 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
424 # if 2, load 1; if 0 load 1
428 rewind_drive ${TAPE_DRIVE}
431 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
435 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
436 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
440 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
441 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
445 echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
451 # Save current directory
453 if test "x${REGRESS_DEBUG}" = "x1"; then
459 # Source the configuration variables
462 db_name=${db_name:-"regress"}
463 db_user=${db_user:-"regress"}
464 db_password=${db_password:-""}
465 working=${working:-"$cwd/working"}
466 bin=${bin:-"$cwd/bin"}
469 scripts=${scripts:-"$bin"}
475 rscripts=${rscripts:-"$cwd/scripts"}
477 tmp=${tmp:-"$cwd/tmp"}
479 # Bacula source directory when copied here
480 # also build directory
481 src=${src:-"$cwd/build"}
483 # Temp source directory so we don't mess up $src
484 tmpsrc=${tmpsrc:-"$cwd/tmp/build"}
496 touch ${tmp}/dir.out ${tmp}/fd.out ${tmp}/sd.out
500 if [ x$USE_VTAPE = xyes ]; then
501 mkdir -p $working/ach
504 TAPE_DRIVE=$working/ach/drive0
505 TAPE_DRIVE1=$working/ach/drive1
506 AUTOCHANGER=$working/ach/config
507 AUTOCHANGER_SCRIPT=disk-changer
510 cp /dev/null $working/ach/slot$SLOT1
511 cp /dev/null $working/ach/slot$SLOT2
512 cat > $AUTOCHANGER <<EOF
518 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
519 LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
520 export LD_LIBRARY_PATH