From ebbfed711c9dcc0fc312390a9fea8d34a6cada64 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 12 Nov 2025 18:28:44 +0800 Subject: [PATCH] fix: Modify the service backup directory (#10930) --- agent/app/service/snapshot_create.go | 10 +++------- agent/app/service/snapshot_recover.go | 16 +++++++--------- agent/app/service/snapshot_rollback.go | 5 ++--- agent/app/service/tensorrt_llm.go | 3 +-- core/app/service/upgrade.go | 16 ++++------------ core/cmd/server/cmd/restore.go | 9 ++++----- .../src/views/setting/snapshot/create/index.vue | 13 ++----------- 7 files changed, 23 insertions(+), 49 deletions(-) diff --git a/agent/app/service/snapshot_create.go b/agent/app/service/snapshot_create.go index 5ca184900..e9af6cae7 100644 --- a/agent/app/service/snapshot_create.go +++ b/agent/app/service/snapshot_create.go @@ -286,10 +286,6 @@ func loadDbConn(snap *snapHelper, targetDir string, req dto.SnapshotCreate) erro func snapBaseData(snap snapHelper, targetDir string, withDockerConf bool) error { snap.Task.Log("---------------------- 2 / 8 ----------------------") snap.Task.LogStart(i18n.GetMsgByKey("SnapBaseInfo")) - svcScriptBakPath := path.Join(targetDir, "scriptbak") - if _, err := os.Stat(svcScriptBakPath); err != nil { - _ = os.MkdirAll(svcScriptBakPath, os.ModePerm) - } if global.IsMaster { err := snap.FileOp.CopyFile("/usr/local/bin/1panel-core", targetDir) @@ -312,21 +308,21 @@ func snapBaseData(snap snapHelper, targetDir string, withDockerConf bool) error if global.IsMaster { svcCorePath, _ := controller.GetServicePath("1panel-core") - err = snap.FileOp.CopyFile(svcCorePath, svcScriptBakPath) + err = snap.FileOp.CopyFile(svcCorePath, targetDir) snap.Task.LogWithStatus(i18n.GetWithName("SnapCopy", svcCorePath), err) if err != nil { return err } } svcAgentName, _ := controller.GetServicePath("1panel-agent") - err = snap.FileOp.CopyFile(svcAgentName, svcScriptBakPath) + err = snap.FileOp.CopyFile(svcAgentName, targetDir) snap.Task.LogWithStatus(i18n.GetWithName("SnapCopy", svcAgentName), err) if err != nil { return err } initScriptPath := path.Join(global.Dir.ResourceDir, "initscript") if _, err := os.Stat(initScriptPath); err == nil { - err = snap.FileOp.CopyDirWithNewName(initScriptPath, svcScriptBakPath, ".") + err = snap.FileOp.CopyDirWithNewName(initScriptPath, targetDir, ".") snap.Task.LogWithStatus(i18n.GetWithName("SnapCopy", initScriptPath), err) if err != nil { return err diff --git a/agent/app/service/snapshot_recover.go b/agent/app/service/snapshot_recover.go index 4a6f0a710..8cf4fb510 100644 --- a/agent/app/service/snapshot_recover.go +++ b/agent/app/service/snapshot_recover.go @@ -269,10 +269,9 @@ func backupBeforeRecover(name string, itemHelper *snapRecoverHelper) error { if _, err := os.Stat(baseDir); err != nil { _ = os.MkdirAll(baseDir, os.ModePerm) } - svcScriptBakPath := path.Join(baseDir, "scriptbak") initScriptPath := path.Join(global.Dir.ResourceDir, "initscript") if _, err := os.Stat(initScriptPath); err == nil { - err = itemHelper.FileOp.CopyDirWithNewName(initScriptPath, svcScriptBakPath, ".") + err = itemHelper.FileOp.CopyDirWithNewName(initScriptPath, baseDir, ".") itemHelper.Task.LogWithStatus(i18n.GetWithName("SnapCopy", initScriptPath), err) if err != nil { return err @@ -313,7 +312,7 @@ func backupBeforeRecover(name string, itemHelper *snapRecoverHelper) error { return err } svcCorePath, _ := controller.GetServicePath("1panel-core") - err = itemHelper.FileOp.CopyFile(svcCorePath, svcScriptBakPath) + err = itemHelper.FileOp.CopyFile(svcCorePath, baseDir) itemHelper.Task.LogWithStatus(i18n.GetWithName("SnapCopy", svcCorePath), err) if err != nil { return err @@ -325,7 +324,7 @@ func backupBeforeRecover(name string, itemHelper *snapRecoverHelper) error { return err } svcAgentPath, _ := controller.GetServicePath("1panel-agent") - err = itemHelper.FileOp.CopyFile(svcAgentPath, svcScriptBakPath) + err = itemHelper.FileOp.CopyFile(svcAgentPath, baseDir) itemHelper.Task.LogWithStatus(i18n.GetWithName("SnapCopy", svcAgentPath), err) if err != nil { return err @@ -383,7 +382,6 @@ func recoverAppData(src string, itemHelper *snapRecoverHelper) error { func recoverBaseData(src string, itemHelper *snapRecoverHelper) error { itemHelper.Task.Log("---------------------- 6 / 11 ----------------------") itemHelper.Task.LogStart(i18n.GetMsgByKey("SnapBaseInfo")) - svcScriptBakPath := path.Join(src, "scriptbak") if global.IsMaster { err := itemHelper.FileOp.CopyFile(path.Join(src, "1pctl"), "/usr/local/bin") itemHelper.Task.LogWithStatus(i18n.GetWithName("SnapCopy", "/usr/local/bin/1pctl"), err) @@ -396,10 +394,10 @@ func recoverBaseData(src string, itemHelper *snapRecoverHelper) error { return err } svcCoreName, _ := controller.LoadServiceName("1panel-core") - err = itemHelper.FileOp.CopyFile(path.Join(svcScriptBakPath, svcCoreName), svcBasePath) + err = itemHelper.FileOp.CopyFile(path.Join(src, svcCoreName), svcBasePath) itemHelper.Task.LogWithStatus(i18n.GetWithName("SnapCopy", path.Join(svcBasePath, svcCoreName)), err) if err != nil { - err = itemHelper.FileOp.CopyFile(path.Join(svcScriptBakPath, selCoreName), path.Join(svcBasePath, scriptCoreName)) + err = itemHelper.FileOp.CopyFile(path.Join(src, selCoreName), path.Join(svcBasePath, scriptCoreName)) itemHelper.Task.LogWithStatus(i18n.GetWithName("SnapCopy", path.Join(svcBasePath, scriptCoreName)), err) if err != nil { return err @@ -412,10 +410,10 @@ func recoverBaseData(src string, itemHelper *snapRecoverHelper) error { return err } svcAgentName, _ := controller.LoadServiceName("1panel-agent") - err = itemHelper.FileOp.CopyFile(path.Join(svcScriptBakPath, svcAgentName), svcBasePath) + err = itemHelper.FileOp.CopyFile(path.Join(src, svcAgentName), svcBasePath) itemHelper.Task.LogWithStatus(i18n.GetWithName("SnapCopy", path.Join(svcBasePath, svcAgentName)), err) if err != nil { - err = itemHelper.FileOp.CopyFile(path.Join(svcScriptBakPath, selAgentName), path.Join(svcBasePath, scriptAgentName)) + err = itemHelper.FileOp.CopyFile(path.Join(src, selAgentName), path.Join(svcBasePath, scriptAgentName)) itemHelper.Task.LogWithStatus(i18n.GetWithName("SnapCopy", path.Join(svcBasePath, scriptAgentName)), err) if err != nil { return err diff --git a/agent/app/service/snapshot_rollback.go b/agent/app/service/snapshot_rollback.go index f1c20e423..ac24f36be 100644 --- a/agent/app/service/snapshot_rollback.go +++ b/agent/app/service/snapshot_rollback.go @@ -34,7 +34,6 @@ func (u *SnapshotService) SnapshotRollback(req dto.SnapshotRecover) error { go func() { rootDir := fmt.Sprintf("%s/1panel_original/original_%s", global.Dir.BaseDir, snap.Name) baseDir := path.Join(rootDir, "base") - svcScriptBakPath := path.Join(baseDir, "scriptbak") FileOp := files.NewFileOp() taskItem.AddSubTask( @@ -64,7 +63,7 @@ func (u *SnapshotService) SnapshotRollback(req dto.SnapshotRecover) error { taskItem.AddSubTask( i18n.GetWithName("SnapCopy", path.Join(svcBasePath, svcCoreName)), func(t *task.Task) error { - return FileOp.CopyFile(path.Join(svcScriptBakPath, svcCoreName), svcBasePath) + return FileOp.CopyFile(path.Join(baseDir, svcCoreName), svcBasePath) }, nil, ) @@ -72,7 +71,7 @@ func (u *SnapshotService) SnapshotRollback(req dto.SnapshotRecover) error { taskItem.AddSubTask( i18n.GetWithName("SnapCopy", path.Join(svcBasePath, svcAgentName)), func(t *task.Task) error { - return FileOp.CopyFile(path.Join(svcScriptBakPath, svcAgentName), svcBasePath) + return FileOp.CopyFile(path.Join(baseDir, svcAgentName), svcBasePath) }, nil, ) diff --git a/agent/app/service/tensorrt_llm.go b/agent/app/service/tensorrt_llm.go index 305937e28..703d6526e 100644 --- a/agent/app/service/tensorrt_llm.go +++ b/agent/app/service/tensorrt_llm.go @@ -1,7 +1,6 @@ package service import ( - "errors" "fmt" "os" "path" @@ -418,7 +417,7 @@ func findModelArchive(modelType string) (string, error) { } } - return "", errors.New(fmt.Sprintf("no FusionXplay_%s_Accelerator*.tar.gz found in /home/models", modelType)) + return "", fmt.Errorf("no FusionXplay_%s_Accelerator*.tar.gz found in /home/models", modelType) } func handleModelArchive(modelType string, modelDir string) error { diff --git a/core/app/service/upgrade.go b/core/app/service/upgrade.go index d3bb6bedb..42860a1b8 100644 --- a/core/app/service/upgrade.go +++ b/core/app/service/upgrade.go @@ -295,10 +295,6 @@ func analyzeDoc(version, content string) dto.ReleasesNotes { } func (u *UpgradeService) handleBackup(originalDir string) error { - svcScriptBakPath := path.Join(originalDir, "scriptbak") - if _, err := os.Stat(svcScriptBakPath); err != nil { - _ = os.MkdirAll(svcScriptBakPath, os.ModePerm) - } if err := files.CopyItem(false, true, "/usr/local/bin/1panel-core", originalDir); err != nil { return err } @@ -311,10 +307,10 @@ func (u *UpgradeService) handleBackup(originalDir string) error { if err := files.CopyItem(true, true, "/usr/local/bin/lang", originalDir); err != nil { return err } - if err := files.CopyItem(false, true, path.Join(svcBasePath, svcCoreName), svcScriptBakPath); err != nil { + if err := files.CopyItem(false, true, path.Join(svcBasePath, svcCoreName), originalDir); err != nil { return err } - if err := files.CopyItem(false, true, path.Join(svcBasePath, svcAgentName), svcScriptBakPath); err != nil { + if err := files.CopyItem(false, true, path.Join(svcBasePath, svcAgentName), originalDir); err != nil { return err } if err := files.CopyItem(true, true, path.Join(global.CONF.Base.InstallDir, "1panel/db"), originalDir); err != nil { @@ -328,10 +324,6 @@ func (u *UpgradeService) handleBackup(originalDir string) error { func (u *UpgradeService) handleRollback(originalDir string, errStep int) { _ = settingRepo.Update("SystemStatus", "Free") - svcScriptBakPath := path.Join(originalDir, "scriptbak") - if _, err := os.Stat(svcScriptBakPath); err != nil { - _ = os.MkdirAll(svcScriptBakPath, os.ModePerm) - } dbPath := path.Join(global.CONF.Base.InstallDir, "1panel") if _, err := os.Stat(path.Join(originalDir, "db")); err == nil { if err := files.CopyItem(true, true, path.Join(originalDir, "db"), dbPath); err != nil { @@ -353,10 +345,10 @@ func (u *UpgradeService) handleRollback(originalDir string, errStep int) { if errStep == 2 { return } - if err := files.CopyItem(false, true, path.Join(svcScriptBakPath, svcCoreName), svcBasePath); err != nil { + if err := files.CopyItem(false, true, path.Join(originalDir, svcCoreName), svcBasePath); err != nil { global.LOG.Errorf("rollback %s failed, err: %v", svcCoreName, err) } - if err := files.CopyItem(false, true, path.Join(svcScriptBakPath, svcAgentName), svcBasePath); err != nil { + if err := files.CopyItem(false, true, path.Join(originalDir, svcAgentName), svcBasePath); err != nil { global.LOG.Errorf("rollback %s failed, err: %v", svcAgentName, err) } if errStep == 3 { diff --git a/core/cmd/server/cmd/restore.go b/core/cmd/server/cmd/restore.go index 7de724b56..71a476720 100644 --- a/core/cmd/server/cmd/restore.go +++ b/core/cmd/server/cmd/restore.go @@ -79,14 +79,13 @@ var restoreCmd = &cobra.Command{ svcAgentName, _ := controller.LoadServiceName("1panel-agent") selAgentName, _ := controller.SelectInitScript("1panel-agent") scriptAgentName, _ := controller.GetScriptName("1panel-agent") - svcScriptBakPath := path.Join(tmpPath, "scriptbak") - if err := files.CopyItem(false, true, path.Join(svcScriptBakPath, svcCoreName), svcBasePath); err != nil { - if err := files.CopyItem(false, true, path.Join(svcScriptBakPath, selCoreName), path.Join(svcBasePath, scriptCoreName)); err != nil { + if err := files.CopyItem(false, true, path.Join(tmpPath, svcCoreName), svcBasePath); err != nil { + if err := files.CopyItem(false, true, path.Join(tmpPath, selCoreName), path.Join(svcBasePath, scriptCoreName)); err != nil { return err } } - if err := files.CopyItem(false, true, path.Join(svcScriptBakPath, svcAgentName), svcBasePath); err != nil { - if err := files.CopyItem(false, true, path.Join(svcScriptBakPath, selAgentName), path.Join(svcBasePath, scriptAgentName)); err != nil { + if err := files.CopyItem(false, true, path.Join(tmpPath, svcAgentName), svcBasePath); err != nil { + if err := files.CopyItem(false, true, path.Join(tmpPath, selAgentName), path.Join(svcBasePath, scriptAgentName)); err != nil { return err } } diff --git a/frontend/src/views/setting/snapshot/create/index.vue b/frontend/src/views/setting/snapshot/create/index.vue index 4e2582a02..4b4c73870 100644 --- a/frontend/src/views/setting/snapshot/create/index.vue +++ b/frontend/src/views/setting/snapshot/create/index.vue @@ -1,25 +1,17 @@