#!/bin/sh
#
# Run a simple backup  using the compressed option
#   then restore it.
#

TestName="restore-replace-never"
JobName=restore-replace-never
. scripts/functions

scripts/cleanup
scripts/copy-test-confs
mkdir -p ${cwd}/tmp/dir/dir1
touch ${cwd}/tmp/dir/dir1/file1
touch ${cwd}/tmp/dir/dir1/file2
echo ${cwd}/tmp/dir >${cwd}/tmp/file-list

stat ${cwd}/tmp/dir                >${cwd}/tmp/1
stat ${cwd}/tmp/dir/dir1          >>${cwd}/tmp/1
stat ${cwd}/tmp/dir/dir1/file1    >>${cwd}/tmp/1
stat ${cwd}/tmp/dir/dir1/file2    >>${cwd}/tmp/1
# Strip Change: lines
grep -v "Change:" ${cwd}/tmp/1 >${cwd}/tmp/stat-before

change_jobname CompressedTest $JobName
start_test

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
label storage=File volume=TestVolume001
run job=$JobName yes
wait
messages
quit
END_OF_DATA

run_bareos

rm -rf ${cwd}/tmp/dir

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log2.out
restore where=/ storage=File replace=never select all done yes
@#restore where=/ storage=File select all done yes
wait
messages
quit
END_OF_DATA

run_bconsole

stat ${cwd}/tmp/dir                >${cwd}/tmp/1
stat ${cwd}/tmp/dir/dir1          >>${cwd}/tmp/1
stat ${cwd}/tmp/dir/dir1/file1    >>${cwd}/tmp/1
stat ${cwd}/tmp/dir/dir1/file2    >>${cwd}/tmp/1
# Strip Change: lines
grep -v "Change:" ${cwd}/tmp/1 >${cwd}/tmp/stat-after

check_for_zombie_jobs storage=File
stop_bareos

check_two_logs
if test "$debug" -eq 1 ; then
  diff -u ${cwd}/tmp/stat-before ${cwd}/tmp/stat-after
else
  diff -u ${cwd}/tmp/stat-before ${cwd}/tmp/stat-after 2>&1 >/dev/null
fi
if [ $? != 0 ]; then
  dstat=1
fi
end_test
