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 2>&1 >/dev/null
154 cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf 2>&1 >/dev/null
161 if test "$debug" -eq 1 ; then
162 cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
164 cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf 2>&1 >/dev/null
170 if test "$debug" -eq 1 ; then
171 cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 | tee tmp/log1.out
173 cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 2>&1 >tmp/log1.out
179 if test "$debug" -eq 1 ; then
180 bin/bscan $* | tee tmp/log.out
182 bin/bscan $* 2>&1 >/dev/null
188 B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
189 B_D=`echo $B | awk '{print $3}'`
190 B_t=`echo $B | awk '{print $6}'`
191 B_p=`echo $B | awk '{print $9}'`
193 BSCANLIBDBI="${LIBDBI:+1}"
195 if test "$BSCANLIBDBI" = "1" ; then
196 BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
204 bin/bacula stop 2>&1 >/dev/null
207 check_for_zombie_jobs()
209 scripts/check_for_zombie_jobs $*
214 if test $# -eq 1; then
222 mv bin/bacula-dir.conf bin/1
223 echo "s%${oldname}%${newname}%g" >tmp/1
224 sed -f tmp/1 bin/1 >bin/bacula-dir.conf
225 # echo "Job ${oldname} changed to ${newname}"
230 grep "^ Termination: *Backup OK" tmp/log1.out 2>&1 >/dev/null
232 grep "^ Termination: .*Backup Error" tmp/log1.out 2>&1 >/dev/null
233 if test $? -eq 0; then
236 grep "^ Termination: *Restore OK" tmp/log2.out 2>&1 >/dev/null
238 grep "^ Termination: .*Restore Error" tmp/log2.out 2>&1 >/dev/null
239 if test $? -eq 0; then
242 grep "^ Termination: *Restore OK -- warning file count mismatch" tmp/log2.out 2>&1 >/dev/null
243 if test $? -eq 0; then
246 grep "^ Termination: .*Verify Differences" tmp/log2.out 2>&1 >/dev/null
247 if test $? -eq 0; then
254 if test "$debug" -eq 1 ; then
255 diff -ur build tmp/bacula-restores${cwd}/build
257 diff -ur build tmp/bacula-restores${cwd}/build 2>&1 >/dev/null
262 check_restore_tmp_build_diff()
264 if test "$debug" -eq 1 ; then
265 diff -ur tmp/build tmp/bacula-restores${cwd}/tmp/build
267 diff -ur tmp/build tmp/bacula-restores${cwd}/tmp/build 2>&1 >/dev/null
274 if [ $zstat != 0 ] ; then
276 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
277 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
278 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
282 if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
285 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
286 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
287 if [ $bstat != 0 -o $rstat != 0 ] ; then
288 echo " !!!!! Bad termination status !!!!! "
289 echo " !!!!! Bad termination status !!!!! " >>test.out
291 echo " !!!!! Restored files differ !!!!! "
292 echo " !!!!! Restored files differ !!!!! " >>test.out
294 echo " Status: backup=$bstat restore=$rstat diff=$dstat"
295 echo " Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
299 echo " ===== $TestName OK `date +%R:%S` ===== "
300 echo " ===== $TestName OK `date +%R:%S` ===== " >>test.out
301 if test "$debug" -eq 0 ; then
309 scripts/copy-tape-confs
315 scripts/copy-test-confs
321 if test "x${REGRESS_WAIT}" = "x1"; then
322 echo "Start Bacula under debugger and enter anything when ready ..."
331 if test -n "$DRIVE" -a -n "$SLOT"; then
332 if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
341 if test a$USE_VTAPE = a; then
351 if test a$USE_VTAPE = a; then
358 # Get a tape from slot1
359 slot=`bin/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
362 bin/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
369 rewind_drive ${TAPE_DRIVE}
370 bin/$MTX ${AUTOCHANGER} unload $slot ${TAPE_DRIVE} $DRIVE1
371 bin/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
378 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
379 # if 2, load 1; if 0 load 1
383 rewind_drive ${TAPE_DRIVE}
386 bin/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
390 bin/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
391 bin/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
395 bin/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
396 bin/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
400 echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
407 # Save current directory
409 if test "x${REGRESS_DEBUG}" = "x1"; then
415 # Source the configuration variables
418 db_name=${db_name:-"regress"}
419 db_user=${db_user:-"regress"}
420 db_password=${db_password:-""}
424 if [ x$USE_VTAPE = xyes ]; then
425 mkdir -p $cwd/working/ach
428 TAPE_DRIVE=$cwd/working/ach/drive1
429 TAPE_DRIVE1=$cwd/working/ach/drive1
430 AUTOCHANGER=$cwd/working/ach/config
431 AUTOCHANGER_SCRIPT=disk-changer
434 cat > $AUTOCHANGER <<EOF
440 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}
441 LD_LIBRARY_PATH=$cwd/bin
442 export LD_LIBRARY_PATH