Skip to content

Commit f97ce11

Browse files
jzebedeem90
andauthored
Add "none" compression type (#457)
* Add "none" compression type * Add "none" compression to docs * Use passThroughWriteCloser for "none" compression * Add test for none compression --------- Co-authored-by: Frederik Ring <[email protected]>
1 parent 336e12f commit f97ce11

File tree

6 files changed

+70
-5
lines changed

6 files changed

+70
-5
lines changed

cmd/backup/archive.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ func compress(paths []string, outFilePath, algo string, concurrency int) error {
9393

9494
func getCompressionWriter(file *os.File, algo string, concurrency int) (io.WriteCloser, error) {
9595
switch algo {
96+
case "none":
97+
return &passThroughWriteCloser{file}, nil
9698
case "gz":
9799
w, err := pgzip.NewWriterLevel(file, 5)
98100
if err != nil {
@@ -165,3 +167,15 @@ func writeTarball(path string, tarWriter *tar.Writer, prefix string) error {
165167

166168
return nil
167169
}
170+
171+
type passThroughWriteCloser struct {
172+
target io.WriteCloser
173+
}
174+
175+
func (p *passThroughWriteCloser) Write(b []byte) (int, error) {
176+
return p.target.Write(b)
177+
}
178+
179+
func (p *passThroughWriteCloser) Close() error {
180+
return nil
181+
}

cmd/backup/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type CompressionType string
9292

9393
func (c *CompressionType) Decode(v string) error {
9494
switch v {
95-
case "gz", "zst":
95+
case "none", "gz", "zst":
9696
*c = CompressionType(v)
9797
return nil
9898
default:

cmd/backup/script.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ func (s *script) init() error {
8686

8787
var bf bytes.Buffer
8888
if tErr := tmplFileName.Execute(&bf, map[string]string{
89-
"Extension": fmt.Sprintf("tar.%s", s.c.BackupCompression),
89+
"Extension": func() string {
90+
if s.c.BackupCompression == "none" {
91+
return "tar"
92+
}
93+
return fmt.Sprintf("tar.%s", s.c.BackupCompression)
94+
}(),
9095
}); tErr != nil {
9196
return errwrap.Wrap(tErr, "error executing backup file extension template")
9297
}

docs/reference/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ You can populate below template according to your requirements and use it as you
4343
# BACKUP_CRON_EXPRESSION="0 2 * * *"
4444
4545
# The compression algorithm used in conjunction with tar.
46-
# Valid options are: "gz" (Gzip) and "zst" (Zstd).
47-
# Note that the selection affects the file extension.
46+
# Valid options are: "gz" (Gzip), "zst" (Zstd) or "none" (tar only).
47+
# Default is "gz". Note that the selection affects the file extension.
4848
4949
# BACKUP_COMPRESSION="gz"
5050
@@ -60,7 +60,7 @@ You can populate below template according to your requirements and use it as you
6060
# will result in the same filename for every backup run, which means previous
6161
# versions will be overwritten on subsequent runs.
6262
# Extension can be defined literally or via "{{ .Extension }}" template,
63-
# in which case it will become either "tar.gz" or "tar.zst" (depending
63+
# in which case it will become either "tar.gz", "tar.zst" or ".tar" (depending
6464
# on your BACKUP_COMPRESSION setting).
6565
# The default results in filenames like: `backup-2021-08-29T04-00-00.tar.gz`.
6666

test/tar/docker-compose.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
backup:
3+
image: offen/docker-volume-backup:${TEST_VERSION:-canary}
4+
restart: always
5+
environment:
6+
BACKUP_FILENAME: test.{{ .Extension }}
7+
BACKUP_COMPRESSION: none
8+
volumes:
9+
- app_data:/backup/app_data:ro
10+
- /var/run/docker.sock:/var/run/docker.sock
11+
- ${LOCAL_DIR:-./local}:/archive
12+
13+
offen:
14+
image: offen/offen:latest
15+
labels:
16+
- docker-volume-backup.stop-during-backup=true
17+
volumes:
18+
- app_data:/var/opt/offen
19+
20+
volumes:
21+
app_data:

test/tar/run.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
cd "$(dirname "$0")"
6+
. ../util.sh
7+
current_test=$(basename $(pwd))
8+
9+
export LOCAL_DIR=$(mktemp -d)
10+
11+
docker compose up -d --quiet-pull
12+
sleep 5
13+
14+
docker compose exec backup backup
15+
16+
sleep 5
17+
18+
expect_running_containers "2"
19+
20+
tmp_dir=$(mktemp -d)
21+
tar -xvf "$LOCAL_DIR/test.tar" -C $tmp_dir
22+
if [ ! -f "$tmp_dir/backup/app_data/offen.db" ]; then
23+
fail "Could not find expected file in untared archive."
24+
fi
25+
pass "Expected file was found."

0 commit comments

Comments
 (0)