From ae9c6e8e618e8e4d0b617c6dafcf0885e35af3c1 Mon Sep 17 00:00:00 2001 From: ssongliu Date: Mon, 6 Feb 2023 15:34:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BF=AB=E7=85=A7=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/snapshot.go | 34 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/backend/app/service/snapshot.go b/backend/app/service/snapshot.go index 9bf4c597b..810477e9b 100644 --- a/backend/app/service/snapshot.go +++ b/backend/app/service/snapshot.go @@ -6,7 +6,6 @@ import ( "fmt" "io/ioutil" "os" - "os/exec" "path/filepath" "strings" "time" @@ -614,10 +613,10 @@ func (u *SnapshotService) handlePanelDatas(fileOp files.FileOp, operation string case "recover": exclusionRules := "" if strings.Contains(backupDir, target) { - exclusionRules += ("1Panel" + strings.ReplaceAll(backupDir, target, "") + ";") + exclusionRules += ("1panel" + strings.ReplaceAll(backupDir, target, "") + ";") } if strings.Contains(dockerDir, target) { - exclusionRules += ("1Panel" + strings.ReplaceAll(dockerDir, target, "") + ";") + exclusionRules += ("1panel" + strings.ReplaceAll(dockerDir, target, "") + ";") } if err := u.handleTar(target, fmt.Sprintf("%s/original", filepath.Join(source, "../")), "1panel_data.tar.gz", exclusionRules); err != nil { return fmt.Errorf("restore original panel data failed, err: %v", err) @@ -779,24 +778,22 @@ func (u *SnapshotService) handleTar(sourceDir, targetDir, name, exclusionRules s return err } } - exStr := []string{"--warning=no-file-changed"} - exStr = append(exStr, "-zcf") - exStr = append(exStr, targetDir+"/"+name) + + exStr := "" excludes := strings.Split(exclusionRules, ";") for _, exclude := range excludes { if len(exclude) == 0 { continue } - exStr = append(exStr, "--exclude") - exStr = append(exStr, exclude) + exStr += " --exclude " + exStr += exclude } - exStr = append(exStr, "-C") - exStr = append(exStr, sourceDir) - exStr = append(exStr, ".") - cmd := exec.Command("tar", exStr...) - stdout, err := cmd.CombinedOutput() + + ss := fmt.Sprintf("tar zcf %s %s -C %s .", targetDir+"/"+name, exStr, sourceDir) + fmt.Println(ss) + stdout, err := cmd.Exec(ss) if err != nil { - return errors.New(string(stdout)) + return errors.New(stdout) } return nil } @@ -807,14 +804,7 @@ func (u *SnapshotService) handleUnTar(sourceDir, targetDir string) error { return err } } - exStr := []string{} - exStr = append(exStr, "zxf") - exStr = append(exStr, sourceDir) - exStr = append(exStr, "-C") - exStr = append(exStr, targetDir) - exStr = append(exStr, ".") - cmd := exec.Command("tar", exStr...) - stdout, err := cmd.CombinedOutput() + stdout, err := cmd.Exec(fmt.Sprintf("tar zxf %s -C %s .", sourceDir, targetDir)) if err != nil { return errors.New(string(stdout)) }