#!/usr/bin/env bash
#
# Copyright (C) 2000-2022 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# Run a simple backup of the Bacula build directory
# then restore it.  (no incremenal just a backup and restore)
#
# XPARAM CUSTOM=<BUILD_YOUR_OWN_CUSTOM>
# the size of data to handle, to make the test short or long

TestName="simple-test"
JobName=backup
. scripts/functions

scripts/cleanup
scripts/copy-test-confs
echo "${cwd}/build" >${cwd}/tmp/file-list

if [ -n "$CUSTOM" ] ; then
   dd if=/dev/urandom of=$tmp/random-data bs=1M count=10
   echo "$tmp/random-data" >${cwd}/tmp/file-list
fi

start_test

cat <<END_OF_DATA >$tmp/bconcmds
@output /dev/null
messages
@$out $tmp/log1.out
setdebug level=4 storage=File
setdebug level=1 client
label storage=File volume=TestVolume001
run job=Simple yes
wait
messages
@# 
@# now do a restore
@#
@$out $tmp/log2.out  
setdebug level=4 storage=File
restore where=$tmp/bacula-restores select all done
yes
wait
messages
quit
END_OF_DATA

run_bacula
check_for_zombie_jobs storage=File
stop_bacula
check_two_logs
[ -n "$CUSTOM" ] || check_restore_diff
end_test
