mirror of
https://github.com/offen/docker-volume-backup.git
synced 2024-11-24 06:00:27 +01:00
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 <frederik.ring@gmail.com>
This commit is contained in:
parent
336e12f874
commit
f97ce11734
@ -93,6 +93,8 @@ func compress(paths []string, outFilePath, algo string, concurrency int) error {
|
|||||||
|
|
||||||
func getCompressionWriter(file *os.File, algo string, concurrency int) (io.WriteCloser, error) {
|
func getCompressionWriter(file *os.File, algo string, concurrency int) (io.WriteCloser, error) {
|
||||||
switch algo {
|
switch algo {
|
||||||
|
case "none":
|
||||||
|
return &passThroughWriteCloser{file}, nil
|
||||||
case "gz":
|
case "gz":
|
||||||
w, err := pgzip.NewWriterLevel(file, 5)
|
w, err := pgzip.NewWriterLevel(file, 5)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -165,3 +167,15 @@ func writeTarball(path string, tarWriter *tar.Writer, prefix string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type passThroughWriteCloser struct {
|
||||||
|
target io.WriteCloser
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *passThroughWriteCloser) Write(b []byte) (int, error) {
|
||||||
|
return p.target.Write(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *passThroughWriteCloser) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -92,7 +92,7 @@ type CompressionType string
|
|||||||
|
|
||||||
func (c *CompressionType) Decode(v string) error {
|
func (c *CompressionType) Decode(v string) error {
|
||||||
switch v {
|
switch v {
|
||||||
case "gz", "zst":
|
case "none", "gz", "zst":
|
||||||
*c = CompressionType(v)
|
*c = CompressionType(v)
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
|
@ -86,7 +86,12 @@ func (s *script) init() error {
|
|||||||
|
|
||||||
var bf bytes.Buffer
|
var bf bytes.Buffer
|
||||||
if tErr := tmplFileName.Execute(&bf, map[string]string{
|
if tErr := tmplFileName.Execute(&bf, map[string]string{
|
||||||
"Extension": fmt.Sprintf("tar.%s", s.c.BackupCompression),
|
"Extension": func() string {
|
||||||
|
if s.c.BackupCompression == "none" {
|
||||||
|
return "tar"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("tar.%s", s.c.BackupCompression)
|
||||||
|
}(),
|
||||||
}); tErr != nil {
|
}); tErr != nil {
|
||||||
return errwrap.Wrap(tErr, "error executing backup file extension template")
|
return errwrap.Wrap(tErr, "error executing backup file extension template")
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,8 @@ You can populate below template according to your requirements and use it as you
|
|||||||
# BACKUP_CRON_EXPRESSION="0 2 * * *"
|
# BACKUP_CRON_EXPRESSION="0 2 * * *"
|
||||||
|
|
||||||
# The compression algorithm used in conjunction with tar.
|
# The compression algorithm used in conjunction with tar.
|
||||||
# Valid options are: "gz" (Gzip) and "zst" (Zstd).
|
# Valid options are: "gz" (Gzip), "zst" (Zstd) or "none" (tar only).
|
||||||
# Note that the selection affects the file extension.
|
# Default is "gz". Note that the selection affects the file extension.
|
||||||
|
|
||||||
# BACKUP_COMPRESSION="gz"
|
# BACKUP_COMPRESSION="gz"
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ You can populate below template according to your requirements and use it as you
|
|||||||
# will result in the same filename for every backup run, which means previous
|
# will result in the same filename for every backup run, which means previous
|
||||||
# versions will be overwritten on subsequent runs.
|
# versions will be overwritten on subsequent runs.
|
||||||
# Extension can be defined literally or via "{{ .Extension }}" template,
|
# Extension can be defined literally or via "{{ .Extension }}" template,
|
||||||
# in which case it will become either "tar.gz" or "tar.zst" (depending
|
# in which case it will become either "tar.gz", "tar.zst" or ".tar" (depending
|
||||||
# on your BACKUP_COMPRESSION setting).
|
# on your BACKUP_COMPRESSION setting).
|
||||||
# The default results in filenames like: `backup-2021-08-29T04-00-00.tar.gz`.
|
# The default results in filenames like: `backup-2021-08-29T04-00-00.tar.gz`.
|
||||||
|
|
||||||
|
21
test/tar/docker-compose.yml
Normal file
21
test/tar/docker-compose.yml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
services:
|
||||||
|
backup:
|
||||||
|
image: offen/docker-volume-backup:${TEST_VERSION:-canary}
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
BACKUP_FILENAME: test.{{ .Extension }}
|
||||||
|
BACKUP_COMPRESSION: none
|
||||||
|
volumes:
|
||||||
|
- app_data:/backup/app_data:ro
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
- ${LOCAL_DIR:-./local}:/archive
|
||||||
|
|
||||||
|
offen:
|
||||||
|
image: offen/offen:latest
|
||||||
|
labels:
|
||||||
|
- docker-volume-backup.stop-during-backup=true
|
||||||
|
volumes:
|
||||||
|
- app_data:/var/opt/offen
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
app_data:
|
25
test/tar/run.sh
Executable file
25
test/tar/run.sh
Executable file
@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
. ../util.sh
|
||||||
|
current_test=$(basename $(pwd))
|
||||||
|
|
||||||
|
export LOCAL_DIR=$(mktemp -d)
|
||||||
|
|
||||||
|
docker compose up -d --quiet-pull
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
docker compose exec backup backup
|
||||||
|
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
expect_running_containers "2"
|
||||||
|
|
||||||
|
tmp_dir=$(mktemp -d)
|
||||||
|
tar -xvf "$LOCAL_DIR/test.tar" -C $tmp_dir
|
||||||
|
if [ ! -f "$tmp_dir/backup/app_data/offen.db" ]; then
|
||||||
|
fail "Could not find expected file in untared archive."
|
||||||
|
fi
|
||||||
|
pass "Expected file was found."
|
Loading…
Reference in New Issue
Block a user