#!/bin/sh
#
# Attempt to backup and restore a file with the bpipe plugin
#
TestName="debug-test"
JobName=pluginTest
. scripts/functions

scripts/cleanup
scripts/copy-plugin-confs
rm -f ${cwd}/working/*trace*

# Directory to backup.
# This directory will be created by setup_data().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data data/small.tgz

# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
echo "${BackupDirectory}" >${tmp}/file-list


start_test

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
label storage=File1 volume=TestVolume001
update volume=TestVolume001 MaxVolBytes=1000
run job=$JobName storage=File1 yes
@sleep 5
messages
quit
END_OF_DATA

run_bareos

killall -SEGV bareos-dir bareos-sd bareos-fd

test -f working/*dir*bactrace
dstat=$?
test -f working/*fd*bactrace
dstat=`expr $dstat + $?`
test -f working/*sd*bactrace
dstat=`expr $dstat + $?`
test -f working/*dir*traceback
dstat=`expr $dstat + $?`
test -f working/*fd*traceback
dstat=`expr $dstat + $?`
test -f working/*sd*traceback
dstat=`expr $dstat + $?`

grep $JobName working/*dir*bactrace > /dev/null 2>&1
dstat=`expr $dstat + $?`
grep bpipe-fd.so working/*fd*bactrace > /dev/null 2>&1
dstat=`expr $dstat + $?`
grep $JobName working/*fd*bactrace > /dev/null 2>&1
dstat=`expr $dstat + $?`

bstat=0
rstat=0

stop_bareos

end_test
