#!/usr/bin/env bash
#
# Copyright (C) 2000-2021 Kern Sibbald
# Copyright (C) 2021-2026 Bacula Systems SA
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# Run a simple backup and copy the volume
#   then restore it.
#
TestName="bcopy-test"
JobName=backup
. scripts/functions

scripts/cleanup
scripts/copy-confs

#
# Zap out any schedule in default conf file so that
#  it doesn't start during our test
#
outf="$tmp/sed_tmp"
echo "s%  Schedule =%# Schedule =%g" >${outf}
cp $scripts/bacula-dir.conf $tmp/1
sed -f ${outf} $tmp/1 >$scripts/bacula-dir.conf

change_jobname BackupClient1 $JobName
start_test

cat <<END_OF_DATA >$tmp/bconcmds
@output /dev/null
messages
@$out $tmp/log1.out
setdebug level=4 storage=File1
label volume=TestVolume001 storage=File1 pool=File slot=1 drive=0
label volume=TestVolume002 storage=File2 pool=File slot=1 drive=0
run job=$JobName level=full yes
run job=$JobName level=full yes
wait
messages
@exec "touch $cwd/build/po/fr.po"
run job=$JobName level=incremental yes
wait
messages
quit
END_OF_DATA

run_bacula

stop_bacula

$bin/bcopy -i TestVolume001 -o TestVolume002 FileChgr1-Dev1 FileChgr2-Dev1

if [ $? -ne 0 ]; then
    print_debug "ERROR: Found error with bcopy"
    estat=1
fi

mkdir -p $tmp/bacula-restores

$bin/bextract -V TestVolume002 FileChgr2-Dev1 $tmp/bacula-restores

check_restore_diff
end_test
