#!/bin/bash
set -e
set -o pipefail
set -u
#
# Run a simple backup
#   then restore it.
#
TestName="$(basename "$(pwd)")"
export TestName

JobName=backup-bareos-fd

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

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

start_test

cat <<END_OF_DATA >"$tmp/bconcmds"
@$out ${NULL_DEV}
messages
@$out $tmp/hardlink-backup.out
setdebug level=100 storage=File
run job=backup-some-hardlinks yes
status director
status client
status storage=File
wait
messages
@#
@# now do a restore
@#
@$out $tmp/hardlink-restore.out
wait
messages
restore client=bareos-fd fileset=HardLinks where=$tmp/bareos-hardlink-restores select all done yes
wait
messages
quit
END_OF_DATA

run_bconsole
check_for_zombie_jobs storage=File

expect_grep "SD Files Written: *2" \
  "$tmp/hardlink-backup.out" \
  "hardlink was not properly backed up/restored."

expect_not_grep "Could not hard link" \
  "$tmp/hardlink-restore.out" \
  "hardlink was not properly backed up/restored."

check_two_logs "$tmp/hardlink-backup.out" "tmp/hardlink-restore.out"

end_test
