#!/bin/sh
+#
+# Copyright (C) 2000-2015 Kern Sibbald
+# License: BSD 2-Clause; see file LICENSE-FOSS
+#
+
#
# Run a simple backup of the Bacula build directory using the compressed option
# then backup four times, each with incremental then
# do a bscan and restore.
# It should require at least 4 different bsrs.
#
-cwd=`pwd`
-bin/bacula stop 2>&1 >/dev/null
-scripts/copy-tape-confs
-scripts/cleanup-tape
-echo "${cwd}/build" >/tmp/file-list
-cd bin
-./drop_bacula_tables >/dev/null 2>&1
-./make_bacula_tables >/dev/null 2>&1
-./grant_bacula_privileges 2>&1 >/dev/null
-cd ..
-cp ${cwd}/bin/bacula-sd.conf ${cwd}/tmp/1
-sed "s%# Maximum File Size% Maximum File Size%" ${cwd}/tmp/1 >${cwd}/bin/bacula-sd.conf
-
-echo " "
-echo " "
-echo " === Starting bscan-tape ==="
-echo " === Starting bscan-tape ===" >>working/log
-echo " "
-
-bin/bacula start 2>&1 >/dev/null
-bin/bconsole -c bin/bconsole.conf <<END_OF_DATA 2>&1 >/dev/null
-@output /dev/null
-estimate job=NightlySave listing
-estimate job=NightlySave listing
-estimate job=NightlySave listing
+TestName="bscan-tape"
+JobName=bscantape
+. scripts/functions
+
+require_tape_drive
+
+copy_tape_confs
+
+echo "${cwd}/build" >tmp/file-list
+
+cp ${cwd}/bin/bacula-sd.conf tmp/1
+sed "s%# Maximum File Size% Maximum File Size%" tmp/1 >${cwd}/bin/bacula-sd.conf
+
+change_jobname NightlySave $JobName
+start_test
+
+cat <<END_OF_DATA >tmp/bconcmds
+@$out /dev/null
+estimate job=$JobName listing
+estimate job=$JobName listing
messages
-@output tmp/log1.out
-label storage=DDS-4 volume=TestVolume001 slot=0
-run job=NightlySave yes
-wait
-run job=NightlySave level=Full yes
+@$out tmp/log1.out
+setdebug level=2 storage=tape
+label storage=tape volume=TestVolume001 slot=0 pool=Default
+run job=$JobName level=Full yes
wait
-run job=NightlySave level=Full yes
+run job=$JobName level=Full yes
wait
messages
quit
END_OF_DATA
-scripts/check_for_zombie_jobs storage=DDS-4
-echo "Backup 1 done"
+
+run_bacula
+check_for_zombie_jobs storage=tape
+
# make some files for the incremental to pick up
touch ${cwd}/build/src/dird/*.c ${cwd}/build/src/dird/*.o
touch ${cwd}/build/src/lib/*.c ${cwd}/build/src/lib/*.o
#
# run a second job
#
-bin/bconsole -c bin/bconsole.conf <<END_OF_DATA 2>&1 >/dev/null
-@output /dev/null
+cat <<END_OF_DATA >tmp/bconcmds
+@$out /dev/null
messages
-@output tmp/log1.out
-run job=NightlySave level=Incremental yes
+@$out tmp/log1.out
+run job=$JobName level=Incremental yes
wait
messages
quit
END_OF_DATA
-scripts/check_for_zombie_jobs storage=DDS-4
-echo "Backup 2 done"
+
+run_bconsole
+scripts/check_for_zombie_jobs storage=tape
+
touch ${cwd}/build/src/dird/*.c
touch ${cwd}/build/src/lib/*.c ${cwd}/build/src/lib/*.o
#
# run a third job
#
-bin/bconsole -c bin/bconsole.conf <<END_OF_DATA 2>&1 >/dev/null
-@output /dev/null
-messages
-@output tmp/log1.out
-run job=NightlySave level=Incremental yes
-wait
-messages
-quit
-END_OF_DATA
-scripts/check_for_zombie_jobs storage=DDS-4
-echo "Backup 3 done"
+
+run_bconsole
+scripts/check_for_zombie_jobs storage=tape
+
# make some files for the incremental to pick up
touch ${cwd}/build/src/lib/*.c ${cwd}/build/src/lib/*.o
#echo "abc" > ${cwd}/build/src/lib/dummy
#
# run a fourth job
#
-bin/bconsole -c bin/bconsole.conf <<END_OF_DATA 2>&1 >/dev/null
-@output /dev/null
-messages
-@output tmp/log1.out
-run job=NightlySave level=Incremental yes
-wait
-messages
-quit
-END_OF_DATA
-scripts/check_for_zombie_jobs storage=DDS-4
-echo "Backup 4 done"
+
+run_bconsole
+scripts/check_for_zombie_jobs storage=tape
+
+stop_bacula
+
#
# now drop and recreate the database
#
./grant_bacula_privileges 2>&1 >/dev/null
cd ..
-bin/bacula stop 2>&1 >/dev/null
echo "volume=TestVolume001" >tmp/bscan.bsr
-# bin/bscan -w working -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf ${cwd}/tmp 2>&1 >/dev/null
-bin/bscan -w working -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf /dev/nst0
-bin/bacula start 2>&1 >/dev/null
-bin/bconsole -c bin/bconsole.conf <<END_OF_DATA
-@output /dev/null
+
+bscan_libdbi
+
+# If the database has a password pass it to bscan
+if test "x${db_password}" = "x"; then
+ PASSWD=
+else
+ PASSWD="-P ${db_password}"
+fi
+
+if test "$debug" -eq 1 ; then
+ $bin/bscan -w working $BSCANLIBDBI -u ${db_user} -n ${db_name} $PASSWD -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf tape
+else
+ $bin/bscan -w working $BSCANLIBDBI -u ${db_user} -n ${db_name} $PASSWD -m -s -v -b tmp/bscan.bsr -c bin/bacula-sd.conf tape >/dev/null 2>&1
+fi
+
+echo $BSCANLIBDBI
+
+cat <<END_OF_DATA >tmp/bconcmds
+@$out /dev/null
messages
-@output tmp/log2.out
+@$out tmp/log2.out
@#
@# now do a restore
@#
-restore where=${cwd}/tmp/bacula-restores select all storage=DDS-4 done
+restore where=${cwd}/tmp/bacula-restores select all storage=tape done
yes
wait
messages
-@output
quit
END_OF_DATA
-scripts/check_for_zombie_jobs storage=DDS-4
+
+run_bacula
+check_for_zombie_jobs storage=tape
+stop_bacula
rm -f ${cwd}/build/src/lib/dummy
-bin/bacula stop 2>&1 >/dev/null
-grep "^Termination: *Backup OK" tmp/log1.out 2>&1 >/dev/null
-bstat=$?
-grep "^Termination: *Restore OK" tmp/log2.out 2>&1 >/dev/null
-rstat=$?
-diff -r build tmp/bacula-restores${cwd}/build 2>&1 >/dev/null
-if [ $? != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
- echo " "
- echo " "
- echo " !!!!! bscan-tape Bacula source failed!!! !!!!! "
- echo " !!!!! bscan-tape failed!!! !!!!! " >>test.out
- echo " "
-else
- echo " ===== bscan-tape Bacula source OK ===== "
- echo " ===== bscan-tape OK ===== " >>test.out
-# scripts/cleanup
-fi
+
+check_two_logs
+check_restore_diff
+end_test