2 # A set of useful functions to be sourced in each test
8 $bin/bacula-dir -d50 -t -c $cwd/scripts/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 bin/bacula-dir.conf tmp/1
23 sed -f ${outf} tmp/1 > bin/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 bin/bacula-ctl-sd start
158 bin/bacula-ctl-fd start $1
159 bin/bacula-ctl-dir start
160 cat tmp/bconcmds | $bin/bconsole -c bin/bconsole.conf
163 bin/bacula start >/dev/null 2>&1
164 cat tmp/bconcmds | $bin/bconsole -c bin/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 bin/bconsole.conf
175 cat $bconsole_file | $bin/bconsole -c bin/bconsole.conf 2>&1 >/dev/null
181 if test "$debug" -eq 1 ; then
182 cat tmp/bconcmds | $bin/btape -c bin/bacula-sd.conf DDS-4 | tee tmp/log1.out
184 cat tmp/bconcmds | $bin/btape -c bin/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 scripts/check_for_zombie_jobs $*
229 if test $# -eq 1; then
237 mv bin/bacula-dir.conf bin/1
238 echo "s%${oldname}%${newname}%g" >tmp/1
239 sed -f tmp/1 bin/1 >bin/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 build tmp/bacula-restores${cwd}/build
277 diff -ur build tmp/bacula-restores${cwd}/build 2>&1 >/dev/null
282 check_restore_tmp_build_diff()
284 if test "$debug" -eq 1 ; then
285 diff -ur tmp/build tmp/bacula-restores${cwd}/tmp/build
287 diff -ur tmp/build tmp/bacula-restores${cwd}/tmp/build 2>&1 >/dev/null
294 if [ $zstat != 0 ] ; then
296 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
297 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
298 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
299 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
303 if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
306 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
307 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
308 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
309 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
310 if [ $bstat != 0 -o $rstat != 0 ] ; then
311 echo " !!!!! Bad termination status !!!!! "
312 echo " !!!!! Bad termination status !!!!! " >>test.out
314 echo " !!!!! Restored files differ !!!!! "
315 echo " !!!!! Restored files differ !!!!! " >>test.out
317 echo " Status: backup=$bstat restore=$rstat diff=$dstat"
318 echo " Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
322 echo " ===== $TestName OK `date +%R:%S` ===== "
323 echo " ===== $TestName OK `date +%R:%S` ===== " >>test.out
324 if test "$debug" -eq 0 ; then
332 scripts/copy-tape-confs
338 scripts/copy-test-confs
344 if test "x${REGRESS_WAIT}" = "x1"; then
345 echo "Start Bacula under debugger and enter anything when ready ..."
354 if test -n "$DRIVE" -a -n "$SLOT"; then
355 if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
364 if test a$USE_VTAPE = a; then
374 if test a$USE_VTAPE = a; then
381 # Get a tape from slot1
382 slot=`$scripts/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
385 $scripts/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
392 rewind_drive ${TAPE_DRIVE}
393 $scripts/$MTX ${AUTOCHANGER} unload $slot ${TAPE_DRIVE} $DRIVE1
394 $scripts/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
401 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
402 # if 2, load 1; if 0 load 1
406 rewind_drive ${TAPE_DRIVE}
409 $scripts/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
413 $scripts/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
414 $scripts/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
418 $scripts/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
419 $scripts/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
423 echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
429 # Save current directory
431 if test "x${REGRESS_DEBUG}" = "x1"; then
437 # Source the configuration variables
440 db_name=${db_name:-"regress"}
441 db_user=${db_user:-"regress"}
442 db_password=${db_password:-""}
443 working=${working:-"$cwd/working"}
444 bin=${bin:-"$cwd/bin"}
445 scripts=${scripts:-"$bin"}
453 if [ x$USE_VTAPE = xyes ]; then
454 mkdir -p $working/ach
457 TAPE_DRIVE=$working/ach/drive1
458 TAPE_DRIVE1=$working/ach/drive1
459 AUTOCHANGER=$working/ach/config
460 AUTOCHANGER_SCRIPT=disk-changer
463 cat > $AUTOCHANGER <<EOF
469 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
470 LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
471 export LD_LIBRARY_PATH