#!/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 then create some           
#   new files, do an Incremental onto a different medium 
#   and then restore everything.
#
# This script uses the virtual disk autochanger
#
TestName="incremental-2media"
JobName=Inc2media
. scripts/functions


scripts/cleanup
scripts/copy-2disk-confs
scripts/prepare-disk-changer
echo "${cwd}/build" >${cwd}/tmp/file-list

change_jobname $JobName
start_test

# Write out bconsole commands
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
label storage=tape volume=TestVolume001 slot=1 Pool=Default drive=0
label storage=File volume=TestVolume002 Pool=Default
run job=$JobName yes
wait
messages
quit
END_OF_DATA

run_bacula

# 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

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
@# Force Incremental on the second Volume
update volume=TestVolume001 VolStatus=Used
setdebug level=51 storage=File
run level=Incremental job=$JobName storage=File yes
wait
messages
@# 
@# now do a restore
@#
@$out ${cwd}/tmp/log2.out
setdebug level=151 storage=tape
restore where=${cwd}/tmp/bacula-restores select all done 
yes
wait
restore where=${cwd}/tmp/bacula-restores select all done 
yes
wait
status storage=tape
messages
quit
END_OF_DATA

run_bconsole

check_for_zombie_jobs storage=File
stop_bacula

check_two_logs
check_restore_diff

end_test
