#!/bin/sh
#
# Run a simple backup, then create some
#   new files, do an Incremental onto a different medium
#   and then restore everything.
#
# This script uses the two different tape drives.
#
TestName="incremental-2media-tape"
JobName=Inc2mediaTape
. scripts/functions

require_tape_drive
require_second_drive

scripts/cleanup

# Get conf files
/bin/cp -f scripts/bareos-dir-2d.conf bin/bareos-dir.conf
/bin/cp -f scripts/bareos-sd-2d.conf bin/bareos-sd.conf
/bin/cp -f scripts/bareos-fd-2d.conf bin/bareos-fd.conf
/bin/cp -f scripts/bconsole-2d.conf bin/bconsole.conf

${rscripts}/set_tape_options

mt -f /dev/nst0 rewind
mt -f /dev/nst0 weof
mt -f /dev/nst1 rewind
mt -f /dev/nst1 weof

change_jobname $JobName

# 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


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=$SLOT1 Pool=Default drive=$DRIVE1
label storage=DLT80 volume=TestVolume002 Pool=Default
run job=$JobName yes
wait
messages
quit
END_OF_DATA

run_bareos

echo "Backup 1 done"
# make some files for the incremental to pick up
echo "test" > ${BackupDirectory}/test1.txt
echo "test" > ${BackupDirectory}/test2.txt

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=DLT80
run level=Incremental job=$JobName storage=DLT80 yes
wait
list volumes
messages
@#
@# now do a restore
@#
@$out ${cwd}/tmp/log2.out
setdebug level=51 storage=tape
restore where=${cwd}/tmp/bareos-restores select all done
yes
wait
messages
quit
END_OF_DATA

run_bconsole

check_for_zombie_jobs storage=DLT80
stop_bareos

check_two_logs
check_restore_diff

end_test
