mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-10 15:36:45 +08:00
fix: Fix the problem that the local backup account modification does not take effect (#8175)
This commit is contained in:
parent
9cd83cd5dc
commit
ba1d5bfbc0
2 changed files with 21 additions and 16 deletions
|
@ -244,6 +244,7 @@ func (u *BackupService) Update(req dto.BackupOperate) error {
|
||||||
if err := changeLocalBackup(backup.BackupPath, newBackup.BackupPath); err != nil {
|
if err := changeLocalBackup(backup.BackupPath, newBackup.BackupPath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
global.Dir.LocalBackupDir = newBackup.BackupPath
|
||||||
}
|
}
|
||||||
|
|
||||||
if newBackup.Type == constant.OneDrive || newBackup.Type == constant.GoogleDrive {
|
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 {
|
if err != nil || !isOk {
|
||||||
return buserr.WithMap("ErrBackupCheck", map[string]interface{}{"err": err.Error()}, err)
|
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.ID = backup.ID
|
||||||
newBackup.CreatedAt = backup.CreatedAt
|
newBackup.CreatedAt = backup.CreatedAt
|
||||||
newBackup.UpdatedAt = backup.UpdatedAt
|
newBackup.UpdatedAt = backup.UpdatedAt
|
||||||
|
@ -546,34 +547,40 @@ func loadBackupNamesByID(accountIDs string, downloadID uint) ([]string, string,
|
||||||
func changeLocalBackup(oldPath, newPath string) error {
|
func changeLocalBackup(oldPath, newPath string) error {
|
||||||
fileOp := files.NewFileOp()
|
fileOp := files.NewFileOp()
|
||||||
if fileOp.Stat(path.Join(oldPath, "app")) {
|
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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if fileOp.Stat(path.Join(oldPath, "database")) {
|
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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if fileOp.Stat(path.Join(oldPath, "directory")) {
|
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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if fileOp.Stat(path.Join(oldPath, "system_snapshot")) {
|
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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if fileOp.Stat(path.Join(oldPath, "website")) {
|
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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if fileOp.Stat(path.Join(oldPath, "log")) {
|
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
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -373,12 +373,10 @@ func loadBackupExcludes(snap snapHelper, req []dto.DataTree) []string {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(item.Path, path.Join(global.Dir.LocalBackupDir, "system_snapshot")) {
|
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 {
|
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)
|
snap.Task.LogWithStatus("delete snapshot from database", err)
|
||||||
}
|
}
|
||||||
} else {
|
} 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 {
|
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)
|
snap.Task.LogWithStatus("delete backup file from database", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue