#!/bin/sh
#
# Copyright (C) 2000-2022 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#

#
# Run a simple backup of the Bacula build directory without
# md5 signature then restore it.
#
TestName="no-chksum-test"
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
echo "s%  signature =%# signature =%g" >> $outf
cp $scripts/bacula-dir.conf $tmp/1
sed -f $outf $tmp/1 >$scripts/bacula-dir.conf

change_jobname BackupClient1 $JobName
start_test

cat <<END_OF_DATA >$tmp/bconcmds
@output /dev/null
messages
@$out $tmp/log1.out
label volume=TestVolume001 storage=File pool=File
END_OF_DATA

run_bacula

cat <<END_OF_DATA >$tmp/bconcmds
@$out $tmp/log1.out
run job=$JobName yes
wait
messages
quit
END_OF_DATA

run_bconsole

#
# Now do a second backup after making a few changes
#
touch ${cwd}/build/po/fr.po
#

run_bconsole

dd if=/dev/zero of=$cwd/build/bigfile count=500000 > /dev/null

run_bconsole

rm -f $cwd/build/bigfile 

cat <<END_OF_DATA >$tmp/bconcmds
@output /dev/null
messages
@$out $tmp/log1.out
@# don't restore the bigfile, and try to see if it reads the whole volume
list files jobid=3
delete jobid=3
@# 
@# now do a restore
@#
@$out $tmp/log2.out  
setdebug level=150 trace=1 storage=File
restore where=$tmp/bacula-restores select all done
yes
wait
messages
quit
END_OF_DATA

run_bconsole

check_for_zombie_jobs storage=File
stop_bacula

check_two_logs
check_restore_diff
end_test
