From 74708dfa7afe9aafc7ae531614a2e47f35ea978e Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 6 May 2025 18:35:36 +0800 Subject: [PATCH] fix: Fix the problem of snapshot timeout (#8555) --- agent/app/service/snapshot_create.go | 2 +- agent/app/service/snapshot_recover.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/agent/app/service/snapshot_create.go b/agent/app/service/snapshot_create.go index c5095d27b..c290bed40 100644 --- a/agent/app/service/snapshot_create.go +++ b/agent/app/service/snapshot_create.go @@ -370,7 +370,7 @@ func snapAppImage(snap snapHelper, req dto.SnapshotCreate, targetDir string) err snap.Task.Log(strings.Join(imageList, " ")) if len(imageList) != 0 { snap.Task.Logf("docker save %s | gzip -c > %s", strings.Join(imageList, " "), path.Join(targetDir, "images.tar.gz")) - std, err := cmd.RunDefaultWithStdoutBashCf("docker save %s | gzip -c > %s", strings.Join(imageList, " "), path.Join(targetDir, "images.tar.gz")) + std, err := cmd.NewCommandMgr(cmd.WithTimeout(10*time.Minute)).RunWithStdoutBashCf("docker save %s | gzip -c > %s", strings.Join(imageList, " "), path.Join(targetDir, "images.tar.gz")) if err != nil { snap.Task.LogFailedWithErr(i18n.GetMsgByKey("SnapDockerSave"), errors.New(std)) return errors.New(std) diff --git a/agent/app/service/snapshot_recover.go b/agent/app/service/snapshot_recover.go index 4868afe58..d62144ab0 100644 --- a/agent/app/service/snapshot_recover.go +++ b/agent/app/service/snapshot_recover.go @@ -6,6 +6,7 @@ import ( "os" "path" "strings" + "time" "github.com/1Panel-dev/1Panel/agent/app/repo" @@ -314,7 +315,7 @@ func recoverAppData(src string, itemHelper *snapRecoverHelper) error { itemHelper.Task.Log(i18n.GetMsgByKey("RecoverAppEmpty")) return nil } - std, err := cmd.RunDefaultWithStdoutBashCf("docker load < %s", path.Join(src, "images.tar.gz")) + std, err := cmd.NewCommandMgr(cmd.WithTimeout(10*time.Minute)).RunWithStdoutBashCf("docker load < %s", path.Join(src, "images.tar.gz")) if err != nil { itemHelper.Task.LogFailedWithErr(i18n.GetMsgByKey("RecoverAppImage"), errors.New(std)) return fmt.Errorf("docker load images failed, err: %v", err)