From ac384628c924e38e299fed17a56853289551e3e3 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 6 Jun 2024 16:03:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=8E=8B=E7=BC=A9?= =?UTF-8?q?=E5=A4=87=E4=BB=BD=E6=81=A2=E5=A4=8D=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#5322)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/backup_website.go | 2 +- backend/app/service/cronjob_helper.go | 2 +- backend/app/service/snapshot.go | 2 +- backend/utils/postgresql/client/local.go | 9 ++++++++- frontend/src/views/setting/snapshot/index.vue | 1 + 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/app/service/backup_website.go b/backend/app/service/backup_website.go index 10709fc5b..da0c659b0 100644 --- a/backend/app/service/backup_website.go +++ b/backend/app/service/backup_website.go @@ -113,7 +113,7 @@ func handleWebsiteRecover(website *model.Website, recoverFile string, isRollback defer func() { if !isOk { global.LOG.Info("recover failed, start to rollback now") - if err := handleWebsiteRecover(website, rollbackFile, true, secret); err != nil { + if err := handleWebsiteRecover(website, rollbackFile, true, ""); err != nil { global.LOG.Errorf("rollback website %s from %s failed, err: %v", website.Alias, rollbackFile, err) return } diff --git a/backend/app/service/cronjob_helper.go b/backend/app/service/cronjob_helper.go index 03435b4df..1d0459073 100644 --- a/backend/app/service/cronjob_helper.go +++ b/backend/app/service/cronjob_helper.go @@ -191,7 +191,7 @@ func handleUnTar(sourceFile, targetDir string, secret string) error { extraCmd := "openssl enc -d -aes-256-cbc -k " + secret + " -in " + sourceFile + " | " commands = fmt.Sprintf("%s tar -zxvf - -C %s", extraCmd, targetDir+" > /dev/null 2>&1") } else { - commands = fmt.Sprintf("tar -zxvf %s %s", sourceFile+" -C ", targetDir+" > /dev/null 2>&1") + commands = fmt.Sprintf("tar zxvfC %s %s", sourceFile, targetDir) } if len(secret) != 0 { global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******")) diff --git a/backend/app/service/snapshot.go b/backend/app/service/snapshot.go index 48ea41637..afdb8978b 100644 --- a/backend/app/service/snapshot.go +++ b/backend/app/service/snapshot.go @@ -396,7 +396,7 @@ func (u *SnapshotService) handleUnTar(sourceDir, targetDir string, secret string extraCmd := "openssl enc -d -aes-256-cbc -k " + secret + " -in " + sourceDir + " | " commands = fmt.Sprintf("%s tar -zxvf - -C %s", extraCmd, targetDir+" > /dev/null 2>&1") } else { - commands = fmt.Sprintf("tar -zxvf %s %s", sourceDir+" -C ", targetDir+" > /dev/null 2>&1") + commands = fmt.Sprintf("tar zxvfC %s %s", sourceDir, targetDir) } if len(secret) != 0 { global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******")) diff --git a/backend/utils/postgresql/client/local.go b/backend/utils/postgresql/client/local.go index 1e0e15f6b..91e7cb699 100644 --- a/backend/utils/postgresql/client/local.go +++ b/backend/utils/postgresql/client/local.go @@ -1,6 +1,7 @@ package client import ( + "bytes" "compress/gzip" "context" "errors" @@ -136,11 +137,17 @@ func (r *Local) Backup(info BackupInfo) error { 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) + var stderr bytes.Buffer + cmd.Stderr = &stderr + gzipCmd := exec.Command("gzip", "-cf") gzipCmd.Stdin, _ = cmd.StdoutPipe() gzipCmd.Stdout = outfile _ = gzipCmd.Start() - _ = cmd.Run() + + if err := cmd.Run(); err != nil { + return fmt.Errorf("handle backup database failed, err: %v", stderr.String()) + } _ = gzipCmd.Wait() return nil } diff --git a/frontend/src/views/setting/snapshot/index.vue b/frontend/src/views/setting/snapshot/index.vue index f511e21ed..09e77d56b 100644 --- a/frontend/src/views/setting/snapshot/index.vue +++ b/frontend/src/views/setting/snapshot/index.vue @@ -382,6 +382,7 @@ const search = async () => { pageSize: paginationConfig.pageSize, }; const res = await searchSnapshotPage(params); + cleanData.value = false; data.value = res.data.items || []; paginationConfig.total = res.data.total; };