#!/bin/bash

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
fi

echo =====================================================
echo test starting time:
date +%c
set -e
set -x

mkdir test
echo 'include=../all/config' > test/config
echo 'DirectoryToBackup=/root/Paranoidbackup' >> test/config
echo include=../config.dos >> test/config
ln -s '../all/directory_exclude' test/directory_exclude
ln -s '../all/include_exclude' test/include_exclude
pb --make-virtual-restore-list --config=test/config
echo exit code of make virtual restore list was $?
cd test
ls -lr
cd ..
pb --backup --config=test/config
echo exit code of backup was $?
cd test
ls -lr
cd ..
pb --list --config=test/config
echo exit code of list was $?
rm -f test/cont* test/l* test/v*
all/mdti/start &
sleep 10
cat all/mdti/index
echo -e "delete\ncntrl" > all/mdti/commands
sleep 5
echo -e "delete\npb_1" > all/mdti/commands
sleep 5
echo exit > all/mdti/commands

echo Repeat=2 >>test/config
> test/virtual_restore_list
pb --check-configuration --config=test/config
echo exit code of check configuration was $?
pb --backup --config=test/config
echo exit code of backup was $?
cd test
ls -lr
cd ..
cat all/mdti/index
echo foo > delete_me_1
echo foo > delete_me_2
pb --prepare-for-new-files --config=test/config
echo exit code of prepare for new files was $?
cd test
ls -lr
cd ..
echo bar > delete_me_2
echo bar > delete_me_3
pb --exclude-new-files --config=test/config
echo exit code of exclude new files was $?
cd test
ls -lr
cd ..
echo prblst > delete_me_4
pb --backup --config=test/config
echo exit code of backup was $?
cd test
ls -lr
cd ..
cat all/mdti/index
pb --list --config=test/config
echo exit code of list was $?
pb --list --config=test/config > list_log
pb --compare --config=test/config
echo exit code of compare was $?
echo DirectoryToBackup=test_restore >>test/config
mkdir test_restore
pb --restore --config=test/config
echo exit code of restore was $?
cd test_restore
ls -lr
cd ..

echo DirectoryToBackup=test_restore_s >>test/config
mkdir test_restore_s
pb --find --config=test/config '--pattern=\.pl$' '--pattern=^C'
echo exit code of find was $?
pb --restore-selected-files --config=test/config --file-name=1.2:paranoidbackup.pl
echo exit code of restore was $?
pb --compare-selected-files --config=test/config --file-name=1:paranoidbackup.pl
echo exit code of compare was $?
cd test_restore_s
ls -lr
cd ..

echo DirectoryToBackup=test_restore1 >>test/config
mkdir test_restore1
pb --desperate-restore-1a --config=test/config
echo exit code of desperate restore 1a was $?
pb --desperate-restore-1b --config=test/config
echo exit code of desperate restore 1b was $?
cd test_restore1
ls -lr
cd ..

echo DirectoryToBackup=test_restore2 >>test/config
mkdir test_restore2
set +e
pb --desperate-restore-2 --config=test/config
echo exit code of desperate restore 2 was $?
set -e
cd test_restore2
ls -lr
cd ..

cd test
ls -lr
rm -f cont* l* v*
rm -r repeat2
cd ..
all/mdti/start &
sleep 10
cat all/mdti/index
echo -e "delete\ncntrl2" > all/mdti/commands
sleep 5
echo -e "delete\ncntrl" > all/mdti/commands
sleep 5
echo -e "delete\npb_2.2" > all/mdti/commands
sleep 5
echo -e "delete\npb_2" > all/mdti/commands
sleep 5
echo -e "delete\npb_1.2" > all/mdti/commands
sleep 5
echo -e "delete\npb_1" > all/mdti/commands
sleep 5
echo exit > all/mdti/commands

rm -fr test_restore test_restore1 test_restore2 test_restore_s



set +e

echo 'include=../all/config' > test/config
echo 'DirectoryToBackup=/root/Paranoidbackup' >> test/config
echo include=../config.dos >>test/config
echo DirectoryToBackup=test_restore >>test/config
mkdir test_restore
pb --compare --config=test/config
echo exit code of compare was $?
pb --restore --config=test/config
echo exit code of restore was $?
cd test_restore
ls -lr
cd ..
rm -fr test_restore

mv test/include_exclude test/include_exclude~
cp test/include_exclude~ test/include_exclude
echo 'exc output$' >> test/include_exclude
mkdir test_restore
pb --make-virtual-restore-list --config=test/config
echo exit code of make virtual restore list was $?
pb --backup --config=test/config
echo exit code of backup was $?
rm test/include_exclude
mv test/include_exclude~ test/include_exclude
cd test
ls -lr
cd ..
rm -fr delete_me_? test test_restore 
set +x
echo time when done test:
date +%c
exit



echo 'include=../all/config' > test/config
echo 'DirectoryToBackup=/root/Paranoidbackup' >> test/config
echo include=../config.afio >>test/config
echo include=../config.dos >>test/config
> test/virtual_restore_list
pb --check-configuration --config=test/config
echo exit code of check configuration was $?
pb --backup --config=test/config
echo exit code of backup was $?
pb --list --config=test/config
echo exit code of list was $?
pb --compare --config=test/config
echo exit code of compare was $?
echo DirectoryToBackup=test_restore_a >>test/config
mkdir test_restore_a
pb --restore --config=test/config
echo exit code of restore was $?
cd test_restore_a
ls -lr
cd test
ls -lr
rm -f cont* l* v*
cd ..
all/mdti/start &
sleep 10
cat all/mdti/index
echo -e "delete\ncntrl" > all/mdti/commands
sleep 5
echo -e "delete\npb_1" > all/mdti/commands
sleep 5
echo exit > all/mdti/commands

echo 'include=../all/config' > test/config
echo 'DirectoryToBackup=/root/Paranoidbackup' >> test/config
echo include=../config.tar >>test/config
echo include=../config.dos >>test/config
> test/virtual_restore_list
pb --check-configuration --config=test/config
echo exit code of check configuration was $?
pb --backup --config=test/config
echo exit code of backup was $?
pb --list --config=test/config
echo exit code of list was $?
pb --compare --config=test/config
echo exit code of compare was $?
echo DirectoryToBackup=test_restore_t >>test/config
mkdir test_restore_t
pb --restore --config=test/config
echo exit code of restore was $?
cd test_restore_t
ls -lr
cd test
ls -lr
rm -f cont* l* v*
cd ..
all/mdti/start &
sleep 10
cat all/mdti/index
echo -e "delete\ncntrl" > all/mdti/commands
sleep 5
echo -e "delete\npb_1" > all/mdti/commands
sleep 5
echo exit > all/mdti/commands

echo 'include=../all/config' > test/config
echo 'DirectoryToBackup=/root/Paranoidbackup' >> test/config
echo include=../config.cpio >>test/config
echo include=../config.dos >>test/config
> test/virtual_restore_list
pb --check-configuration --config=test/config
echo exit code of check configuration was $?
pb --backup --config=test/config
echo exit code of backup was $?
pb --list --config=test/config
echo exit code of list was $?
echo DirectoryToBackup=test_restore_c >>test/config
mkdir test_restore_c
pb --restore --config=test/config
echo exit code of restore was $?
cd test_restore_c
ls -lr
cd test
ls -lr
rm -f cont* l* v*
cd ..
all/mdti/start &
sleep 10
cat all/mdti/index
echo -e "delete\ncntrl" > all/mdti/commands
sleep 5
echo -e "delete\npb_1" > all/mdti/commands
sleep 5
echo exit > all/mdti/commands

rm -fr test_restore_a test_restore_t test_restore_c

exit

This tests most features of Paranoid Backup; if there are bugs
this should find them

This includes config.dos because I was testing it on a dos floppy;
testing with a floppy is much faster than testing with a tape.

Special thanks to AOL for donating the floppy disk which was used for
these tests!

When I run this, I use the command 'lo bug_test'. 'lo' is a program which
logs output and standard error output to a file name 'output' in the current
directory.

This is not a real program. When I was testing Paranoid Backup, I did a
series of tests. Then I cat'ed all my test scripts into a single test
script. Then I started to edit it, to make it into a unified test program,
but by then I was finished testing Paranoid Backup, so the test program did
not seem so important, so I never finished. Thus this is still partly a
mess.
