#!/bin/bash
set -e
set -o pipefail
set -u
set -x
TestName="$(basename "$(pwd)")"
export TestName

myname=$(basename "$0")

#shellcheck source=../environment.in
. ./environment

#shellcheck source=../scripts/functions
. "${rscripts}"/functions

expected_files=2

start_test

mkdir -p "${tmp}/data"
echo "$0" >"${tmp}/data/$myname"

cat <<END_OF_DATA >"$tmp/bconcmds"
@$out ${NULL_DEV}
messages
@$out "$tmp/$myname.log"
restore client=bareos-fd fileset=DBFileStream where=/ pluginoptions=mssqlvdi:serveraddress=${HOSTNAME}:instance=default:database=DBFileStreamTest:norecovery=yes:replace=yes:recoverafterrestore=yes select all done yes
wait
messages
quit
END_OF_DATA

run_bconsole

#check_for_zombie_jobs storage=File

check_log "$tmp/$myname.log"
# check that the updated content is there
"${SQLCMD}" -Q "SELECT * FROM DBFileStreamTest.production.brands"  | grep Bareos

end_test
