-
Notifications
You must be signed in to change notification settings - Fork 183
feat: Replace deprecated qpress with configurable compression options for backups #4340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3
Are you sure you want to change the base?
Changes from 2 commits
f60a433
5e2b948
7d79131
f8a38dd
4f2606f
591cbf3
3503ba4
f2d7d1a
d4093e6
43f5800
51b5ad3
d490673
50afba6
534a92c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,7 @@ type MongoDBBackupJob struct { | |
| dataModel backuppb.DataModel | ||
| jobLogger *pbmJobLogger | ||
| folder string | ||
| compression backuppb.BackupCompression | ||
| } | ||
|
|
||
| // NewMongoDBBackupJob creates new Job for MongoDB backup. | ||
|
|
@@ -62,6 +63,7 @@ func NewMongoDBBackupJob( | |
| pitr bool, | ||
| dataModel backuppb.DataModel, | ||
| folder string, | ||
| compression backuppb.BackupCompression, | ||
| ) (*MongoDBBackupJob, error) { | ||
| if dataModel != backuppb.DataModel_DATA_MODEL_PHYSICAL && dataModel != backuppb.DataModel_DATA_MODEL_LOGICAL { | ||
| return nil, errors.Errorf("'%s' is not a supported data model for MongoDB backups", dataModel) | ||
|
|
@@ -81,6 +83,7 @@ func NewMongoDBBackupJob( | |
| dataModel: dataModel, | ||
| jobLogger: newPbmJobLogger(id, pbmBackupJob, dsn), | ||
| folder: folder, | ||
| compression: compression, | ||
| }, nil | ||
| } | ||
|
|
||
|
|
@@ -216,6 +219,26 @@ func (j *MongoDBBackupJob) startBackup(ctx context.Context) (*pbmBackup, error) | |
| return nil, errors.Errorf("'%s' is not a supported data model for backups", j.dataModel) | ||
| } | ||
|
|
||
| switch j.compression { | ||
| case backuppb.BackupCompression_BACKUP_COMPRESSION_DEFAULT: | ||
| case backuppb.BackupCompression_BACKUP_COMPRESSION_GZIP: | ||
| pbmArgs = append(pbmArgs, "--compression=gzip") | ||
| case backuppb.BackupCompression_BACKUP_COMPRESSION_SNAPPY: | ||
| pbmArgs = append(pbmArgs, "--compression=snappy") | ||
| case backuppb.BackupCompression_BACKUP_COMPRESSION_LZ4: | ||
| pbmArgs = append(pbmArgs, "--compression=lz4") | ||
| case backuppb.BackupCompression_BACKUP_COMPRESSION_S2: | ||
| pbmArgs = append(pbmArgs, "--compression=s2") | ||
|
Comment on lines
+230
to
+231
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are we sure pbm supports this compression method?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, also documented as the default -- https://docs.percona.com/percona-backup-mongodb/reference/backup-options.html#backupcompression |
||
| case backuppb.BackupCompression_BACKUP_COMPRESSION_PGZIP: | ||
| pbmArgs = append(pbmArgs, "--compression=pgzip") | ||
| case backuppb.BackupCompression_BACKUP_COMPRESSION_ZSTD: | ||
| pbmArgs = append(pbmArgs, "--compression=zstd") | ||
| case backuppb.BackupCompression_BACKUP_COMPRESSION_NONE: | ||
| pbmArgs = append(pbmArgs, "--compression=none") | ||
| default: | ||
| return nil, errors.Errorf("unknown compression: %s", j.compression) | ||
| } | ||
|
|
||
| if err := execPBMCommand(ctx, j.dsn, &result, pbmArgs...); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,10 +46,11 @@ type MySQLBackupJob struct { | |
| connConf DBConnConfig | ||
| locationConfig BackupLocationConfig | ||
| folder string | ||
| compression backuppb.BackupCompression | ||
| } | ||
|
|
||
| // NewMySQLBackupJob constructs new Job for MySQL backup. | ||
| func NewMySQLBackupJob(id string, timeout time.Duration, name string, connConf DBConnConfig, locationConfig BackupLocationConfig, folder string) *MySQLBackupJob { | ||
| func NewMySQLBackupJob(id string, timeout time.Duration, name string, connConf DBConnConfig, locationConfig BackupLocationConfig, folder string, compression backuppb.BackupCompression) *MySQLBackupJob { | ||
| return &MySQLBackupJob{ | ||
| id: id, | ||
| timeout: timeout, | ||
|
|
@@ -58,6 +59,7 @@ func NewMySQLBackupJob(id string, timeout time.Duration, name string, connConf D | |
| connConf: connConf, | ||
| locationConfig: locationConfig, | ||
| folder: folder, | ||
| compression: compression, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -119,8 +121,10 @@ func (j *MySQLBackupJob) binariesInstalled() error { | |
| return errors.Wrapf(err, "lookpath: %s", xtrabackupBin) | ||
| } | ||
|
|
||
| if _, err := exec.LookPath(qpressBin); err != nil { | ||
| return errors.Wrapf(err, "lookpath: %s", qpressBin) | ||
| if j.compression == backuppb.BackupCompression_BACKUP_COMPRESSION_QUICKLZ { | ||
| if _, err := exec.LookPath(qpressBin); err != nil { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensures we only check that qpress is installed if user wants to explicitly use quicklz, other compression options are installed as part of xtrabackup, so no need to explicitly check for them |
||
| return errors.Wrapf(err, "lookpath: %s", qpressBin) | ||
| } | ||
| } | ||
|
|
||
| if j.locationConfig.Type == S3BackupLocationType { | ||
|
|
@@ -149,12 +153,25 @@ func (j *MySQLBackupJob) backup(ctx context.Context) (rerr error) { | |
|
|
||
| xtrabackupCmd := exec.CommandContext(pipeCtx, | ||
| xtrabackupBin, | ||
| "--compress", | ||
| "--backup", | ||
| // Target dir is created, even though it's empty, because we are streaming it to cloud. | ||
| // https://jira.percona.com/browse/PXB-2602 | ||
| "--target-dir="+tmpDir) // #nosec G204 | ||
|
|
||
| switch j.compression { | ||
| case backuppb.BackupCompression_BACKUP_COMPRESSION_DEFAULT: | ||
| xtrabackupCmd.Args = append(xtrabackupCmd.Args, "--compress") | ||
| case backuppb.BackupCompression_BACKUP_COMPRESSION_QUICKLZ: | ||
| xtrabackupCmd.Args = append(xtrabackupCmd.Args, "--compress=quicklz") | ||
| case backuppb.BackupCompression_BACKUP_COMPRESSION_ZSTD: | ||
| xtrabackupCmd.Args = append(xtrabackupCmd.Args, "--compress=zstd") | ||
| case backuppb.BackupCompression_BACKUP_COMPRESSION_LZ4: | ||
| xtrabackupCmd.Args = append(xtrabackupCmd.Args, "--compress=lz4") | ||
| case backuppb.BackupCompression_BACKUP_COMPRESSION_NONE: | ||
| default: | ||
| return errors.Errorf("unknown compression: %s", j.compression) | ||
| } | ||
|
|
||
| if j.connConf.User != "" { | ||
| xtrabackupCmd.Args = append(xtrabackupCmd.Args, "--user="+j.connConf.User) | ||
| xtrabackupCmd.Args = append(xtrabackupCmd.Args, "--password="+j.connConf.Password) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specifies PBMs configuration options, and by default no specific compression
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks to me like it's defaulting to gzip though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its an empty case block, allowing to use PBM's default option to compress with s2, can explicitly specify that if that's preferred.