#!/bin/sh
#
# Run a simple backup
#   then restore it.
#
TestName="$(basename "$(pwd)")"
JobName=backup
. scripts/functions

scripts/cleanup
scripts/copy-confs

#
# Zap out any schedule in default conf file so that
#  it doesn't start during our test
#
outf="$tmp/sed_tmp"
echo "s%  Schedule =%# Schedule =%g" >${outf}
cp $rscripts/bareos-dir.conf $tmp/1
sed -f ${outf} $tmp/1 >$conf/bareos-dir.conf

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

start_test

cat <<END_OF_DATA >$tmp/bconcmds
@$out /dev/null
messages
@$out $tmp/log1.out
setdebug level=100 storage=File
label volume=TestVolume001 storage=File pool=Full
run job=$JobName yes
status storage=File
status storage=File
status storage=File
status storage=File
status storage=File
status storage=File
@sleep 1
status storage=File
status storage=File
status storage=File
status storage=File
status storage=File
@sleep 1
status storage=File
status storage=File
status storage=File
status storage=File
status storage=File
wait
messages
@#
@# now do a restore
@#
@$out $tmp/log2.out
restore where=$tmp/bareos-restores select all done
yes
wait
messages
quit
END_OF_DATA

run_bareos
check_for_zombie_jobs storage=File
stop_bareos

cat <<END_OF_DATA >$tmp/bconcmds
@$out /dev/null
messages
@$out $tmp/log1.out
@#setdebug level=100 storage=File
run job=$JobName yes
wait
messages
@#
@# now do a restore
@#
@$out $tmp/log2.out
restore where=$tmp/bareos-restores select all done
yes
wait
messages
quit
END_OF_DATA

#
# Now do a second backup after making a few changes
#
echo "test test" > ${BackupDirectory}/xxx

run_bareos
check_for_zombie_jobs storage=File
stop_bareos

check_two_logs
check_restore_diff ${BackupDirectory}
end_test
