#!/bin/sh
#
# Copyright (C) 2000-2022 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# This should expose bug #7154
#
# This script uses the virtual disk autochanger and two drives
#
TestName="virtualfull-bug-7154"
JobName="backup"
. scripts/functions

scripts/cleanup
scripts/copy-2disk-tape-confs
CLIENT=2drive2disk

echo "${cwd}/build" >${cwd}/tmp/file-list
change_jobname NightlySave $JobName
start_test

# Turn on automatic label
$bperl -e 'add_attribute("$conf/bacula-dir.conf", "LabelFormat", "vol", "Pool")'
$bperl -e 'add_attribute("$conf/bacula-sd.conf", "LabelMedia", "yes", "Device")'


# Enable nextpool for virtualfull and accurate fag
$bperl -e 'add_attribute("$conf/bacula-dir.conf", "Accurate", "yes", "Job")'
$bperl -e 'add_attribute("$conf/bacula-dir.conf", "BackupsToKeep", "5", "Job")'
$bperl -e 'add_attribute("$conf/bacula-dir.conf", "DeleteConsolidatedJobs", "yes", "Job")'
$bperl -e 'add_attribute("$conf/bacula-dir.conf", "Storage", "tape", "Pool")'
$bperl -e 'add_attribute("$conf/bacula-dir.conf", "NextPool", "Default", "Pool", "Default")'

# Write out bconsole commands
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@output /dev/null
messages
@$out ${cwd}/tmp/log1.out
@#setdebug level=100 client=$CLIENT 
run job=$JobName level=Full Pool=Default yes
wait
@exec "touch $cwd/build/po/fr.po"
run job=$JobName level=Incremental Pool=Default yes
wait
@exec "touch $cwd/build/po/fr.po"
run job=$JobName level=Incremental Pool=Default yes
wait
@exec "touch $cwd/build/po/fr.po"
run job=$JobName level=Incremental Pool=Default yes
wait
@exec "touch $cwd/build/po/fr.po"
run job=$JobName level=Incremental Pool=Default yes
wait
@exec "touch $cwd/build/po/fr.po"
run job=$JobName level=Incremental Pool=Default yes
wait
@exec "touch $cwd/build/po/fr.po"
run job=$JobName level=Incremental Pool=Default yes
wait
@exec "touch $cwd/build/po/fr.po"
run job=$JobName level=Incremental Pool=Default yes
wait
@exec "touch $cwd/build/po/fr.po"
run job=$JobName level=Incremental Pool=Default yes
wait
@#setdebug level=150 storage=tape trace=1
run job=$JobName level=VirtualFull yes
wait
messages
list jobs
messages
quit
END_OF_DATA

# exit

run_bacula

check_for_zombie_jobs storage=tape
stop_bacula

touch $tmp/log2.out
check_two_logs

end_test
