#!/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
# then restore it.
#
-cwd=`pwd`
-scripts/copy-confs
+TestName="backup-bacula-test"
+JobName=backup
+. scripts/functions
+
scripts/cleanup
-bin/bacula stop 2>&1 >/dev/null
-bin/drop_sqlite_tables
-bin/make_sqlite_tables
-
-echo " "
-echo " "
-echo " === Starting Backup Bacula Test ==="
-echo " === Starting Backup Bacula Test ===" >>working/log
-echo " "
-
-bin/bacula start
-bin/console -c bin/console.conf <<END_OF_DATA
-@output /dev/null
+scripts/copy-confs
+
+#
+# Zap out any schedule in default conf file so that
+# it doesn't start during our test
+#
+outf="$tmp/sed_tmp"
+echo "s% Schedule =%# Schedule =%g" >${outf}
+cp $scripts/bacula-dir.conf $tmp/1
+sed -f ${outf} $tmp/1 >$scripts/bacula-dir.conf
+
+change_jobname BackupClient1 $JobName
+start_test
+
+cat <<END_OF_DATA >$tmp/bconcmds
+@$out /dev/null
+messages
+@$out $tmp/log1.out
+setdebug level=4 storage=File1
+label volume=TestVolume001 storage=File1 pool=File slot=1 drive=0
+show job=$JobName
+show jobs
+run job=$JobName yes
+status storage=File1
+status storage=File1
+status storage=File1
+status storage=File1
+status storage=File1
+status storage=File1
+@sleep 1
+status storage=File1
+status storage=File1
+status storage=File1
+status storage=File1
+status storage=File1
+@sleep 1
+status storage=File1
+status storage=File1
+status storage=File1
+status storage=File1
+status storage=File1
+wait
messages
-@output
-label
-TestVolume001
-run job=NightlySave
+@#
+@# now do a restore
+@#
+@$out $tmp/log2.out
+setdebug level=4 storage=File1
+restore where=$tmp/bacula-restores select all done
yes
wait
messages
+quit
+END_OF_DATA
+
+run_bacula
+check_for_zombie_jobs storage=File1
+stop_bacula
+
+cat <<END_OF_DATA >$tmp/bconcmds
+@$out /dev/null
+messages
+@$out $tmp/log1.out
+setdebug level=4 storage=File1
+run job=$JobName yes
+wait
+messages
@#
@# now do a restore
@#
-restore
-5
-done
+@$out $tmp/log2.out
+#setbandwidth client=$CLIENT limit=100
+setdebug level=4 storage=File1
+restore where=$tmp/bacula-restores select all done
yes
-@sleep 1
wait
-@output /dev/null
messages
quit
END_OF_DATA
-sleep 2
-bin/bacula stop
-diff -r build /tmp/bacula-restores${cwd}/build
-if [ $? != 0 ] ; then
- echo " "
- echo " "
- echo " ===== Backup Bacula Test failed!!! ===== "
- echo " ===== Backup Bacula Test failed!!! ===== " >>test.out
- echo " "
-else
- echo " ===== Backup Bacula Test OK ===== "
- echo " ===== Backup Bacula Test OK ===== " >>test.out
- scripts/cleanup
-fi
+
+#
+# Now do a second backup after making a few changes
+#
+touch ${cwd}/build/src/dird/*.o
+echo "test test" > ${cwd}/build/src/dird/xxx
+#
+
+run_bacula
+check_for_zombie_jobs storage=File1
+stop_bacula
+
+check_two_logs
+check_restore_diff
+end_test