From f151227edd7fd2dd7658258f25fee20754c3f0b3 Mon Sep 17 00:00:00 2001 From: Avi Deitcher Date: Tue, 6 May 2025 12:19:38 +0300 Subject: [PATCH] add support for no compression Signed-off-by: Avi Deitcher --- cmd/dump.go | 2 +- cmd/restore.go | 2 +- docs/configuration.md | 2 +- pkg/compression/bzip2.go | 2 ++ pkg/compression/compressor.go | 2 ++ pkg/compression/gzip.go | 2 ++ pkg/compression/none.go | 29 +++++++++++++++++++++++++++++ 7 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 pkg/compression/none.go diff --git a/cmd/dump.go b/cmd/dump.go index 8d6b07ea..d9b0152b 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -315,7 +315,7 @@ S3: If it is a URL of the format s3://bucketname/path then it will connect via S flags.Bool("safechars", false, "The dump filename usually includes the character `:` in the date, to comply with RFC3339. Some systems and shells don't like that character. If true, will replace all `:` with `-`.") // compression - flags.String("compression", defaultCompression, "Compression to use. Supported are: `gzip`, `bzip2`") + flags.String("compression", defaultCompression, "Compression to use. Supported are: `gzip`, `bzip2`, `none`") // source filename pattern flags.String("filename-pattern", defaultFilenamePattern, "Pattern to use for filename in target. See documentation.") diff --git a/cmd/restore.go b/cmd/restore.go index 30c4632d..127247f7 100644 --- a/cmd/restore.go +++ b/cmd/restore.go @@ -149,7 +149,7 @@ func restoreCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command, } // compression - flags.String("compression", defaultCompression, "Compression to use. Supported are: `gzip`, `bzip2`") + flags.String("compression", defaultCompression, "Compression to use. Supported are: `gzip`, `bzip2`, `none`") // specific database to which to restore flags.String("database", "", "Mapping of from:to database names to which to restore, comma-separated, e.g. foo:bar,buz:qux. Replaces the `USE ` clauses in a backup file. If blank, uses the file as is.") diff --git a/docs/configuration.md b/docs/configuration.md index d6438406..45234fa0 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -87,7 +87,7 @@ The following are the environment variables, CLI flags and configuration file op | path-style addressing for S3 bucket instead of default virtual-host-style addressing | BR | `aws-path-style` | `AWS_PATH_STYLE` | `dump.targets[s3-target].pathStyle` | | | SMB username, used only if a target does not have one | BRP | `smb-user` | `SMB_USER` | `dump.targets[smb-target].username` | | | SMB password, used only if a target does not have one | BRP | `smb-pass` | `SMB_PASS` | `dump.targets[smb-target].password` | | -| compression to use, one of: `bzip2`, `gzip` | BP | `compression` | `DB_DUMP_COMPRESSION` | `dump.compression` | `gzip` | +| compression to use, one of: `bzip2`, `gzip`, `none` | BP | `compression` | `DB_DUMP_COMPRESSION` | `dump.compression` | `gzip` | | whether to include triggers, procedures and functions | B | `triggers-and-functions` | `DB_DUMP_TRIGGERS_AND_FUNCTIONS` | `dump.triggersAndFunctions` | `false` | | when in container, run the dump or restore with `nice`/`ionice` | BR | `` | `NICE` | `` | `false` | | filename to save the target backup file | B | `dump --filename-pattern` | `DB_DUMP_FILENAME_PATTERN` | `dump.filenamePattern` | | diff --git a/pkg/compression/bzip2.go b/pkg/compression/bzip2.go index 529dbdca..ffe6e49f 100644 --- a/pkg/compression/bzip2.go +++ b/pkg/compression/bzip2.go @@ -6,6 +6,8 @@ import ( "github.com/dsnet/compress/bzip2" ) +var _ Compressor = &Bzip2Compressor{} + type Bzip2Compressor struct { } diff --git a/pkg/compression/compressor.go b/pkg/compression/compressor.go index 545b5e79..8e955e16 100644 --- a/pkg/compression/compressor.go +++ b/pkg/compression/compressor.go @@ -17,6 +17,8 @@ func GetCompressor(name string) (Compressor, error) { return &GzipCompressor{}, nil case "bzip2": return &Bzip2Compressor{}, nil + case "none": + return &NoCompressor{}, nil default: return nil, fmt.Errorf("unknown compression format: %s", name) } diff --git a/pkg/compression/gzip.go b/pkg/compression/gzip.go index eabad2ba..15ef6e1e 100644 --- a/pkg/compression/gzip.go +++ b/pkg/compression/gzip.go @@ -5,6 +5,8 @@ import ( "io" ) +var _ Compressor = &GzipCompressor{} + type GzipCompressor struct { } diff --git a/pkg/compression/none.go b/pkg/compression/none.go new file mode 100644 index 00000000..c746e39d --- /dev/null +++ b/pkg/compression/none.go @@ -0,0 +1,29 @@ +package compression + +import ( + "io" +) + +var _ Compressor = &NoCompressor{} + +type NoCompressor struct { +} + +func (n *NoCompressor) Uncompress(in io.Reader) (io.Reader, error) { + return in, nil +} + +func (n *NoCompressor) Compress(out io.Writer) (io.WriteCloser, error) { + return &nopWriteCloser{out}, nil +} +func (n *NoCompressor) Extension() string { + return "tar" +} + +type nopWriteCloser struct { + io.Writer +} + +func (n *nopWriteCloser) Close() error { + return nil +}