mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-27 20:49:03 +08:00
fix: 解决数据库备份错误的问题 (#4941)
This commit is contained in:
parent
e799d1cc49
commit
5d9c09f69e
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user