#!/bin/sh
#
# Run a backup but force it to have
#   a comm error, and check that it restarts correctly.
#
TestName="restart-job-test"
JobName=RestartJob
. 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/small.tgz

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



change_jobname NightlySave $JobName
start_test

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
setdebug level=0 trace=0 hangup=100 client
@#setdebug level=20 dir
label storage=File volume=TestVolume001
run job=$JobName yes
wait
messages
sql
select * from JobMedia where JobId=1;

quit
END_OF_DATA

run_bareos

scripts/check_for_zombie_jobs storage=File

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@#
@# now do a restore
@#
@$out ${cwd}/tmp/log2.out
restore where=$tmp/bareos-restores storage=File select all done
yes
wait
messages
quit
END_OF_DATA

run_bconsole
scripts/check_for_zombie_jobs storage=File
stop_bareos

check_two_logs
check_restore_diff
end_test
