mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-08 14:37:29 +08:00
fix: Fix the problem of snapshot synchronization failure (#8559)
This commit is contained in:
parent
74708dfa7a
commit
7534b680a7
3 changed files with 14 additions and 2 deletions
|
@ -124,7 +124,7 @@ func (u *BackupService) Create(req dto.BackupOperate) error {
|
||||||
if req.Type == constant.Local {
|
if req.Type == constant.Local {
|
||||||
return buserr.New("ErrBackupLocalCreate")
|
return buserr.New("ErrBackupLocalCreate")
|
||||||
}
|
}
|
||||||
if req.Type != constant.Sftp && req.BackupPath != "/" {
|
if req.Type != constant.Sftp {
|
||||||
req.BackupPath = strings.TrimPrefix(req.BackupPath, "/")
|
req.BackupPath = strings.TrimPrefix(req.BackupPath, "/")
|
||||||
}
|
}
|
||||||
backup, _ := backupRepo.Get(repo.WithByName(req.Name))
|
backup, _ := backupRepo.Get(repo.WithByName(req.Name))
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/agent/app/dto"
|
"github.com/1Panel-dev/1Panel/agent/app/dto"
|
||||||
|
@ -190,7 +191,14 @@ func (u *BackupRecordService) ListFiles(req dto.OperateByID) []string {
|
||||||
global.LOG.Debugf("load files failed, err: %v", err)
|
global.LOG.Debugf("load files failed, err: %v", err)
|
||||||
return []string{}
|
return []string{}
|
||||||
}
|
}
|
||||||
return files
|
var datas []string
|
||||||
|
for _, file := range files {
|
||||||
|
fileName := path.Base(file)
|
||||||
|
if len(file) != 0 && (strings.HasPrefix(fileName, "1panel-v2.") || strings.HasPrefix(fileName, "snapshot-1panel-v2.")) {
|
||||||
|
datas = append(datas, path.Base(file))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return datas
|
||||||
}
|
}
|
||||||
|
|
||||||
type backupSizeHelper struct {
|
type backupSizeHelper struct {
|
||||||
|
|
|
@ -65,7 +65,11 @@ func (u *SnapshotService) SnapshotImport(req dto.SnapshotImport) error {
|
||||||
if len(req.Names) == 0 {
|
if len(req.Names) == 0 {
|
||||||
return fmt.Errorf("incorrect snapshot request body: %v", req.Names)
|
return fmt.Errorf("incorrect snapshot request body: %v", req.Names)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, snapName := range req.Names {
|
for _, snapName := range req.Names {
|
||||||
|
if !strings.HasPrefix(snapName, "1panel-v2.") && !strings.HasPrefix(snapName, "snapshot-1panel-v2.") {
|
||||||
|
return fmt.Errorf("incorrect snapshot name format of %s", snapName)
|
||||||
|
}
|
||||||
snap, _ := snapshotRepo.Get(repo.WithByName(strings.ReplaceAll(snapName, ".tar.gz", "")))
|
snap, _ := snapshotRepo.Get(repo.WithByName(strings.ReplaceAll(snapName, ".tar.gz", "")))
|
||||||
if snap.ID != 0 {
|
if snap.ID != 0 {
|
||||||
return buserr.New("ErrRecordExist")
|
return buserr.New("ErrRecordExist")
|
||||||
|
|
Loading…
Add table
Reference in a new issue