mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-22 08:00:53 +00:00
fix: Fix local PostgreSQL database backup failure (#11295)
This commit is contained in:
@@ -134,11 +134,7 @@ func (r *Local) Backup(info BackupInfo) error {
|
||||
defer outfile.Close()
|
||||
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)))
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(
|
||||
ctx,
|
||||
"docker", "exec", "-i", r.ContainerName,
|
||||
cmd := exec.Command("docker", "exec", "-i", r.ContainerName,
|
||||
"sh", "-c",
|
||||
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)
|
||||
defer fi.Close()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(info.Timeout*uint(time.Second)))
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(ctx, "docker", "exec", "-i", r.ContainerName, "sh", "-c",
|
||||
cmd := exec.Command("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),
|
||||
)
|
||||
if strings.HasSuffix(info.SourceFile, ".gz") {
|
||||
|
||||
Reference in New Issue
Block a user