Skip to content

Commit 3d3d22d

Browse files
authored
fix: Fix local PostgreSQL database backup failure (#11295)
1 parent 23a3a5c commit 3d3d22d

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

agent/utils/postgresql/client/local.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,7 @@ func (r *Local) Backup(info BackupInfo) error {
134134
defer outfile.Close()
135135
global.LOG.Infof("start to pg_dump | gzip > %s.gzip", info.TargetDir+"/"+info.FileName)
136136

137-
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(info.Timeout*uint(time.Second)))
138-
defer cancel()
139-
cmd := exec.CommandContext(
140-
ctx,
141-
"docker", "exec", "-i", r.ContainerName,
137+
cmd := exec.Command("docker", "exec", "-i", r.ContainerName,
142138
"sh", "-c",
143139
fmt.Sprintf("PGPASSWORD=%s pg_dump -F c -U %s -d %s", r.Password, r.Username, info.Name),
144140
)
@@ -161,9 +157,7 @@ func (r *Local) Recover(info RecoverInfo) error {
161157
fi, _ := os.Open(info.SourceFile)
162158
defer fi.Close()
163159

164-
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(info.Timeout*uint(time.Second)))
165-
defer cancel()
166-
cmd := exec.CommandContext(ctx, "docker", "exec", "-i", r.ContainerName, "sh", "-c",
160+
cmd := exec.Command("docker", "exec", "-i", r.ContainerName, "sh", "-c",
167161
fmt.Sprintf("PGPASSWORD=%s pg_restore -F c -c --if-exists --no-owner -U %s -d %s", r.Password, r.Username, info.Name),
168162
)
169163
if strings.HasSuffix(info.SourceFile, ".gz") {

0 commit comments

Comments
 (0)