fix: 解决数据库备份错误的问题 (#4941)

This commit is contained in:
ssongliu 2024-05-09 21:50:24 +08:00 committed by GitHub
parent e799d1cc49
commit 5d9c09f69e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package client
import (
"bytes"
"compress/gzip"
"context"
"errors"
@ -230,11 +231,17 @@ func (r *Local) Backup(info BackupInfo) error {
}
global.LOG.Infof("start to %s | gzip > %s.gzip", dumpCmd, info.TargetDir+"/"+info.FileName)
cmd := exec.Command("docker", "exec", r.ContainerName, dumpCmd, "-uroot", "-p"+r.Password, "--default-character-set="+info.Format, info.Name)
var stderr bytes.Buffer
cmd.Stderr = &stderr
gzipCmd := exec.Command("gzip", "-cf")
gzipCmd.Stdin, _ = cmd.StdoutPipe()
gzipCmd.Stdout = outfile
_ = gzipCmd.Start()
_ = cmd.Run()
if err := cmd.Run(); err != nil {
return fmt.Errorf("handle backup database failed, err: %v", stderr.String())
}
_ = gzipCmd.Wait()
return nil
}

View File

@ -1,6 +1,7 @@
package client
import (
"bytes"
"compress/gzip"
"context"
"database/sql"
@ -249,12 +250,17 @@ func (r *Remote) Backup(info BackupInfo) error {
global.LOG.Debug(backupCmd)
cmd := exec.Command("bash", "-c", backupCmd)
var stderr bytes.Buffer
cmd.Stderr = &stderr
gzipCmd := exec.Command("gzip", "-cf")
gzipCmd.Stdin, _ = cmd.StdoutPipe()
gzipCmd.Stdout = outfile
_ = gzipCmd.Start()
_ = cmd.Run()
if err := cmd.Run(); err != nil {
return fmt.Errorf("handle backup database failed, err: %v", stderr.String())
}
_ = gzipCmd.Wait()
return nil
}