Skip to content

Commit ad4e2af

Browse files
authored
Exclude specific backends from pruning (#262)
* Skip backends while pruning * Add pruning test step and silence download log for better readability * Add test cases for pruning in all backends Also add -q or --quiet-pull to all tests. * Add test case for skipping backends while pruning * Adjusted test logging, generate new test spec file * Gitignore for temp test file
1 parent 5fcc96e commit ad4e2af

File tree

25 files changed

+330
-40
lines changed

25 files changed

+330
-40
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ You can populate below template according to your requirements and use it as you
205205

206206
# BACKUP_EXCLUDE_REGEXP="\.log$"
207207

208+
# Exclude one or many storage backends from the pruning process.
209+
# E.g. with one backend excluded: BACKUP_SKIP_BACKENDS_FROM_PRUNE=s3
210+
# E.g. with multiple backends excluded: BACKUP_SKIP_BACKENDS_FROM_PRUNE=s3,webdav
211+
# Available backends are: S3, WebDAV, SSH, Local, Dropbox, Azure
212+
# Note: The name of the backends is case insensitive.
213+
# Default: All backends get pruned.
214+
215+
# BACKUP_SKIP_BACKENDS_FROM_PRUNE=
216+
208217
########### BACKUP STORAGE
209218

210219
# The name of the remote bucket that should be used for storing backups. If

cmd/backup/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Config struct {
4141
BackupStopContainerLabel string `split_words:"true" default:"true"`
4242
BackupFromSnapshot bool `split_words:"true"`
4343
BackupExcludeRegexp RegexpDecoder `split_words:"true"`
44+
BackupSkipBackendsFromPrune []string `split_words:"true"`
4445
GpgPassphrase string `split_words:"true"`
4546
NotificationURLs []string `envconfig:"NOTIFICATION_URLS"`
4647
NotificationLevel string `split_words:"true" default:"error"`

cmd/backup/script.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"os"
1515
"path"
1616
"path/filepath"
17+
"slices"
18+
"strings"
1719
"text/template"
1820
"time"
1921

@@ -591,6 +593,12 @@ func (s *script) pruneBackups() error {
591593
for _, backend := range s.storages {
592594
b := backend
593595
eg.Go(func() error {
596+
if skipPrune(b.Name(), s.c.BackupSkipBackendsFromPrune) {
597+
s.logger.Info(
598+
fmt.Sprintf("Skipping pruning for backend `%s`.", b.Name()),
599+
)
600+
return nil
601+
}
594602
stats, err := b.Prune(deadline, s.c.BackupPruningPrefix)
595603
if err != nil {
596604
return err
@@ -622,3 +630,14 @@ func (s *script) must(err error) {
622630
panic(err)
623631
}
624632
}
633+
634+
// skipPrune returns true if the given backend name is contained in the
635+
// list of skipped backends.
636+
func skipPrune(name string, skippedBackends []string) bool {
637+
return slices.ContainsFunc(
638+
skippedBackends,
639+
func(b string) bool {
640+
return strings.EqualFold(b, name) // ignore case on both sides
641+
},
642+
)
643+
}

test/azure/run.sh

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,61 @@ cd "$(dirname "$0")"
66
. ../util.sh
77
current_test=$(basename $(pwd))
88

9-
docker compose up -d
9+
download_az () {
10+
docker compose run --rm az_cli \
11+
az storage blob download -f /dump/$1.tar.gz -c test-container -n path/to/backup/$1.tar.gz
12+
}
13+
14+
docker compose up -d --quiet-pull
1015
sleep 5
1116

12-
# A symlink for a known file in the volume is created so the test can check
13-
# whether symlinks are preserved on backup.
1417
docker compose exec backup backup
1518

1619
sleep 5
1720

1821
expect_running_containers "3"
1922

20-
docker compose run --rm az_cli \
21-
az storage blob download -f /dump/test.tar.gz -c test-container -n path/to/backup/test.tar.gz
23+
download_az "test"
2224
tar -xvf ./local/test.tar.gz -C /tmp && test -f /tmp/backup/app_data/offen.db
2325

2426
pass "Found relevant files in untared remote backups."
2527

2628
# The second part of this test checks if backups get deleted when the retention
2729
# is set to 0 days (which it should not as it would mean all backups get deleted)
28-
# TODO: find out if we can test actual deletion without having to wait for a day
2930
BACKUP_RETENTION_DAYS="0" docker compose up -d
3031
sleep 5
3132

3233
docker compose exec backup backup
3334

34-
docker compose run --rm az_cli \
35-
az storage blob download -f /dump/test.tar.gz -c test-container -n path/to/backup/test.tar.gz
35+
download_az "test"
3636
test -f ./local/test.tar.gz
3737

3838
pass "Remote backups have not been deleted."
3939

40+
# The third part of this test checks if old backups get deleted when the retention
41+
# is set to 7 days (which it should)
42+
43+
BACKUP_RETENTION_DAYS="7" docker compose up -d
44+
sleep 5
45+
46+
info "Create first backup with no prune"
47+
docker compose exec backup backup
48+
49+
sudo date --set="14 days ago"
50+
51+
docker compose run --rm az_cli \
52+
az storage blob upload -f /dump/test.tar.gz -c test-container -n path/to/backup/test-old.tar.gz
53+
54+
sudo date --set="14 days"
55+
56+
info "Create second backup and prune"
57+
docker compose exec backup backup
58+
59+
info "Download first backup which should be pruned"
60+
download_az "test-old" || true
61+
test ! -f ./local/test-old.tar.gz
62+
test -f ./local/test.tar.gz
63+
64+
pass "Old remote backup has been pruned, new one is still present."
65+
4066
docker compose down --volumes

test/certs/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ openssl x509 -req -passin pass:test \
2424

2525
openssl x509 -in minio.crt -noout -text
2626

27-
docker compose up -d
27+
docker compose up -d --quiet-pull
2828
sleep 5
2929

3030
docker compose exec backup backup

test/cli/run.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ docker volume create app_data
1313
# correctly. It is not supposed to hold any data.
1414
docker volume create empty_data
1515

16-
docker run -d \
16+
docker run -d -q \
1717
--name minio \
1818
--network test_network \
1919
--env MINIO_ROOT_USER=test \
@@ -25,15 +25,15 @@ docker run -d \
2525

2626
docker exec minio mkdir -p /data/backup
2727

28-
docker run -d \
28+
docker run -d -q \
2929
--name offen \
3030
--network test_network \
3131
-v app_data:/var/opt/offen/ \
3232
offen/offen:latest
3333

3434
sleep 10
3535

36-
docker run --rm \
36+
docker run --rm -q \
3737
--network test_network \
3838
-v app_data:/backup/app_data \
3939
-v empty_data:/backup/empty_data \
@@ -48,7 +48,7 @@ docker run --rm \
4848
--entrypoint backup \
4949
offen/docker-volume-backup:${TEST_VERSION:-canary}
5050

51-
docker run --rm \
51+
docker run --rm -q \
5252
-v backup_data:/data alpine \
5353
ash -c 'tar -xvf /data/backup/test.tar.gz && test -f /backup/app_data/offen.db && test -d /backup/empty_data'
5454

test/commands/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ current_test=$(basename $(pwd))
88

99
mkdir -p ./local
1010

11-
docker compose up -d
11+
docker compose up -d --quiet-pull
1212
sleep 30 # mariadb likes to take a bit before responding
1313

1414
docker compose exec backup backup

test/confd/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ current_test=$(basename $(pwd))
88

99
mkdir -p local
1010

11-
docker compose up -d
11+
docker compose up -d --quiet-pull
1212

1313
# sleep until a backup is guaranteed to have happened on the 1 minute schedule
1414
sleep 100

test/dropbox/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
user_v2_ready.yaml

test/dropbox/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
ports:
1010
- 8080:8080
1111
volumes:
12-
- ./user_v2.yaml:/etc/openapi/user_v2.yaml
12+
- ./user_v2_ready.yaml:/etc/openapi/user_v2.yaml
1313

1414
oauth2_mock:
1515
image: ghcr.io/navikt/mock-oauth2-server:1.0.0

0 commit comments

Comments
 (0)