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

#
# Run a simple backup of the Bacula build directory using the compressed option
#   then restore a few selected files.
#
TestName="restore2-by-file-test"
JobName=restore2byfile
. scripts/functions
copy_test_confs

echo "${cwd}/build" >${cwd}/tmp/file-list
sed s%\^%${cwd}% ${cwd}/scripts/flist | sort | uniq >${cwd}/tmp/restore2-list

change_jobname CompressedTest $JobName
start_test

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

run_bacula
check_for_zombie_jobs storage=File
stop_bacula

check_two_logs
dstat=0
for i in `cat ${cwd}/tmp/restore2-list`; do  
   diff $i ${cwd}/tmp/bacula-restores$i
   if [ $? != 0 ] ; then
      dstat=1
   fi
done
end_test
