tests/backup-bacula-tape
 tests/small-file-size-tape
 tests/two-volume-tape
+tests/restore-by-file-tape
 echo " "
 echo " "
 echo "Test results"
 
 tests/span-vol-test
 tests/restore-by-file-test
 tests/restore2-by-file-test
+tests/four-jobs-test
 echo " "
 echo " "
 echo "Test results"
 
 rm -rf tmp/restored tmp/largefile tmp/bscan.bsr tmp/log*.out
 rm -rf /tmp/sed_tmp /tmp/file-list
 rm -rf tmp/build tmp/restore-list tmp/restore2-list
+rm -rf working/log
 
--- /dev/null
+#!/bin/sh
+#
+# Run a simple backup of the Bacula build directory using the compressed option
+#   then backup four times, each with incremental then finally restore.
+#   It should require at least 4 different bsrs.
+#
+cwd=`pwd`
+scripts/copy-test-confs
+scripts/cleanup
+echo "${cwd}/build" >/tmp/file-list
+bin/bacula stop 2>&1 >/dev/null
+bin/drop_sqlite_tables
+bin/make_sqlite_tables
+
+echo " "
+echo " "
+echo " === Starting four-jobs-test  ==="
+echo " === Starting four-jobs-test  ===" >>working/log
+echo " "
+
+bin/bacula start 2>&1 >/dev/null
+bin/console -c bin/console.conf <<END_OF_DATA
+@output /dev/null
+estimate job=CompressedTest listing
+estimate job=CompressedTest listing
+estimate job=CompressedTest listing
+messages
+@output tmp/log1.out
+label storage=File volume=TestVolume001
+run job=CompressedTest yes
+wait
+messages
+quit
+END_OF_DATA
+echo "Backup 1 done"
+# 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/console -c bin/console.conf <<END_OF_DATA
+@output /dev/null
+messages
+@output tmp/log1.out
+run job=CompressedTest
+yes
+wait
+messages
+quit
+END_OF_DATA
+echo "Backup 2 done"
+touch ${cwd}/build/src/dird/*.c
+touch ${cwd}/build/src/lib/*.c ${cwd}/build/src/lib/*.o
+#
+# run a third job
+#
+bin/console -c bin/console.conf <<END_OF_DATA
+@output /dev/null
+messages
+@output tmp/log1.out
+label storage=File volume=TestVolume001
+run job=CompressedTest yes
+wait
+messages
+quit
+END_OF_DATA
+echo "Backup 3 done"
+# make some files for the incremental to pick up
+touch ${cwd}/build/src/lib/*.c ${cwd}/build/src/lib/*.o
+#
+# run a fourth job
+#
+bin/console -c bin/console.conf <<END_OF_DATA
+@output /dev/null
+messages
+@output tmp/log1.out
+label storage=File volume=TestVolume001
+run job=CompressedTest yes
+wait
+messages
+quit
+END_OF_DATA
+echo "Backup 4 done"
+# 
+# now do several restores to ensure we cleanup between jobs
+#
+bin/console -c bin/console.conf <<END_OF_DATA
+@output /dev/null
+restore where=${cwd}/tmp/bacula-restores current all
+yes
+wait
+restore where=${cwd}/tmp/bacula-restores current all
+yes
+wait
+@output tmp/log2.out
+restore where=${cwd}/tmp/bacula-restores current all
+yes
+wait
+messages
+@output
+quit
+END_OF_DATA
+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 "  !!!!! four-jobs-test Bacula source failed!!! !!!!! "
+   echo "  !!!!! four-jobs-test failed!!! !!!!! " >>test.out
+   echo " "
+else
+   echo "  ===== four-jobs-test Bacula source OK ===== "
+   echo "  ===== four-jobs-test OK ===== " >>test.out
+   scripts/cleanup
+fi
 
--- /dev/null
+#!/bin/sh
+#
+# Run a simple backup of the Bacula build directory 
+#   to a tape where the maximum tape file size is set to 1M
+#   then restore a few files from it.
+#
+cwd=`pwd`
+bin/bacula stop  2>&1 >/dev/null
+scripts/copy-tape-confs
+scripts/cleanup-tape
+echo "${cwd}/build" >/tmp/file-list
+sed s%\^%${cwd}% ${cwd}/scripts/flist >${cwd}/tmp/restore2-list
+bin/drop_sqlite_tables
+bin/make_sqlite_tables
+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 restore-by-file-tape test ==="
+echo " === Starting restore-by-file-tape test ===" >>working/log
+echo " "
+
+bin/bacula start 2>&1 >/dev/null
+bin/console -c bin/console.conf <<END_OF_DATA
+@output /dev/null
+messages
+@output tmp/log1.out
+label storage=DDS-4 volume=TestVolume001 slot=0
+run job=NightlySave level=Full yes
+wait
+messages
+@# 
+@# now do a restore
+@#
+@output tmp/log2.out
+restore where=${cwd}/tmp/bacula-restores
+7
+<${cwd}/tmp/restore2-list
+
+yes
+wait
+messages
+@output
+quit
+END_OF_DATA
+dstat=0
+#
+# We need to stop and start Bacula to
+#  test appending to a previously written tape
+#
+bin/bacula stop  2>&1 >/dev/null
+bin/bacula start 2>&1 >/dev/null
+for i in `cat ${cwd}/tmp/restore2-list`; do
+   diff $i ${cwd}/tmp/bacula-restores$i
+   if [ $? != 0 ] ; then
+      dstat=1
+   fi
+done
+grep "^Termination: *Backup OK" tmp/log1.out 2>&1 >/dev/null
+bstat=$?
+grep "^Termination: *Restore OK" tmp/log2.out 2>&1 >/dev/null
+rstat=$?
+if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
+   echo " "
+   echo " "
+   echo "  !!!!! restore-by-file-tape test Bacula source failed!!! !!!!! "
+   echo "  !!!!! restore-by-file-tape test failed!!! !!!!! " >>test.out
+   echo " "
+   bin/bacula stop 2>&1 >/dev/null
+   exit 1
+fi
+rm -rf ${cwd}/tmp/bacula-restores
+#
+# Now do a second backup and restore
+#
+bin/console -c bin/console.conf <<END_OF_DATA
+@output /dev/null
+messages
+@output tmp/log1.out
+run job=NightlySave level=Full yes
+wait
+messages
+@#
+@# now do a restore
+@#
+@output tmp/log2.out
+restore where=${cwd}/tmp/bacula-restores
+7
+<${cwd}/tmp/restore2-list
+                                                                                        
+yes
+wait
+messages
+@output
+quit
+END_OF_DATA
+bin/bacula stop 2>&1 >/dev/null
+for i in `cat ${cwd}/tmp/restore2-list`; do
+   diff $i ${cwd}/tmp/bacula-restores$i
+   if [ $? != 0 ] ; then
+      dstat=1
+   fi
+done
+grep "^Termination: *Backup OK" tmp/log1.out 2>&1 >/dev/null
+bstat=$?
+grep "^Termination: *Restore OK" tmp/log2.out 2>&1 >/dev/null
+rstat=$?
+if [ $dstat != 0 -o $bstat != 0 -o $rstat != 0 ] ; then
+   echo " "
+   echo " "
+   echo "  !!!!! restore-by-file-tape test Bacula source failed!!! !!!!! "
+   echo "  !!!!! restore-by-file-tape test failed!!! !!!!! " >>test.out
+   echo " "
+else
+   echo "  ===== restore-by-file-tape test Bacula source OK ===== "
+   echo "  ===== restore-by-file-tape test OK ===== " >>test.out
+#  scripts/cleanup
+fi
 
 scripts/copy-test-confs
 scripts/cleanup
 echo "${cwd}/build" >/tmp/file-list
-sed s%\^%${cwd}% ${cwd}/scripts/flist >>${cwd}/tmp/restore2-list
+sed s%\^%${cwd}% ${cwd}/scripts/flist >${cwd}/tmp/restore2-list
 bin/bacula stop  2>&1 >/dev/null
 bin/drop_sqlite_tables
 bin/make_sqlite_tables
 
 echo "${cwd}/build" >/tmp/file-list
 bin/drop_sqlite_tables
 bin/make_sqlite_tables
-out="tmp/sed_tmp"
-echo "s%# Maximum File Size%  Maximum File Size%g" >${out}
 cp ${cwd}/bin/bacula-sd.conf ${cwd}/tmp/1
-sed -f ${out} ${cwd}/tmp/1 >${cwd}/bin/bacula-sd.conf
+sed "s%# Maximum File Size%  Maximum File Size%" ${cwd}/tmp/1 >${cwd}/bin/bacula-sd.conf
 
 echo " "
 echo " "