From 9701ca9ec6618368a7329add3b4118a55d47e2d3 Mon Sep 17 00:00:00 2001 From: toxisch Date: Fri, 15 May 2020 11:41:59 +0200 Subject: [PATCH 1/3] remove DEFINER from sql stream with sed pipe --- service/mysql/backup.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/service/mysql/backup.go b/service/mysql/backup.go index 4321e0ec..4092eb3d 100644 --- a/service/mysql/backup.go +++ b/service/mysql/backup.go @@ -55,10 +55,12 @@ func Backup(ctx context.Context, s3 *s3.Client, service util.Service, binding *c } log.Debugf("executing mysql backup command: %v", strings.Join(command, " ")) - cmd := exec.CommandContext(ctx, command[0], command[1:]...) + mysqldumpCmd := exec.CommandContext(ctx, command[0], command[1:]...) + sedCmd := exec.CommandContext(ctx, "sed", "-e", "s/DEFINER=[^*]*\\*/\\*/g") // capture stdout to pass to gzipping buffer - outPipe, err := cmd.StdoutPipe() + outPipe, _ := sedCmd.StdoutPipe() + _, err := mysqldumpCmd.StdoutPipe() if err != nil { log.Errorf("could not get stdout pipe for mysqldump: %v", err) state.BackupFailure(service) @@ -66,6 +68,11 @@ func Backup(ctx context.Context, s3 *s3.Client, service util.Service, binding *c } defer outPipe.Close() + // pipe mysqldumpCmd to sedCmd + sedPipeR, sedPipeW := io.Pipe() + mysqldumpCmd.Stdout = sedPipeW + sedCmd.Stdin = sedPipeR + var uploadWait sync.WaitGroup uploadCtx, uploadCancel := context.WithCancel(context.Background()) // allows upload to be cancelable, in case backup times out defer uploadCancel() // cancel upload in case Backup() exits before uploadWait is done @@ -104,15 +111,16 @@ func Backup(ctx context.Context, s3 *s3.Client, service util.Service, binding *c // capture and read stderr in case an error occurs var errBuf bytes.Buffer - cmd.Stderr = &errBuf + mysqldumpCmd.Stderr = &errBuf - if err := cmd.Start(); err != nil { + if err := mysqldumpCmd.Start(); err != nil { log.Errorf("could not run mysqldump: %v", err) state.BackupFailure(service) return err } + sedCmd.Start() - if err := cmd.Wait(); err != nil { + if err := mysqldumpCmd.Wait(); err != nil { state.BackupFailure(service) // check for timeout error if ctx.Err() == context.DeadlineExceeded { @@ -122,7 +130,8 @@ func Backup(ctx context.Context, s3 *s3.Client, service util.Service, binding *c log.Errorln(strings.TrimRight(errBuf.String(), "\r\n")) return fmt.Errorf("mysqldump: %v", err) } - + sedPipeW.Close() + sedCmd.Wait() uploadWait.Wait() // wait for upload to have finished if err == nil { state.BackupSuccess(service) From 7abe317f1d68c5b04c698be0b7a038cffa1bb5b3 Mon Sep 17 00:00:00 2001 From: Vinicius Pontes Date: Fri, 28 Aug 2020 15:27:08 +0200 Subject: [PATCH 2/3] added "--hex-blob" to mysqldump save geodata correctly --- service/mysql/backup.go | 1 + 1 file changed, 1 insertion(+) diff --git a/service/mysql/backup.go b/service/mysql/backup.go index 4092eb3d..45d2116c 100644 --- a/service/mysql/backup.go +++ b/service/mysql/backup.go @@ -41,6 +41,7 @@ func Backup(ctx context.Context, s3 *s3.Client, service util.Service, binding *c command = append(command, "--single-transaction") command = append(command, "--quick") command = append(command, "--skip-add-locks") + command = append(command, "--hex-blob=TRUE") command = append(command, "-h") command = append(command, credentials.Hostname) command = append(command, "-P") From 81cf5c66b72968a1d11fff51287a2a0465b79eb5 Mon Sep 17 00:00:00 2001 From: toxisch Date: Wed, 30 Mar 2022 11:20:09 +0200 Subject: [PATCH 3/3] drop collection on mongo restore Signed-off-by: toxisch --- service/mongodb/restore.go | 1 + 1 file changed, 1 insertion(+) diff --git a/service/mongodb/restore.go b/service/mongodb/restore.go index 74922fa1..a72dccb7 100644 --- a/service/mongodb/restore.go +++ b/service/mongodb/restore.go @@ -32,6 +32,7 @@ func Restore(ctx context.Context, s3 *s3.Client, service util.Service, binding * command = append(command, "--uri") command = append(command, uri) command = append(command, "--gzip") + command = append(command, "--drop") command = append(command, "--archive") log.Debugf("executing mongodb restore command: %v", strings.Join(command, " "))