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 tape | tee ${tmp}/log1.out
188 cat ${tmp}/bconcmds | ${bin}/btape -c ${conf}/bacula-sd.conf tape >${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 if test "$debug" -eq 1 ; then
222 ${bin}/bacula stop 2>&1 >/dev/null
226 check_for_zombie_jobs()
228 ${rscripts}/check_for_zombie_jobs $*
233 if test $# -eq 1; then
241 mv ${conf}/bacula-dir.conf ${bin}/1
242 echo "s%${oldname}%${newname}%g" >${tmp}/1
243 sed -f ${tmp}/1 ${bin}/1 >${conf}/bacula-dir.conf
244 # echo "Job ${oldname} changed to ${newname}"
249 grep "^ Termination: *Backup OK" ${tmp}/log1.out 2>&1 >/dev/null
251 grep "^ Termination: .*Backup Error" ${tmp}/log1.out 2>&1 >/dev/null
252 if test $? -eq 0; then
255 grep "^ Termination: *Restore OK" ${tmp}/log2.out 2>&1 >/dev/null
257 grep "^ Termination: .*Restore Error" ${tmp}/log2.out 2>&1 >/dev/null
258 if test $? -eq 0; then
261 grep "^ Termination: *Restore OK -- warning file count mismatch" ${tmp}/log2.out 2>&1 >/dev/null
262 if test $? -eq 0; then
265 grep "^ Termination: .*Verify Differences" ${tmp}/log2.out 2>&1 >/dev/null
266 if test $? -eq 0; then
269 grep "Encoding error for database" ${tmp}/log1.out > /dev/null
270 if test $? -eq 0; then
271 print_debug "Found database encoding error"
278 if test "$debug" -eq 1 ; then
279 diff -ur ${src} ${tmp}/bacula-restores${src}
281 diff -ur ${src} ${tmp}/bacula-restores${src} 2>&1 >/dev/null
286 check_restore_bin_diff()
288 if test "$debug" -eq 1 ; then
289 diff -ur ${bin} ${tmp}/bacula-restores${bin}
291 diff -ur ${bin} ${tmp}/bacula-restores${bin} 2>&1 >/dev/null
297 check_restore_tmp_build_diff()
299 if test "$debug" -eq 1 ; then
300 diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc}
302 diff -ur ${tmpsrc} ${tmp}/bacula-restores${tmpsrc} 2>&1 >/dev/null
309 if [ $zstat != 0 ] ; then
311 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
312 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
313 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
314 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
318 if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
321 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
322 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
323 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
324 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
325 if [ $bstat != 0 -o $rstat != 0 ] ; then
326 echo " !!!!! Bad termination status !!!!! "
327 echo " !!!!! Bad termination status !!!!! " >>test.out
329 echo " !!!!! Restored files differ !!!!! "
330 echo " !!!!! Restored files differ !!!!! " >>test.out
332 echo " Status: backup=$bstat restore=$rstat diff=$dstat"
333 echo " Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
337 echo " ===== $TestName OK `date +%R:%S` ===== "
338 echo " ===== $TestName OK `date +%R:%S` ===== " >>test.out
339 if test "$debug" -eq 0 ; then
347 ${rscripts}/copy-tape-confs
348 ${rscripts}/cleanup-tape
353 ${rscripts}/copy-test-confs
359 for i in ${conf}/bacula-fd.conf; do
360 sed 's/Plugin/#Plugin/' $i > $tmp/1
367 if test "x${REGRESS_WAIT}" = "x1"; then
368 echo "Start Bacula under debugger and enter anything when ready ..."
377 if test -n "$DRIVE" -a -n "$SLOT"; then
378 if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
380 if [ ! -d "$dir" ]; then
390 if test a$USE_VTAPE = a; then
400 if test a$USE_VTAPE = a; then
407 # Get a tape from slot1
408 slot=`${scripts}/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
411 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
418 rewind_drive ${TAPE_DRIVE}
419 ${scripts}/$MTX ${AUTOCHANGER} unload $slot ${TAPE_DRIVE} $DRIVE1
420 ${scripts}/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
427 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
428 # if 2, load 1; if 0 load 1
432 rewind_drive ${TAPE_DRIVE}
435 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
439 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
440 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
444 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
445 ${scripts}/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
449 echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
455 # Save current directory
457 if test "x${REGRESS_DEBUG}" = "x1"; then
463 # Source the configuration variables
466 db_name=${db_name:-"regress"}
467 db_user=${db_user:-"regress"}
468 db_password=${db_password:-""}
469 working=${working:-"$cwd/working"}
470 bin=${bin:-"$cwd/bin"}
473 scripts=${scripts:-"$bin"}
479 rscripts=${rscripts:-"$cwd/scripts"}
481 tmp=${tmp:-"$cwd/tmp"}
483 # Bacula source directory when copied here
484 # also build directory
485 src=${src:-"$cwd/build"}
487 # Temp source directory so we don't mess up $src
488 tmpsrc=${tmpsrc:-"$cwd/tmp/build"}
500 touch ${tmp}/dir.out ${tmp}/fd.out ${tmp}/sd.out
504 if [ x$USE_VTAPE = xyes ]; then
505 mkdir -p $working/ach
508 TAPE_DRIVE=$working/ach/drive0
509 TAPE_DRIVE1=$working/ach/drive1
510 AUTOCHANGER=$working/ach/config
511 AUTOCHANGER_SCRIPT=disk-changer
514 cp /dev/null $working/ach/slot$SLOT1
515 cp /dev/null $working/ach/slot$SLOT2
516 cat > $AUTOCHANGER <<EOF
522 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
523 LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
524 export LD_LIBRARY_PATH