docker-restic-cron/tests/test.sh

75 lines
2.1 KiB
Bash
Raw Permalink Normal View History

2018-05-13 17:31:31 +00:00
#! /bin/bash
set -e
2018-05-13 17:31:31 +00:00
2021-06-14 22:55:26 +00:00
image="$1"
2018-05-13 17:31:31 +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 \
-e RESTIC_PASSWORD="Correct.Horse.Battery.Staple" \
2018-05-13 17:31:31 +00:00
-v "$(pwd)/test.sh:/test.sh" \
2021-06-14 22:55:26 +00:00
"$image" \
2018-05-13 17:31:31 +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-05-13 17:31:31 +00:00
type crontab
echo "Create test data..."
mkdir -p /data && echo Test > /data/test.txt
echo "Fake a start and init repo"
2021-06-15 00:01:52 +00:00
CRON_SCHEDULE="" /scripts/start.sh
2018-05-13 17:31:31 +00:00
echo "Making backup..."
2021-06-15 00:01:52 +00:00
/scripts/cron-exec.sh /scripts/backup.sh || { cat /cron.log && exit 1; }
2018-05-13 17:31:31 +00:00
echo "Verify backup..."
2021-06-15 00:01:52 +00:00
/scripts/cron-exec.sh /scripts/verify.sh || { cat /cron.log && exit 1; }
2018-05-13 17:31:31 +00:00
2021-06-14 22:55:26 +00:00
echo "Auto cleanup on second backup..."
2021-06-15 00:01:52 +00:00
CLEANUP_COMMAND="--prune --keep-last 1" /scripts/cron-exec.sh /scripts/backup.sh || { cat /cron.log && exit 1; }
2021-06-14 22:55:26 +00:00
2018-05-13 17:31:31 +00:00
echo "Delete test data..."
rm -fr /data/*
echo "Verify deleted..."
test -f /data/test.txt && exit 1 || echo "Gone"
echo "Restore backup..."
2021-06-15 00:01:52 +00:00
/scripts/cron-exec.sh /scripts/restore.sh latest || { cat /cron.log && exit 1; }
/scripts/healthcheck.sh
2018-05-13 17:31:31 +00:00
2018-08-10 18:20:47 +00:00
echo "Verify restore..."
test -f /data/test.txt
cat /data/test.txt
2018-05-13 17:31:31 +00:00
echo "Verify backup..."
2021-06-15 00:01:52 +00:00
/scripts/verify.sh
2018-05-13 17:31:31 +00:00
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..."
2021-06-15 00:01:52 +00:00
RESTORE_ON_EMPTY_START=true /scripts/start.sh || { cat /cron.log && exit 1; }
/scripts/healthcheck.sh || { echo "Failed healthcheck"; cat /cron.log; exit 1; }
2018-05-13 17:31:31 +00:00
echo "Verify restore happened..."
test -f /data/test.txt
cat /data/test.txt
2018-05-13 17:31:31 +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/cron-exec.sh /scripts/restore.sh latest && exit 1 || echo "OK"
2019-02-01 21:48:00 +00:00
echo "Verify failed healthcheck"
2021-06-15 00:01:52 +00:00
/scripts/healthcheck.sh && exit 1 || echo "OK"
2018-05-13 17:31:31 +00:00
fi