2 # A set of useful functions to be sourced in each test
10 echo "s% mail =%# mail = %g" >${outf}
11 echo "s% operator =%# operator =%g" >>${outf}
12 cp bin/bacula-dir.conf tmp/1
13 sed -f ${outf} tmp/1 > bin/bacula-dir.conf
16 echo " === Starting $TestName at `date +%R:%S` ==="
17 echo " === Starting $TestName at `date +%R:%S` ===" >> working/log
24 MUID=`/usr/bin/id | awk -F= '{print $2}' | awk -F\( '{print $1}'`
25 if [ $MUID != 0 ] ; then
27 echo "You must be root to run this test."
28 echo " ===== !!!! $TestName not run at `date +%R:%S` ==="
29 echo " ===== !!!! $TestName not run at `date +%R:%S` !!!! ===== " >>test.out
37 if test x${TAPE_DRIVE} = x/dev/null ; then
38 echo "$TestName test needs a tape drive, but has none."
43 require_second_drive()
45 if test x${TAPE_DRIVE1} = x/dev/null ; then
46 echo "$JobName needs second drive, but has none."
53 if test x${AUTOCHANGER} = x/dev/null ; then
54 echo "$TestName needs an autochanger, but has none."
61 if test x${USE_VTAPE} = x ; then
62 echo "$TestName test needs the vtape driver."
70 if [ $os != 'Linux' ]; then
71 echo "This test $TestName runs only on Linux"
76 skip_if_no_autochanger()
78 if test x${AUTOCHANGER} = x/dev/null ; then
79 echo "$TestName test skipped. No autochanger."
87 if test "$debug" -eq 1 ; then
96 if test "$debug" -eq 1 ; then
101 check_files_written()
105 FILES=`awk '/FD Files Written:/ { last=$4 } END { print last }' $LOG`
107 if [ "$NB" != "$FILES" ]; then
108 print_debug "Expect $NB files, get $FILES"
113 ################################################################
114 # Get information from logs
120 RET=`awk -F: "BEGIN { jobid=$JOBID } "'/Prev Backup JobId/ { cjid=$2 } /New Backup JobId/ { if (cjid == jobid) { print $2 } }' $LOG`
126 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`
136 if [ "$RET" -$OP "$TIME" ]; then
137 print_debug "Expect $OP than $TIME sec, get $RET"
146 if test "$debug" -eq 1 ; then
147 bin/bacula-ctl-sd start
148 bin/bacula-ctl-fd start $1
149 bin/bacula-ctl-dir start
150 cat tmp/bconcmds | $bin/bconsole -c bin/bconsole.conf
153 bin/bacula start >/dev/null 2>&1
154 cat tmp/bconcmds | $bin/bconsole -c bin/bconsole.conf >/dev/null 2>&1
161 bconsole_file=${1:-tmp/bconcmds}
162 if test "$debug" -eq 1 ; then
163 cat $bconsole_file | $bin/bconsole -c bin/bconsole.conf
165 cat $bconsole_file | $bin/bconsole -c bin/bconsole.conf 2>&1 >/dev/null
171 if test "$debug" -eq 1 ; then
172 cat tmp/bconcmds | $bin/btape -c bin/bacula-sd.conf DDS-4 | tee tmp/log1.out
174 cat tmp/bconcmds | $bin/btape -c bin/bacula-sd.conf DDS-4 >tmp/log1.out 2>&1
180 if test "$debug" -eq 1 ; then
181 $bin/bscan $* | tee tmp/log.out
183 $bin/bscan $* 2>&1 >/dev/null
189 B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
190 B_D=`echo $B | awk '{print $3}'`
191 B_t=`echo $B | awk '{print $6}'`
192 B_p=`echo $B | awk '{print $9}'`
194 BSCANLIBDBI="${LIBDBI:+1}"
196 if test "$BSCANLIBDBI" = "1" ; then
197 BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
205 bin/bacula stop 2>&1 >/dev/null
212 check_for_zombie_jobs()
214 scripts/check_for_zombie_jobs $*
219 if test $# -eq 1; then
227 mv bin/bacula-dir.conf bin/1
228 echo "s%${oldname}%${newname}%g" >tmp/1
229 sed -f tmp/1 bin/1 >bin/bacula-dir.conf
230 # echo "Job ${oldname} changed to ${newname}"
235 grep "^ Termination: *Backup OK" tmp/log1.out 2>&1 >/dev/null
237 grep "^ Termination: .*Backup Error" tmp/log1.out 2>&1 >/dev/null
238 if test $? -eq 0; then
241 grep "^ Termination: *Restore OK" tmp/log2.out 2>&1 >/dev/null
243 grep "^ Termination: .*Restore Error" tmp/log2.out 2>&1 >/dev/null
244 if test $? -eq 0; then
247 grep "^ Termination: *Restore OK -- warning file count mismatch" tmp/log2.out 2>&1 >/dev/null
248 if test $? -eq 0; then
251 grep "^ Termination: .*Verify Differences" tmp/log2.out 2>&1 >/dev/null
252 if test $? -eq 0; then
255 grep "Encoding error for database" tmp/log1.out > /dev/null
256 if test $? -eq 0; then
257 print_debug "Found database encoding error"
264 if test "$debug" -eq 1 ; then
265 diff -ur build tmp/bacula-restores${cwd}/build
267 diff -ur build tmp/bacula-restores${cwd}/build 2>&1 >/dev/null
272 check_restore_tmp_build_diff()
274 if test "$debug" -eq 1 ; then
275 diff -ur tmp/build tmp/bacula-restores${cwd}/tmp/build
277 diff -ur tmp/build tmp/bacula-restores${cwd}/tmp/build 2>&1 >/dev/null
284 if [ $zstat != 0 ] ; then
286 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
287 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat"
288 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
289 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
293 if [ $dstat != 0 -o $bstat != 0 -o $rstat != 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
300 if [ $bstat != 0 -o $rstat != 0 ] ; then
301 echo " !!!!! Bad termination status !!!!! "
302 echo " !!!!! Bad termination status !!!!! " >>test.out
304 echo " !!!!! Restored files differ !!!!! "
305 echo " !!!!! Restored files differ !!!!! " >>test.out
307 echo " Status: backup=$bstat restore=$rstat diff=$dstat"
308 echo " Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
312 echo " ===== $TestName OK `date +%R:%S` ===== "
313 echo " ===== $TestName OK `date +%R:%S` ===== " >>test.out
314 if test "$debug" -eq 0 ; then
322 scripts/copy-tape-confs
328 scripts/copy-test-confs
334 if test "x${REGRESS_WAIT}" = "x1"; then
335 echo "Start Bacula under debugger and enter anything when ready ..."
344 if test -n "$DRIVE" -a -n "$SLOT"; then
345 if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
354 if test a$USE_VTAPE = a; then
364 if test a$USE_VTAPE = a; then
371 # Get a tape from slot1
372 slot=`$scripts/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
375 $scripts/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
382 rewind_drive ${TAPE_DRIVE}
383 $scripts/$MTX ${AUTOCHANGER} unload $slot ${TAPE_DRIVE} $DRIVE1
384 $scripts/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
391 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
392 # if 2, load 1; if 0 load 1
396 rewind_drive ${TAPE_DRIVE}
399 $scripts/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
403 $scripts/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
404 $scripts/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
408 $scripts/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
409 $scripts/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
413 echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
419 # Save current directory
421 if test "x${REGRESS_DEBUG}" = "x1"; then
427 # Source the configuration variables
430 db_name=${db_name:-"regress"}
431 db_user=${db_user:-"regress"}
432 db_password=${db_password:-""}
433 working=${working:-"$cwd/working"}
434 bin=${bin:-"$cwd/bin"}
435 scripts=${scripts:-"$bin"}
443 if [ x$USE_VTAPE = xyes ]; then
444 mkdir -p $working/ach
447 TAPE_DRIVE=$working/ach/drive1
448 TAPE_DRIVE1=$working/ach/drive1
449 AUTOCHANGER=$working/ach/config
450 AUTOCHANGER_SCRIPT=disk-changer
453 cat > $AUTOCHANGER <<EOF
459 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
460 LD_LIBRARY_PATH=$bin:$LD_LIBRARY_PATH
461 export LD_LIBRARY_PATH