#!/bin/sh
#
# Copyright (C) 2000-2022 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#

#
# Run a simple backup of the Bacula build directory but 
#   create two volumes and set a short Volume duration on
#   the first so that it will be used, recycled.  Then
#   Bug #1032 indicates it will get a changer error when
#   loading the second volume. However, we cannot reproduce
#   this problem.
#
# This test uses an autochanger
#
TestName="vol-duration-changer"
JobName=VolDurationChanger
. scripts/functions

require_tape_drive
require_autochanger

scripts/cleanup
scripts/copy-2tape-confs
scripts/prepare-two-tapes

echo "${cwd}/build" >${cwd}/tmp/file-list

change_jobname NightlySave $JobName
start_test

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
setdebug level=100 storage=tape
label storage=tape volume=TestVolume001 slot=$SLOT1 pool=Default drive=$DRIVE1
label storage=tape volume=TestVolume002 slot=$SLOT2 Pool=Default drive=$DRIVE1
update Volume=TestVolume001 VolUse=30
update Volume=TestVolume002 VolUse=30
run job=$JobName level=Full Storage=tape yes
@sleep 31
run job=$JobName level=Full Storage=tape yes
wait
messages
list volumes
@# 
@# now do a restore
@#
@$out ${cwd}/tmp/log2.out
restore where=${cwd}/tmp/bacula-restores select storage=tape
unmark *
mark *
done
yes
wait
messages
quit
END_OF_DATA

run_bacula
check_for_zombie_jobs storage=tape
stop_bacula

check_two_logs
check_restore_diff
end_test
