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

#
# Run a simple backup of the Bacula build directory using the Sparse option
#   then restore it.
#
TestName="gigaslam-sparse-test"
JobName=SparseTest
. scripts/functions

scripts/cleanup
scripts/copy-test-confs
echo "${cwd}/build" >${cwd}/tmp/file-list
cd ${cwd}/build/src/tools
./gigaslam
if [ $? != 0 ]; then
   echo "Execute of ${cwd}/build/src/tools/gigaslam failed."
   rm -f ${cwd}/build/src/tools/gigaslam.gif
   exit 1
fi
cd ${cwd}

start_test

cat >${cwd}/tmp/bconcmds <<END_OF_DATA
@output /dev/null
messages
@$out ${cwd}/tmp/log1.out
label storage=File volume=TestVolume001
run job=$JobName yes
wait
messages
list volumes
@# 
@# now do a restore
@#
@$out ${cwd}/tmp/log2.out
restore where=${cwd}/tmp/bacula-restores select storage=File
unmark *
mark *
done
yes
wait
messages
quit
END_OF_DATA

run_bacula
check_for_zombie_jobs storage=File 
stop_bacula

size=`du ${cwd}/tmp/bacula-restores/${cwd}/build/src/tools/gigaslam.gif | cut -f 1`
if [ $size -gt 120 ]; then
   echo "========== restored sparse file gigaslam.gif too big ========="
   echo "      size is ${size}K it should be 120K"
fi

check_two_logs
check_restore_diff
end_test
rm -f ${cwd}/build/src/tools/gigaslam.gif
rm -f ${cwd}/build/gigaslam.gif
