2018-09-28 00:32:55 +00:00
|
|
|
#! /bin/bash
|
|
|
|
set -e
|
|
|
|
|
2021-06-14 22:55:26 +00:00
|
|
|
image="$1"
|
2018-09-28 00:32:55 +00:00
|
|
|
|
|
|
|
if [ "$IN_CONTAINER" != "true" ] ; then
|
|
|
|
# Run the test script within the container
|
|
|
|
docker run --rm \
|
|
|
|
-e IN_CONTAINER=true \
|
|
|
|
-e SKIP_ON_START=true \
|
2019-01-28 19:55:12 +00:00
|
|
|
-e RESTIC_PASSWORD="Correct.Horse.Battery.Staple" \
|
2018-09-28 00:32:55 +00:00
|
|
|
-v "$(pwd)/test-pre-scripts.sh:/test.sh" \
|
2021-06-15 00:01:52 +00:00
|
|
|
-v "$(pwd)/test-pre-scripts/backup:/scripts/backup" \
|
|
|
|
-v "$(pwd)/test-pre-scripts/restore:/scripts/restore" \
|
|
|
|
-v "$(pwd)/test-pre-scripts/create-test-data.sql:/scripts/create-test-data.sql" \
|
2021-06-14 22:55:26 +00:00
|
|
|
"$image" \
|
2018-09-28 00:32:55 +00:00
|
|
|
bash -c "/test.sh"
|
|
|
|
else
|
|
|
|
echo "Performing backup tests"
|
|
|
|
|
|
|
|
echo "Verify cron and crontab exist"
|
2021-06-15 00:01:52 +00:00
|
|
|
type crond
|
2018-09-28 00:32:55 +00:00
|
|
|
type crontab
|
|
|
|
|
2019-01-28 17:53:41 +00:00
|
|
|
echo "Install sqlite3"
|
2021-06-15 00:01:52 +00:00
|
|
|
apk add sqlite
|
2019-01-28 17:53:41 +00:00
|
|
|
|
2018-09-28 00:32:55 +00:00
|
|
|
echo "Create test data..."
|
2019-01-28 17:53:41 +00:00
|
|
|
mkdir -p /data
|
|
|
|
touch /data/test_database.db
|
|
|
|
sqlite3 /data/test_database.db < /scripts/create-test-data.sql
|
2018-09-28 00:32:55 +00:00
|
|
|
|
2019-01-28 19:55:12 +00:00
|
|
|
echo "Fake a start and init repo"
|
2021-06-15 00:01:52 +00:00
|
|
|
CRON_SCHEDULE="" /scripts/start.sh
|
2019-01-28 19:55:12 +00:00
|
|
|
|
2018-09-28 00:32:55 +00:00
|
|
|
echo "Making backup..."
|
2021-06-15 00:01:52 +00:00
|
|
|
/scripts/backup.sh
|
2018-09-28 00:32:55 +00:00
|
|
|
|
2019-01-28 17:53:41 +00:00
|
|
|
echo "Verify intermediary file is gone"
|
|
|
|
test -f /data/test_database.db.bak && exit 1 || echo "Gone"
|
|
|
|
|
2018-09-28 00:32:55 +00:00
|
|
|
echo "Delete test data..."
|
|
|
|
rm -fr /data/*
|
|
|
|
|
|
|
|
echo "Verify deleted..."
|
2019-01-28 17:53:41 +00:00
|
|
|
test -f /data/test_database.db && exit 1 || echo "Gone"
|
2018-09-28 00:32:55 +00:00
|
|
|
|
|
|
|
echo "Restore backup..."
|
2021-06-15 00:01:52 +00:00
|
|
|
/scripts/restore.sh latest
|
2018-09-28 00:32:55 +00:00
|
|
|
|
2019-01-28 17:53:41 +00:00
|
|
|
echo "Verify restored files exist..."
|
|
|
|
test -f /data/test_database.db
|
|
|
|
test -f /data/test_database.db.bak && exit 1 || echo "Gone"
|
|
|
|
sqlite3 /data/test_database.db "select data from test_table where id = 1"
|
2018-09-28 00:32:55 +00:00
|
|
|
|
|
|
|
echo "Delete test data again..."
|
|
|
|
rm -fr /data/*
|
|
|
|
|
|
|
|
echo "Verify deleted..."
|
2019-01-28 17:53:41 +00:00
|
|
|
test -f /data/test_database.db && exit 1 || echo "Gone"
|
2018-09-28 00:32:55 +00:00
|
|
|
|
|
|
|
echo "Simulate a restart with RESTORE_ON_EMPTY_START..."
|
2021-06-15 00:01:52 +00:00
|
|
|
RESTORE_ON_EMPTY_START=true /scripts/start.sh
|
2018-09-28 00:32:55 +00:00
|
|
|
|
|
|
|
echo "Verify restore happened..."
|
2019-01-28 17:53:41 +00:00
|
|
|
test -f /data/test_database.db
|
|
|
|
test -f /data/test_database.db.bak && exit 1 || echo "Gone"
|
|
|
|
sqlite3 /data/test_database.db "select data from test_table where id = 1"
|
2018-09-28 00:32:55 +00:00
|
|
|
|
2019-01-28 17:53:41 +00:00
|
|
|
echo "Delete test data..."
|
|
|
|
rm -fr /data/*
|
2018-09-28 00:32:55 +00:00
|
|
|
|
|
|
|
echo "Verify restore with incorrect passphrase fails..."
|
|
|
|
echo "Fail to restore backup..."
|
2021-06-15 00:01:52 +00:00
|
|
|
RESTIC_PASSWORD=Incorrect.Mule.Solar.Paperclip /scripts/restore.sh latest && exit 1 || echo "OK"
|
2018-09-28 00:32:55 +00:00
|
|
|
fi
|