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"
117 T=`awk 'BEGIN {t["secs"]=1;t["sec"]=1;t["min"]=60;t["mins"]=60}; /Elapsed time:/ { last=$3*t[$4] } END { print last }' $LOG`
119 if [ "$T" -gt $TIME ]; then
120 print_debug "Expect less than $TIME sec, get $T"
129 if test "$debug" -eq 1 ; then
130 bin/bacula-ctl-sd start
131 bin/bacula-ctl-fd start $1
132 bin/bacula-ctl-dir start
133 cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
136 bin/bacula start 2>&1 >/dev/null
137 cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf 2>&1 >/dev/null
144 if test "$debug" -eq 1 ; then
145 cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf
147 cat tmp/bconcmds | bin/bconsole -c bin/bconsole.conf 2>&1 >/dev/null
153 if test "$debug" -eq 1 ; then
154 cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 | tee tmp/log1.out
156 cat tmp/bconcmds | bin/btape -c bin/bacula-sd.conf DDS-4 2>&1 >tmp/log1.out
162 if test "$debug" -eq 1 ; then
163 bin/bscan $* | tee tmp/log.out
165 bin/bscan $* 2>&1 >/dev/null
171 B=`echo $LIBDBI | sed 's/;//' | sed 's/;//g'`
172 B_D=`echo $B | awk '{print $3}'`
173 B_t=`echo $B | awk '{print $6}'`
174 B_p=`echo $B | awk '{print $9}'`
176 BSCANLIBDBI="${LIBDBI:+1}"
178 if test "$BSCANLIBDBI" = "1" ; then
179 BSCANLIBDBI="-D $B_D -h $B_t -t $B_p"
187 bin/bacula stop 2>&1 >/dev/null
190 check_for_zombie_jobs()
192 scripts/check_for_zombie_jobs $*
197 if test $# -eq 1; then
205 mv bin/bacula-dir.conf bin/1
206 echo "s%${oldname}%${newname}%g" >tmp/1
207 sed -f tmp/1 bin/1 >bin/bacula-dir.conf
208 # echo "Job ${oldname} changed to ${newname}"
213 grep "^ Termination: *Backup OK" tmp/log1.out 2>&1 >/dev/null
215 grep "^ Termination: .*Backup Error" tmp/log1.out 2>&1 >/dev/null
216 if test $? -eq 0; then
219 grep "^ Termination: *Restore OK" tmp/log2.out 2>&1 >/dev/null
221 grep "^ Termination: .*Restore Error" tmp/log2.out 2>&1 >/dev/null
222 if test $? -eq 0; then
225 grep "^ Termination: *Restore OK -- warning file count mismatch" tmp/log2.out 2>&1 >/dev/null
226 if test $? -eq 0; then
229 grep "^ Termination: .*Verify Differences" tmp/log2.out 2>&1 >/dev/null
230 if test $? -eq 0; then
237 if test "$debug" -eq 1 ; then
238 diff -ur build tmp/bacula-restores${cwd}/build
240 diff -ur build tmp/bacula-restores${cwd}/build 2>&1 >/dev/null
245 check_restore_tmp_build_diff()
247 if test "$debug" -eq 1 ; then
248 diff -ur tmp/build tmp/bacula-restores${cwd}/tmp/build
250 diff -ur tmp/build tmp/bacula-restores${cwd}/tmp/build 2>&1 >/dev/null
257 if [ $zstat != 0 ] ; then
259 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
260 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
261 echo " Status: zombie=$zstat backup=$bstat restore=$rstat diff=$dstat" >>test.out
265 if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
268 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! "
269 echo " !!!!! $TestName failed!!! `date +%R:%S` !!!!! " >>test.out
270 if [ $bstat != 0 -o $rstat != 0 ] ; then
271 echo " !!!!! Bad termination status !!!!! "
272 echo " !!!!! Bad termination status !!!!! " >>test.out
274 echo " !!!!! Restored files differ !!!!! "
275 echo " !!!!! Restored files differ !!!!! " >>test.out
277 echo " Status: backup=$bstat restore=$rstat diff=$dstat"
278 echo " Status: backup=$bstat restore=$rstat diff=$dstat" >>test.out
282 echo " ===== $TestName OK `date +%R:%S` ===== "
283 echo " ===== $TestName OK `date +%R:%S` ===== " >>test.out
284 if test "$debug" -eq 0 ; then
292 scripts/copy-tape-confs
298 scripts/copy-test-confs
304 if test "x${REGRESS_WAIT}" = "x1"; then
305 echo "Start Bacula under debugger and enter anything when ready ..."
314 if test -n "$DRIVE" -a -n "$SLOT"; then
315 if test ! -c $DRIVE -a ! -b $DRIVE -a x$USE_VTAPE != x ; then
324 if test a$USE_VTAPE = a; then
334 if test a$USE_VTAPE = a; then
341 # Get a tape from slot1
342 slot=`bin/$MTX ${AUTOCHANGER} loaded 0 ${TAPE_DRIVE} $DRIVE1`
345 bin/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
352 rewind_drive ${TAPE_DRIVE}
353 bin/$MTX ${AUTOCHANGER} unload $slot ${TAPE_DRIVE} $DRIVE1
354 bin/$MTX ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
361 # $1 has currently loaded slot, load the other one i.e. if 1, load 2;
362 # if 2, load 1; if 0 load 1
366 rewind_drive ${TAPE_DRIVE}
369 bin/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
373 bin/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
374 bin/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT2 ${TAPE_DRIVE} $DRIVE1
378 bin/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $1 ${TAPE_DRIVE} $DRIVE1
379 bin/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} load $SLOT1 ${TAPE_DRIVE} $DRIVE1
383 echo "Something went wrong. Expected $SLOT1 or $SLOT2, got $1"
390 # Save current directory
392 if test "x${REGRESS_DEBUG}" = "x1"; then
398 # Source the configuration variables
401 db_name=${db_name:-"regress"}
402 db_user=${db_user:-"regress"}
403 db_password=${db_password:-""}
407 if [ x$USE_VTAPE = xyes ]; then
408 mkdir -p $cwd/working/ach
411 TAPE_DRIVE=$cwd/working/ach/drive1
412 TAPE_DRIVE1=$cwd/working/ach/drive1
413 AUTOCHANGER=$cwd/working/ach/config
414 AUTOCHANGER_SCRIPT=disk-changer
417 cat > $AUTOCHANGER <<EOF
423 AUTOCHANGER_SCRIPT=${AUTOCHANGER_SCRIPT:-mtx-changer}