#!/bin/bash

# this is supposed to verify that Paranoid Backup can backup, compare, and
# restore reliably.

cd /root/Paranoidbackup || exit

if
  test -e test
then
  echo "'test' already exists"
  exit
elif
  test -e all/mdti/commands
then
  echo  all/mdti/commands already exists
  exit
elif
  test ! "$1" = "--part2"
then
  testpb --part2 2>&1 | tee --append output
  exit
fi



# the next line might or might not be needed; it does no harm, so
# we might as well have and not worry about whether or not it is needed.
export LC_COLLATE=POSIX




echo =====================================================
echo test started at:
date +%c
set -e
set -x

mkdir test
echo 'include=../all/config' > test/config
echo 'DirectoryToBackup=/root/Paranoidbackup' >> test/config
ln -s '../all/directory_include_exclude' test/directory_include_exclude
ln -s '../all/include_exclude' test/include_exclude
> test/virtual_restore_list

paranoidbackup.pl --check-configuration --config=/root/Paranoidbackup/test/config
echo exit code of check configuration was $?
paranoidbackup.pl --backup --config=/root/Paranoidbackup/test/config
echo exit code of backup was $?
paranoidbackup.pl --compare --config=/root/Paranoidbackup/test/config
echo exit code of compare was $?
paranoidbackup.pl --list --config=/root/Paranoidbackup/test/config
echo exit code of list was $?
cd test
ls -lr
cd ..
all/mdti/start &
sleep 10
cat all/mdti/index
echo -e "delete\npb_all_control.kxarc" > all/mdti/commands
sleep 5
echo -e "delete\npb_all_1.kxarc" > all/mdti/commands
sleep 5
echo exit > all/mdti/commands
rm -fr test

set +x
echo test done at:
date +%c

exit

The file 'output' is the log of the output of Paranoid Backup; the
file changes as paranoid backup runs; thus the file will
be different while being compared than it was while being backed up;
thus the compare will warn you that the file 'output' has changed.
However, if you include/exclude lists exclude output, then output will
be excluded from the backup and from the compare, and paranoid backup will
not warn you that the file has changed.

This test creates a file named virtual_restore_list, the file changes
during the test backup, at the end of the test backup the file is
compressed to virtual_restore_list.gz; thus the file no longer exists
during the test compare, and paranoid backup will warn you that the file
does not exist.

So the warnings about output and virtual_restore_list are normal, and mean
paranoid backup is working. Any other error messages mean something is
wrong.
