From ba1d5bfbc0152d0541b960ebdabb0e24c9d4afa1 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 18 Mar 2025 11:12:06 +0800 Subject: [PATCH] fix: Fix the problem that the local backup account modification does not take effect (#8175) --- agent/app/service/backup.go | 35 +++++++++++++++++----------- agent/app/service/snapshot_create.go | 2 -- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/agent/app/service/backup.go b/agent/app/service/backup.go index 9657571e0..62364831f 100644 --- a/agent/app/service/backup.go +++ b/agent/app/service/backup.go @@ -244,6 +244,7 @@ func (u *BackupService) Update(req dto.BackupOperate) error { if err := changeLocalBackup(backup.BackupPath, newBackup.BackupPath); err != nil { return err } + global.Dir.LocalBackupDir = newBackup.BackupPath } if newBackup.Type == constant.OneDrive || newBackup.Type == constant.GoogleDrive { @@ -256,16 +257,16 @@ func (u *BackupService) Update(req dto.BackupOperate) error { if err != nil || !isOk { return buserr.WithMap("ErrBackupCheck", map[string]interface{}{"err": err.Error()}, err) } + newBackup.AccessKey, err = encrypt.StringEncrypt(newBackup.AccessKey) + if err != nil { + return err + } + newBackup.Credential, err = encrypt.StringEncrypt(newBackup.Credential) + if err != nil { + return err + } } - newBackup.AccessKey, err = encrypt.StringEncrypt(newBackup.AccessKey) - if err != nil { - return err - } - newBackup.Credential, err = encrypt.StringEncrypt(newBackup.Credential) - if err != nil { - return err - } newBackup.ID = backup.ID newBackup.CreatedAt = backup.CreatedAt newBackup.UpdatedAt = backup.UpdatedAt @@ -546,34 +547,40 @@ func loadBackupNamesByID(accountIDs string, downloadID uint) ([]string, string, func changeLocalBackup(oldPath, newPath string) error { fileOp := files.NewFileOp() if fileOp.Stat(path.Join(oldPath, "app")) { - if err := fileOp.Mv(path.Join(oldPath, "app"), newPath); err != nil { + if err := fileOp.CopyDir(path.Join(oldPath, "app"), newPath); err != nil { return err } } if fileOp.Stat(path.Join(oldPath, "database")) { - if err := fileOp.Mv(path.Join(oldPath, "database"), newPath); err != nil { + if err := fileOp.CopyDir(path.Join(oldPath, "database"), newPath); err != nil { return err } } if fileOp.Stat(path.Join(oldPath, "directory")) { - if err := fileOp.Mv(path.Join(oldPath, "directory"), newPath); err != nil { + if err := fileOp.CopyDir(path.Join(oldPath, "directory"), newPath); err != nil { return err } } if fileOp.Stat(path.Join(oldPath, "system_snapshot")) { - if err := fileOp.Mv(path.Join(oldPath, "system_snapshot"), newPath); err != nil { + if err := fileOp.CopyDir(path.Join(oldPath, "system_snapshot"), newPath); err != nil { return err } } if fileOp.Stat(path.Join(oldPath, "website")) { - if err := fileOp.Mv(path.Join(oldPath, "website"), newPath); err != nil { + if err := fileOp.CopyDir(path.Join(oldPath, "website"), newPath); err != nil { return err } } if fileOp.Stat(path.Join(oldPath, "log")) { - if err := fileOp.Mv(path.Join(oldPath, "log"), newPath); err != nil { + if err := fileOp.CopyDir(path.Join(oldPath, "log"), newPath); err != nil { return err } } + _ = fileOp.RmRf(path.Join(oldPath, "app")) + _ = fileOp.RmRf(path.Join(oldPath, "database")) + _ = fileOp.RmRf(path.Join(oldPath, "directory")) + _ = fileOp.RmRf(path.Join(oldPath, "system_snapshot")) + _ = fileOp.RmRf(path.Join(oldPath, "website")) + _ = fileOp.RmRf(path.Join(oldPath, "log")) return nil } diff --git a/agent/app/service/snapshot_create.go b/agent/app/service/snapshot_create.go index ac8115a23..bed7c77d3 100644 --- a/agent/app/service/snapshot_create.go +++ b/agent/app/service/snapshot_create.go @@ -373,12 +373,10 @@ func loadBackupExcludes(snap snapHelper, req []dto.DataTree) []string { continue } if strings.HasPrefix(item.Path, path.Join(global.Dir.LocalBackupDir, "system_snapshot")) { - fmt.Println(strings.TrimSuffix(item.Name, ".tar.gz")) if err := snap.snapAgentDB.Where("name = ? AND download_account_id = ?", strings.TrimSuffix(item.Name, ".tar.gz"), "1").Delete(&model.Snapshot{}).Error; err != nil { snap.Task.LogWithStatus("delete snapshot from database", err) } } else { - fmt.Println(strings.TrimPrefix(path.Dir(item.Path), global.Dir.LocalBackupDir+"/"), path.Base(item.Path)) if err := snap.snapAgentDB.Where("file_dir = ? AND file_name = ?", strings.TrimPrefix(path.Dir(item.Path), global.Dir.LocalBackupDir+"/"), path.Base(item.Path)).Delete(&model.BackupRecord{}).Error; err != nil { snap.Task.LogWithStatus("delete backup file from database", err) }