mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-19 22:09:03 +08:00
fix: Fix local PostgreSQL database backup failure (#11295)
This commit is contained in:
parent
23a3a5cf74
commit
3d3d22dc06
1 changed files with 2 additions and 8 deletions
|
|
@ -134,11 +134,7 @@ func (r *Local) Backup(info BackupInfo) error {
|
||||||
defer outfile.Close()
|
defer outfile.Close()
|
||||||
global.LOG.Infof("start to pg_dump | gzip > %s.gzip", info.TargetDir+"/"+info.FileName)
|
global.LOG.Infof("start to pg_dump | gzip > %s.gzip", info.TargetDir+"/"+info.FileName)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(info.Timeout*uint(time.Second)))
|
cmd := exec.Command("docker", "exec", "-i", r.ContainerName,
|
||||||
defer cancel()
|
|
||||||
cmd := exec.CommandContext(
|
|
||||||
ctx,
|
|
||||||
"docker", "exec", "-i", r.ContainerName,
|
|
||||||
"sh", "-c",
|
"sh", "-c",
|
||||||
fmt.Sprintf("PGPASSWORD=%s pg_dump -F c -U %s -d %s", r.Password, r.Username, info.Name),
|
fmt.Sprintf("PGPASSWORD=%s pg_dump -F c -U %s -d %s", r.Password, r.Username, info.Name),
|
||||||
)
|
)
|
||||||
|
|
@ -161,9 +157,7 @@ func (r *Local) Recover(info RecoverInfo) error {
|
||||||
fi, _ := os.Open(info.SourceFile)
|
fi, _ := os.Open(info.SourceFile)
|
||||||
defer fi.Close()
|
defer fi.Close()
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(info.Timeout*uint(time.Second)))
|
cmd := exec.Command("docker", "exec", "-i", r.ContainerName, "sh", "-c",
|
||||||
defer cancel()
|
|
||||||
cmd := exec.CommandContext(ctx, "docker", "exec", "-i", r.ContainerName, "sh", "-c",
|
|
||||||
fmt.Sprintf("PGPASSWORD=%s pg_restore -F c -c --if-exists --no-owner -U %s -d %s", r.Password, r.Username, info.Name),
|
fmt.Sprintf("PGPASSWORD=%s pg_restore -F c -c --if-exists --no-owner -U %s -d %s", r.Password, r.Username, info.Name),
|
||||||
)
|
)
|
||||||
if strings.HasSuffix(info.SourceFile, ".gz") {
|
if strings.HasSuffix(info.SourceFile, ".gz") {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue