2021-07-09 08:14:35 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2021-07-09 09:21:42 +02:00
|
|
|
cd $(dirname $0)
|
|
|
|
|
2021-08-19 09:25:53 +02:00
|
|
|
mkdir -p local
|
|
|
|
|
2021-07-09 09:21:42 +02:00
|
|
|
docker-compose up -d
|
|
|
|
sleep 5
|
|
|
|
|
2021-09-04 10:09:51 +02:00
|
|
|
docker-compose exec offen ln -s /var/opt/offen/offen.db /var/opt/offen/db.link
|
2021-07-09 09:21:42 +02:00
|
|
|
docker-compose exec backup backup
|
|
|
|
|
|
|
|
docker run --rm -it \
|
2021-07-11 13:27:01 +02:00
|
|
|
-v compose_backup_data:/data alpine \
|
2021-08-23 09:08:50 +02:00
|
|
|
ash -c 'apk add gnupg && echo 1234secret | gpg -d --pinentry-mode loopback --passphrase-fd 0 --yes /data/backup/test.tar.gz.gpg > /tmp/test.tar.gz && tar -xf /tmp/test.tar.gz -C /tmp && test -f /tmp/backup/app_data/offen.db'
|
2021-07-09 09:21:42 +02:00
|
|
|
|
2021-08-19 09:25:53 +02:00
|
|
|
echo "[TEST:PASS] Found relevant files in untared remote backup."
|
|
|
|
|
2021-10-01 10:07:46 +02:00
|
|
|
test -L ./local/test.latest.tar.gz.gpg
|
2021-12-10 10:18:52 +01:00
|
|
|
|
|
|
|
owner=$(stat -c '%U:%G' ./local/test.tar.gz.gpg)
|
|
|
|
if [ "$owner" != "1000:1000" ]; then
|
|
|
|
echo "[TEST:FAIL] Expected backup file to have correct owners, got $owner"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-08-23 09:08:50 +02:00
|
|
|
echo 1234secret | gpg -d --yes --passphrase-fd 0 ./local/test.tar.gz.gpg > ./local/decrypted.tar.gz
|
|
|
|
tar -xf ./local/decrypted.tar.gz -C /tmp && test -f /tmp/backup/app_data/offen.db
|
|
|
|
rm ./local/decrypted.tar.gz
|
2021-09-04 10:09:51 +02:00
|
|
|
test -L /tmp/backup/app_data/db.link
|
2021-08-19 09:25:53 +02:00
|
|
|
|
|
|
|
echo "[TEST:PASS] Found relevant files in untared local backup."
|
2021-07-11 09:43:16 +02:00
|
|
|
|
2021-07-09 09:57:05 +02:00
|
|
|
if [ "$(docker-compose ps -q | wc -l)" != "3" ]; then
|
2021-07-11 09:43:16 +02:00
|
|
|
echo "[TEST:FAIL] Expected all containers to be running post backup, instead seen:"
|
2021-07-09 09:57:05 +02:00
|
|
|
docker-compose ps
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-07-11 09:43:16 +02:00
|
|
|
echo "[TEST:PASS] All containers running post backup."
|
2021-07-09 09:21:42 +02:00
|
|
|
|
2021-08-20 08:56:04 +02:00
|
|
|
# The second part of this test checks if backups get deleted when the retention
|
|
|
|
# is set to 0 days (which it should not as it would mean all backups get deleted)
|
|
|
|
# TODO: find out if we can test actual deletion without having to wait for a day
|
|
|
|
BACKUP_RETENTION_DAYS="0" docker-compose up -d
|
|
|
|
sleep 5
|
|
|
|
|
|
|
|
docker-compose exec backup backup
|
|
|
|
|
|
|
|
docker run --rm -it \
|
|
|
|
-v compose_backup_data:/data alpine \
|
|
|
|
ash -c '[ $(find /data/backup/ -type f | wc -l) = "1" ]'
|
|
|
|
|
|
|
|
echo "[TEST:PASS] Remote backups have not been deleted."
|
|
|
|
|
|
|
|
if [ "$(find ./local -type f | wc -l)" != "1" ]; then
|
|
|
|
echo "[TEST:FAIL] Backups should not have been deleted, instead seen:"
|
|
|
|
find ./local -type f
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "[TEST:PASS] Local backups have not been deleted."
|
|
|
|
|
2021-07-11 09:43:16 +02:00
|
|
|
docker-compose down --volumes
|