docker-restic-cron/tests/test.sh

65 lines
1.4 KiB
Bash
Raw Normal View History

2018-05-13 17:31:31 +00:00
#! /bin/bash
2018-07-24 15:38:22 +00:00
set -e
2018-05-13 17:31:31 +00:00
image=$1
if [ "$IN_CONTAINER" != "true" ] ; then
# Run the test script within the container
docker run --rm \
-e IN_CONTAINER=true \
-e SKIP_ON_START=true \
2018-07-24 15:38:22 +00:00
-e RESTIC_PASSWORD="Correct.Horse.Battery.Staple" \
2018-05-13 17:31:31 +00:00
-v "$(pwd)/test.sh:/test.sh" \
$image \
bash -c "/test.sh"
else
echo "Performing backup tests"
echo "Verify cron and crontab exist"
type cron
type crontab
echo "Create test data..."
mkdir -p /data && echo Test > /data/test.txt
2018-07-24 15:38:22 +00:00
echo "Fake a start and init repo"
CRON_SCHEDULE="" /start.sh
2018-05-13 17:31:31 +00:00
echo "Making backup..."
/backup.sh
echo "Verify backup..."
/verify.sh
echo "Delete test data..."
rm -fr /data/*
echo "Verify deleted..."
test -f /data/test.txt && exit 1 || echo "Gone"
echo "Restore backup..."
2018-07-24 15:38:22 +00:00
/restore.sh latest
echo "Verify restore..."
cat /data/test.txt
2018-05-13 17:31:31 +00:00
echo "Verify backup..."
/verify.sh
echo "Delete test data again..."
rm -fr /data/*
echo "Verify deleted..."
test -f /data/test.txt && exit 1 || echo "Gone"
echo "Simulate a restart with RESTORE_ON_EMPTY_START..."
RESTORE_ON_EMPTY_START=true /start.sh
2018-05-13 17:31:31 +00:00
echo "Verify restore happened..."
2018-07-24 15:38:22 +00:00
cat /data/test.txt
2018-05-13 17:31:31 +00:00
echo "Verify restore with incorrect passphrase fails..."
echo "Fail to restore backup..."
2018-07-24 15:38:22 +00:00
RESTIC_PASSWORD=Incorrect.Mule.Solar.Paperclip /restore.sh latest && exit 1 || echo "OK"
2018-05-13 17:31:31 +00:00
fi