From 9c357f1ea4e0bcadfa592adf08b6580cc750e0d1 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 23 May 2024 23:16:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E8=BF=87=E7=A8=8B=E4=B8=AD=E5=A4=87=E4=BB=BD=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#5120)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #5103 --- backend/utils/mysql/client/local.go | 5 +++-- backend/utils/mysql/client/remote.go | 5 +++-- backend/utils/postgresql/client/local.go | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/backend/utils/mysql/client/local.go b/backend/utils/mysql/client/local.go index 5e5fe7e57..b79c73616 100644 --- a/backend/utils/mysql/client/local.go +++ b/backend/utils/mysql/client/local.go @@ -225,9 +225,10 @@ func (r *Local) Backup(info BackupInfo) error { } } outfile, err := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755) - if err == nil { - defer outfile.Close() + if err != nil { + return fmt.Errorf("open file %s failed, err: %v", path.Join(info.TargetDir, info.FileName), err) } + defer outfile.Close() dumpCmd := "mysqldump" if r.Type == constant.AppMariaDB { dumpCmd = "mariadb-dump" diff --git a/backend/utils/mysql/client/remote.go b/backend/utils/mysql/client/remote.go index 17ea7029f..1229c2f5d 100644 --- a/backend/utils/mysql/client/remote.go +++ b/backend/utils/mysql/client/remote.go @@ -236,9 +236,10 @@ func (r *Remote) Backup(info BackupInfo) error { } } outfile, err := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755) - if err == nil { - defer outfile.Close() + if err != nil { + return fmt.Errorf("open file %s failed, err: %v", path.Join(info.TargetDir, info.FileName), err) } + defer outfile.Close() dumpCmd := "mysqldump" if r.Type == constant.AppMariaDB { dumpCmd = "mariadb-dump" diff --git a/backend/utils/postgresql/client/local.go b/backend/utils/postgresql/client/local.go index 4b927e78c..1e0e15f6b 100644 --- a/backend/utils/postgresql/client/local.go +++ b/backend/utils/postgresql/client/local.go @@ -130,9 +130,10 @@ func (r *Local) Backup(info BackupInfo) error { } } outfile, err := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755) - if err == nil { - defer outfile.Close() + if err != nil { + return fmt.Errorf("open file %s failed, err: %v", path.Join(info.TargetDir, info.FileName), err) } + defer outfile.Close() global.LOG.Infof("start to pg_dump | gzip > %s.gzip", info.TargetDir+"/"+info.FileName) cmd := exec.Command("docker", "exec", r.ContainerName, "pg_dump", "-F", "c", "-U", r.Username, "-d", info.Name) gzipCmd := exec.Command("gzip", "-cf")