mirror of
https://github.com/offen/docker-volume-backup.git
synced 2025-12-05 17:18:02 +01:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c84674650 | ||
|
|
6fe81cdf2d | ||
|
|
b7ba0e08df |
@@ -11,6 +11,10 @@ jobs:
|
|||||||
name: Build
|
name: Build
|
||||||
command: |
|
command: |
|
||||||
docker build . -t offen/docker-volume-backup:canary
|
docker build . -t offen/docker-volume-backup:canary
|
||||||
|
- run:
|
||||||
|
name: Install gnupg
|
||||||
|
command: |
|
||||||
|
sudo apt-get install -y gnupg
|
||||||
- run:
|
- run:
|
||||||
name: Run tests
|
name: Run tests
|
||||||
working_directory: ~/docker-volume-backup/test
|
working_directory: ~/docker-volume-backup/test
|
||||||
|
|||||||
@@ -107,11 +107,14 @@ probe_expired () {
|
|||||||
local target=$1
|
local target=$1
|
||||||
local is_local=$2
|
local is_local=$2
|
||||||
if [ -z "$is_local" ]; then
|
if [ -z "$is_local" ]; then
|
||||||
|
if [ ! -z "$BACKUP_PRUNING_PREFIX" ]; then
|
||||||
|
target="${target}/${BACKUP_PRUNING_PREFIX}"
|
||||||
|
fi
|
||||||
mc rm $MC_GLOBAL_OPTIONS --fake --recursive --force \
|
mc rm $MC_GLOBAL_OPTIONS --fake --recursive --force \
|
||||||
--older-than "${BACKUP_RETENTION_DAYS}d" \
|
--older-than "${BACKUP_RETENTION_DAYS}d" \
|
||||||
"$target"
|
"$target"
|
||||||
else
|
else
|
||||||
find $target* -type f -mtime $BACKUP_RETENTION_DAYS
|
find $target -name "${BACKUP_PRUNING_PREFIX:-*}" -type f -mtime "+${BACKUP_RETENTION_DAYS}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,9 +122,12 @@ probe_all () {
|
|||||||
local target=$1
|
local target=$1
|
||||||
local is_local=$2
|
local is_local=$2
|
||||||
if [ -z "$is_local" ]; then
|
if [ -z "$is_local" ]; then
|
||||||
|
if [ ! -z "$BACKUP_PRUNING_PREFIX" ]; then
|
||||||
|
target="${target}/${BACKUP_PRUNING_PREFIX}"
|
||||||
|
fi
|
||||||
mc ls $MC_GLOBAL_OPTIONS "$target"
|
mc ls $MC_GLOBAL_OPTIONS "$target"
|
||||||
else
|
else
|
||||||
find $target* -type f
|
find $target -name "${BACKUP_PRUNING_PREFIX:-*}" -type f
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,21 +135,20 @@ delete () {
|
|||||||
local target=$1
|
local target=$1
|
||||||
local is_local=$2
|
local is_local=$2
|
||||||
if [ -z "$is_local" ]; then
|
if [ -z "$is_local" ]; then
|
||||||
|
if [ ! -z "$BACKUP_PRUNING_PREFIX" ]; then
|
||||||
|
target="${target}/${BACKUP_PRUNING_PREFIX}"
|
||||||
|
fi
|
||||||
mc rm $MC_GLOBAL_OPTIONS --recursive --force \
|
mc rm $MC_GLOBAL_OPTIONS --recursive --force \
|
||||||
--older-than "${BACKUP_RETENTION_DAYS}d" \
|
--older-than "${BACKUP_RETENTION_DAYS}d" \
|
||||||
"$target"
|
"$target"
|
||||||
else
|
else
|
||||||
find $target* -delete -type f -mtime $BACKUP_RETENTION_DAYS
|
find $target -name "${BACKUP_PRUNING_PREFIX:-*}" -type f -mtime "+${BACKUP_RETENTION_DAYS}" -delete
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
prune () {
|
prune () {
|
||||||
local target=$1
|
local target=$1
|
||||||
local is_local=$2
|
local is_local=$2
|
||||||
if [ ! -z "$BACKUP_PRUNING_PREFIX" ]; then
|
|
||||||
target="$target/${BACKUP_PRUNING_PREFIX}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
rule_applies_to=$(probe_expired "$target" "$is_local" | wc -l)
|
rule_applies_to=$(probe_expired "$target" "$is_local" | wc -l)
|
||||||
if [ "$rule_applies_to" == "0" ]; then
|
if [ "$rule_applies_to" == "0" ]; then
|
||||||
echo "No backups found older than the configured retention period of ${BACKUP_RETENTION_DAYS} days."
|
echo "No backups found older than the configured retention period of ${BACKUP_RETENTION_DAYS} days."
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ services:
|
|||||||
BACKUP_FILENAME: test.tar.gz
|
BACKUP_FILENAME: test.tar.gz
|
||||||
BACKUP_CRON_EXPRESSION: 0 0 5 31 2 ?
|
BACKUP_CRON_EXPRESSION: 0 0 5 31 2 ?
|
||||||
BACKUP_RETENTION_DAYS: ${BACKUP_RETENTION_DAYS:-7}
|
BACKUP_RETENTION_DAYS: ${BACKUP_RETENTION_DAYS:-7}
|
||||||
BACKUP_FORCE_PRUNE: ${BACKUP_FORCE_PRUNE:-}
|
|
||||||
BACKUP_PRUNING_LEEWAY: 5s
|
BACKUP_PRUNING_LEEWAY: 5s
|
||||||
BACKUP_PRUNING_PREFIX: test
|
BACKUP_PRUNING_PREFIX: test
|
||||||
|
GPG_PASSPHRASE: 1234secret
|
||||||
volumes:
|
volumes:
|
||||||
- ./local:/archive
|
- ./local:/archive
|
||||||
- app_data:/backup/app_data:ro
|
- app_data:/backup/app_data:ro
|
||||||
|
|||||||
@@ -13,11 +13,13 @@ docker-compose exec backup backup
|
|||||||
|
|
||||||
docker run --rm -it \
|
docker run --rm -it \
|
||||||
-v compose_backup_data:/data alpine \
|
-v compose_backup_data:/data alpine \
|
||||||
ash -c 'tar -xf /data/backup/test.tar.gz && test -f /backup/app_data/offen.db'
|
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'
|
||||||
|
|
||||||
echo "[TEST:PASS] Found relevant files in untared remote backup."
|
echo "[TEST:PASS] Found relevant files in untared remote backup."
|
||||||
|
|
||||||
tar -xf ./local/test.tar.gz -C /tmp && test -f /tmp/backup/app_data/offen.db
|
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
|
||||||
|
|
||||||
echo "[TEST:PASS] Found relevant files in untared local backup."
|
echo "[TEST:PASS] Found relevant files in untared local backup."
|
||||||
|
|
||||||
@@ -29,8 +31,6 @@ fi
|
|||||||
|
|
||||||
echo "[TEST:PASS] All containers running post backup."
|
echo "[TEST:PASS] All containers running post backup."
|
||||||
|
|
||||||
docker-compose down
|
|
||||||
|
|
||||||
# The second part of this test checks if backups get deleted when the retention
|
# 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)
|
# 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
|
# TODO: find out if we can test actual deletion without having to wait for a day
|
||||||
|
|||||||
Reference in New Issue
Block a user