#!/bin/sh
#
# Run a simple backup  using the compressed option
#   then backup four times, each with incremental then finally restore.
#   It should require at least 4 different bsrs.
#
TestName="four-jobs-test"
JobName=SpanVol
. scripts/functions

scripts/cleanup
scripts/copy-test-confs

# 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/flat-c.tgz

# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
echo "${BackupDirectory}" >${tmp}/file-list



change_jobname CompressedTest $JobName
start_test

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out ${cwd}/tmp/log1.out
label storage=File volume=TestVolume001
run job=$JobName yes
wait
messages
quit
END_OF_DATA

run_bareos
check_for_zombie_jobs storage=File
# make some files for the incremental to pick up
touch ${BackupDirectory}/*.c
echo "test" > ${BackupDirectory}/test1.txt

#
# run a second job
#
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out  ${cwd}/tmp/log1.out
run job=$JobName yes
wait
messages
quit
END_OF_DATA

run_bconsole
check_for_zombie_jobs storage=File

touch ${BackupDirectory}/*.c
echo "test" > ${BackupDirectory}/test2.txt
#
# run a third job
#
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
run job=$JobName yes
wait
messages
quit
END_OF_DATA

run_bconsole
check_for_zombie_jobs storage=File

# make some files for the incremental to pick up
touch ${BackupDirectory}/*.c
echo "test" > ${BackupDirectory}/test3.txt
#
# run a fourth job
#
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
run job=$JobName yes
wait
messages
quit
END_OF_DATA

run_bconsole
check_for_zombie_jobs storage=File

#
# now do several restores to ensure we cleanup between jobs
#
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
restore where=${cwd}/tmp/bareos-restores select all storage=File done
yes
wait
restore where=${cwd}/tmp/bareos-restores select all storage=File done
yes
wait
@$out ${cwd}/tmp/log2.out
restore where=${cwd}/tmp/bareos-restores select storage=File
unmark *
mark *
done
yes
wait
messages
quit
END_OF_DATA

run_bconsole
check_for_zombie_jobs storage=File
stop_bareos

check_two_logs
check_restore_diff
end_test
