#!/bin/sh
#
# Run four jobs at the same time, with two Volumes.
#   Set max Vol bytes of first volume
#   to less than total backup to force Bareos to use the second
#   Volume.
#
TestName="2drive-concurrent-test"
JobName=Four-concurrent-jobs
. scripts/functions

scripts/cleanup
scripts/copy-2disk-drive-confs
scripts/prepare-disk-changer
CLIENT=2drive2disk

change_jobname NightlySave $JobName
start_test

# Directory to backup.
# This directory will be created by setup_data().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data data/small.tgz

# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
echo "${BackupDirectory}" >${tmp}/file-list

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out   ${cwd}/tmp/log1.out
label pool=Default storage=tape volume=TestVolume001 slot=1 drive=0
label pool=Default storage=tape volume=TestVolume002 slot=2 drive=1
update Volume=TestVolume001 MaxVolBytes=100000000
@#50000000
@#12
@#ssetdebug level=200 Storage=tape
status storage=tape
list jobs
list volumes
run job=$JobName level=Full Storage=tape
yes
@#reload
list jobs
list volumes
run job=$JobName level=Full Storage=tape
yes
@#reload
list jobs
list volumes
run job=$JobName level=Full Storage=tape
yes
@#reload
list jobs
list volumes
status storage=tape
run job=$JobName level=Full Storage=tape
yes
status storage=tape
@#reload
@#reload
@#reload
@#reload
@sleep 2
status dir
status storage=tape
@#reload
@sleep 5
list jobs
list volumes
messages
@#reload
@#reload
wait
status storage=tape
@#reload
messages
@#
@# now do a restore
@#
@$out   ${cwd}/tmp/log2.out
status storage=tape
restore where=${cwd}/tmp/bareos-restores select storage=tape
unmark *
mark *
done
yes
wait
@#reload
@#reload
messages
@output
quit
END_OF_DATA

run_bareos
check_for_zombie_jobs storage=tape
stop_bareos

check_two_logs
check_restore_diff
end_test
