Skip to content

Commit 45886e8

Browse files
jkatzJonathan S. Katz
authored andcommitted
Add support for the pgBackRest --compress-type flag
Selecting the compression type for pgBackRest is supported across recent Postgres Operator releases, but the CLI was not allowing for this flag to be passed through. This allows for the selection of pgBackRest compression type amongst the allowable methods in the container, which are none, bz2, gz, and lz4. Currently zst does not ship within the container. Issue: [ch10287]
1 parent eacd2bb commit 45886e8

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

internal/apiserver/backupoptions/backupoptionsutil.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ func isValidCompressLevel(compressLevel int) bool {
167167
}
168168
}
169169

170+
// isValidCompressType checks that the compression type passed in matches one
171+
// of the ones supported by pgBackRest. However, it presently does not support
172+
// `zst`
173+
func isValidCompressType(compressType string) bool {
174+
return compressType == "gz" || compressType == "bz2" || compressType == "lz4" || compressType == "none"
175+
}
176+
170177
// isValidRetentionRange validates that pgBackrest Full, Diff or Archive
171178
// retention option value is set within the allowable range.
172179
// allowed: 1-9999999
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package backupoptions
2+
3+
/*
4+
Copyright 2021 Crunchy Data Solutions, Inc.
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
import "testing"
19+
20+
func TestIsValidCompressType(t *testing.T) {
21+
tests := []struct {
22+
compressType string
23+
expected bool
24+
}{
25+
{compressType: "bz2", expected: true},
26+
{compressType: "gz", expected: true},
27+
{compressType: "none", expected: true},
28+
{compressType: "lz4", expected: true},
29+
{compressType: "zst", expected: false},
30+
{compressType: "bogus", expected: false},
31+
}
32+
33+
for _, test := range tests {
34+
t.Run(test.compressType, func(t *testing.T) {
35+
if isValidCompressType(test.compressType) != test.expected {
36+
t.Fatalf("expected %q to be %t", test.compressType, test.expected)
37+
}
38+
})
39+
}
40+
}

internal/apiserver/backupoptions/pgbackrestoptions.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type pgBackRestBackupOptions struct {
8282
NoCompress bool `flag:"no-compress"`
8383
CompressLevel int `flag:"compress-level"`
8484
CompressLevelNetwork int `flag:"compress-level-network"`
85+
CompressType string `flag:"compress-type"`
8586
DBTimeout int `flag:"db-timeout"`
8687
Delta bool `flag:"no-delta"`
8788
ProcessMax int `flag:"process-max"`
@@ -146,6 +147,11 @@ func (backRestBackupOpts pgBackRestBackupOptions) validate(setFlagFieldNames []s
146147
err := errors.New("Invalid network compress level for pgBackRest backup")
147148
errstrings = append(errstrings, err.Error())
148149
}
150+
case "CompressType":
151+
if !isValidCompressType(backRestBackupOpts.CompressType) {
152+
err := errors.New("Invalid compress type for pgBackRest backup")
153+
errstrings = append(errstrings, err.Error())
154+
}
149155
case "LogLevelConsole":
150156
if !isValidBackrestLogLevel(backRestBackupOpts.LogLevelConsole) {
151157
err := errors.New("Invalid log level for pgBackRest backup")

0 commit comments

Comments
 (0)