#!/bin/bash
set -e
set -o pipefail
set -u
#
# Run a simple backup, set it to archive and do a copy.
#
TestName="$(basename "$(pwd)")"
export TestName

JobName=backup-bareos-fd

#shellcheck source=../../environment.in
. ./environment

#shellcheck source=../../scripts/functions
. "${rscripts}"/functions
"${rscripts}"/cleanup
"${rscripts}"/setup

# Fill ${BackupDirectory} with data.
setup_data

start_test

cat <<END_OF_DATA >"$tmp/bconcmds"
@$out ${NULL_DEV}
messages
@$out $tmp/log1.out
setdebug level=100 storage=File
label volume=TestVolume001 storage=File pool=Full
run job=$JobName yes
status director
status client
status storage=File
wait
messages
@#
@# do the 1st copy
@#
@$out $tmp/log2.out
wait
run job=copy-job1 yes
wait
messages
@#
@# do the 2nd copy
@#
@$out $tmp/log3.out
wait
run job=copy-job2 yes
wait
messages
quit
END_OF_DATA

run_bareos "$@"
check_for_zombie_jobs storage=File

check_sd_files_written $tmp/log2.out
check_sd_files_written $tmp/log3.out

end_test
