#!/bin/sh
#
#  Run a job with small Maximum Volume Bytes.  It should
#    create a lot of volumes. The test stresses auto-creation of
#    Volumes and restores from a lot of Volumes. Note, it creates
#    writes and then reads something like 110 Volumes (will vary
#    depending on the size of the Bareos source).
#
TestName="maxbytes-test"
JobName=maxbytes
. scripts/functions

scripts/cleanup
scripts/copy-test-confs

cp -f ${cwd}/bin/bareos-dir.conf ${cwd}/tmp/1
sed "s%# Maximum Volume Bytes%  Maximum Volume Bytes%" ${cwd}/tmp/1 >${cwd}/bin/bareos-dir.conf
cp -f ${cwd}/bin/bareos-dir.conf ${cwd}/tmp/1
sed "s%# Simple Label Format%  Label Format%" ${cwd}/tmp/1 >${cwd}/bin/bareos-dir.conf

change_jobname NightlySave $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

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out   ${cwd}/tmp/log1.out
@#setdebug level=100 Storage=File1
run job=$JobName level=Full Storage=File1 yes
wait
list volumes
messages
@#
@# now do a restore
@#
@$out   ${cwd}/tmp/log2.out
restore where=${cwd}/tmp/bareos-restores select storage=File1
unmark *
mark *
done
yes
wait
@#reload
@#reload
messages
quit
END_OF_DATA

run_bareos
check_for_zombie_jobs storage=File1
stop_bareos

check_two_logs
check_restore_diff
end_test
