Skip to content

Commit 775fd1e

Browse files
authored
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. This also removes the `--compress` and `--no-compress` flags, and removes `--compress-level` from being considered in the "restore" command, as pgBackRest does not use that flag there. Issue: [ch10287]
1 parent e2aa57b commit 775fd1e

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

internal/apiserver/backupoptions/backupoptionsutil.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ func isValidCompressLevel(compressLevel int) bool {
164164
}
165165
}
166166

167+
// isValidCompressType checks that the compression type passed in matches one
168+
// of the ones supported by pgBackRest. However, it presently does not support
169+
// `zst`
170+
func isValidCompressType(compressType string) bool {
171+
return compressType == "gz" || compressType == "bz2" || compressType == "lz4" || compressType == "none"
172+
}
173+
167174
// isValidRetentionRange validates that pgBackrest Full, Diff or Archive
168175
// retention option value is set within the allowable range.
169176
// 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 & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ type pgBackRestBackupOptions struct {
7878
NoStopAuto bool `flag:"no-stop-auto"`
7979
BackupType string `flag:"type"`
8080
BufferSize string `flag:"buffer-size"`
81-
Compress bool `flag:"compress"`
82-
NoCompress bool `flag:"no-compress"`
8381
CompressLevel int `flag:"compress-level"`
8482
CompressLevelNetwork int `flag:"compress-level-network"`
83+
CompressType string `flag:"compress-type"`
8584
DBTimeout int `flag:"db-timeout"`
8685
Delta bool `flag:"no-delta"`
8786
ProcessMax int `flag:"process-max"`
@@ -108,9 +107,6 @@ type pgBackRestRestoreOptions struct {
108107
TargetTimeline int `flag:"target-timeline"`
109108
RestoreType string `flag:"type"`
110109
BufferSize string `flag:"buffer-size"`
111-
Compress bool `flag:"compress"`
112-
NoCompress bool `flag:"no-compress"`
113-
CompressLevel int `flag:"compress-level"`
114110
CompressLevelNetwork int `flag:"compress-level-network"`
115111
DBTimeout int `flag:"db-timeout"`
116112
Delta bool `flag:"no-delta"`
@@ -145,6 +141,11 @@ func (backRestBackupOpts pgBackRestBackupOptions) validate(setFlagFieldNames []s
145141
err := errors.New("Invalid network compress level for pgBackRest backup")
146142
errstrings = append(errstrings, err.Error())
147143
}
144+
case "CompressType":
145+
if !isValidCompressType(backRestBackupOpts.CompressType) {
146+
err := errors.New("Invalid compress type for pgBackRest backup")
147+
errstrings = append(errstrings, err.Error())
148+
}
148149
case "LogLevelConsole":
149150
if !isValidBackrestLogLevel(backRestBackupOpts.LogLevelConsole) {
150151
err := errors.New("Invalid log level for pgBackRest backup")
@@ -212,11 +213,6 @@ func (backRestRestoreOpts pgBackRestRestoreOptions) validate(setFlagFieldNames [
212213
err := errors.New("Invalid type provided for pgBackRest restore")
213214
errstrings = append(errstrings, err.Error())
214215
}
215-
case "CompressLevel":
216-
if !isValidCompressLevel(backRestRestoreOpts.CompressLevel) {
217-
err := errors.New("Invalid compress level for pgBackRest restore")
218-
errstrings = append(errstrings, err.Error())
219-
}
220216
case "CompressLevelNetwork":
221217
if !isValidCompressLevel(backRestRestoreOpts.CompressLevelNetwork) {
222218
err := errors.New("Invalid network compress level for pgBackRest restore")

0 commit comments

Comments
 (0)