fix: 修复几处日志文件未释放问题 (#5110)

pull/5143/head
Node 6 months ago committed by GitHub
parent b59c9ee9ad
commit f211b6b5ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -150,6 +150,7 @@ func runComposeCmdWithLog(operate string, composePath string, logPath string) er
global.LOG.Errorf("Failed to open log file: %v", err) global.LOG.Errorf("Failed to open log file: %v", err)
return err return err
} }
defer logFile.Close()
multiWriterStdout := io.MultiWriter(os.Stdout, logFile) multiWriterStdout := io.MultiWriter(os.Stdout, logFile)
cmd.Stdout = multiWriterStdout cmd.Stdout = multiWriterStdout
var stderrBuf bytes.Buffer var stderrBuf bytes.Buffer

@ -224,7 +224,10 @@ func (r *Local) Backup(info BackupInfo) error {
return fmt.Errorf("mkdir %s failed, err: %v", info.TargetDir, err) return fmt.Errorf("mkdir %s failed, err: %v", info.TargetDir, err)
} }
} }
outfile, _ := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755) outfile, err := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755)
if err == nil {
defer outfile.Close()
}
dumpCmd := "mysqldump" dumpCmd := "mysqldump"
if r.Type == constant.AppMariaDB { if r.Type == constant.AppMariaDB {
dumpCmd = "mariadb-dump" dumpCmd = "mariadb-dump"

@ -235,7 +235,10 @@ func (r *Remote) Backup(info BackupInfo) error {
return fmt.Errorf("mkdir %s failed, err: %v", info.TargetDir, err) return fmt.Errorf("mkdir %s failed, err: %v", info.TargetDir, err)
} }
} }
outfile, _ := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755) outfile, err := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755)
if err == nil {
defer outfile.Close()
}
dumpCmd := "mysqldump" dumpCmd := "mysqldump"
if r.Type == constant.AppMariaDB { if r.Type == constant.AppMariaDB {
dumpCmd = "mariadb-dump" dumpCmd = "mariadb-dump"

@ -129,7 +129,10 @@ func (r *Local) Backup(info BackupInfo) error {
return fmt.Errorf("mkdir %s failed, err: %v", info.TargetDir, err) return fmt.Errorf("mkdir %s failed, err: %v", info.TargetDir, err)
} }
} }
outfile, _ := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755) outfile, err := os.OpenFile(path.Join(info.TargetDir, info.FileName), os.O_RDWR|os.O_CREATE, 0755)
if err == nil {
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)
cmd := exec.Command("docker", "exec", r.ContainerName, "pg_dump", "-F", "c", "-U", r.Username, "-d", info.Name) cmd := exec.Command("docker", "exec", r.ContainerName, "pg_dump", "-F", "c", "-U", r.Username, "-d", info.Name)
gzipCmd := exec.Command("gzip", "-cf") gzipCmd := exec.Command("gzip", "-cf")

Loading…
Cancel
Save