diff --git a/agent/app/api/v2/backup.go b/agent/app/api/v2/backup.go index 463283116855..e71a2b44ac47 100644 --- a/agent/app/api/v2/backup.go +++ b/agent/app/api/v2/backup.go @@ -205,6 +205,29 @@ func (b *BaseApi) GetLocalDir(c *gin.Context) { helper.SuccessWithData(c, dir) } +// @Tags Backup Account +// @Summary Page backup records +// @Description 获取备份记录列表分页 +// @Accept json +// @Param request body dto.SearchForSize true "request" +// @Success 200 {object} dto.RecordFileSize +// @Security ApiKeyAuth +// @Router /backups/record/size [post] +func (b *BaseApi) LoadBackupRecordSize(c *gin.Context) { + var req dto.SearchForSize + if err := helper.CheckBindAndValidate(&req, c); err != nil { + return + } + + list, err := backupRecordService.LoadRecordSize(req) + if err != nil { + helper.InternalServer(c, err) + return + } + + helper.SuccessWithData(c, list) +} + // @Tags Backup Account // @Summary Page backup records // @Description 获取备份记录列表分页 diff --git a/agent/app/api/v2/snapshot.go b/agent/app/api/v2/snapshot.go index f15d9a3a3968..e9a268b6cc9c 100644 --- a/agent/app/api/v2/snapshot.go +++ b/agent/app/api/v2/snapshot.go @@ -134,28 +134,6 @@ func (b *BaseApi) SearchSnapshot(c *gin.Context) { }) } -// @Tags System Setting -// @Summary Load system snapshot size -// @Description 获取系统快照文件大小 -// @Accept json -// @Param request body dto.SearchWithPage true "request" -// @Success 200 -// @Security ApiKeyAuth -// @Router /settings/snapshot/size [post] -func (b *BaseApi) LoadSnapshotSize(c *gin.Context) { - var req dto.SearchWithPage - if err := helper.CheckBindAndValidate(&req, c); err != nil { - return - } - - accounts, err := snapshotService.LoadSize(req) - if err != nil { - helper.InternalServer(c, err) - return - } - helper.SuccessWithData(c, accounts) -} - // @Tags System Setting // @Summary Recover system backup // @Description 从系统快照恢复 diff --git a/agent/app/dto/backup.go b/agent/app/dto/backup.go index daaf6adb6c61..b8ce3b23fb0f 100644 --- a/agent/app/dto/backup.go +++ b/agent/app/dto/backup.go @@ -92,7 +92,6 @@ type BackupRecords struct { DownloadAccountID uint `json:"downloadAccountID"` FileDir string `json:"fileDir"` FileName string `json:"fileName"` - Size int64 `json:"size"` } type DownloadRecord struct { @@ -100,3 +99,17 @@ type DownloadRecord struct { FileDir string `json:"fileDir" validate:"required"` FileName string `json:"fileName" validate:"required"` } + +type SearchForSize struct { + PageInfo + Type string `json:"type" validate:"required"` + Name string `json:"name"` + DetailName string `json:"detailName"` + Info string `json:"info"` + CronjobID uint `json:"cronjobID"` +} +type RecordFileSize struct { + ID uint `json:"id"` + Name string `json:"name"` + Size int64 `json:"size"` +} diff --git a/agent/app/dto/cronjob.go b/agent/app/dto/cronjob.go index 404a1bee766f..0265e5872e13 100644 --- a/agent/app/dto/cronjob.go +++ b/agent/app/dto/cronjob.go @@ -106,17 +106,17 @@ type CronjobInfo struct { ContainerName string `json:"containerName"` User string `json:"user"` - AppID string `json:"appID"` - Website string `json:"website"` - ExclusionRules string `json:"exclusionRules"` - DBType string `json:"dbType"` - DBName string `json:"dbName"` - URL string `json:"url"` - IsDir bool `json:"isDir"` - SourceDir string `json:"sourceDir"` - SourceAccountIDs string `json:"sourceAccountIDs"` - DownloadAccountID uint `json:"downloadAccountID"` - RetainCopies int `json:"retainCopies"` + AppID string `json:"appID"` + Website string `json:"website"` + ExclusionRules string `json:"exclusionRules"` + DBType string `json:"dbType"` + DBName string `json:"dbName"` + URL string `json:"url"` + IsDir bool `json:"isDir"` + SourceDir string `json:"sourceDir"` + SourceAccounts []string `json:"sourceAccounts"` + DownloadAccount string `json:"downloadAccount"` + RetainCopies int `json:"retainCopies"` LastRecordStatus string `json:"lastRecordStatus"` LastRecordTime string `json:"lastRecordTime"` diff --git a/agent/app/dto/snapshot.go b/agent/app/dto/snapshot.go index 9fe53e70dacc..d109c5c4ccc6 100644 --- a/agent/app/dto/snapshot.go +++ b/agent/app/dto/snapshot.go @@ -88,8 +88,8 @@ type SnapshotInfo struct { ID uint `json:"id"` Name string `json:"name"` Description string `json:"description" validate:"max=256"` - From string `json:"from"` - DefaultDownload string `json:"defaultDownload"` + SourceAccounts []string `json:"sourceAccounts"` + DownloadAccount string `json:"downloadAccount"` Status string `json:"status"` Message string `json:"message"` CreatedAt time.Time `json:"createdAt"` @@ -108,11 +108,3 @@ type SnapshotInfo struct { RollbackMessage string `json:"rollbackMessage"` LastRollbackedAt string `json:"lastRollbackedAt"` } - -type SnapshotFile struct { - ID uint `json:"id"` - Name string `json:"name"` - From string `json:"from"` - DefaultDownload string `json:"defaultDownload"` - Size int64 `json:"size"` -} diff --git a/agent/app/service/backup.go b/agent/app/service/backup.go index 7f1e3c586803..d8d10fe34a76 100644 --- a/agent/app/service/backup.go +++ b/agent/app/service/backup.go @@ -88,6 +88,9 @@ func (u *BackupService) SearchWithPage(req dto.SearchPageWithType) (int64, inter if err := copier.Copy(&item, &account); err != nil { global.LOG.Errorf("copy backup account to dto backup info failed, err: %v", err) } + if item.Type != constant.Sftp && item.Type != constant.Local { + item.BackupPath = path.Join("/", strings.TrimPrefix(item.BackupPath, "/")) + } if !item.RememberAuth { item.AccessKey = "" item.Credential = "" @@ -124,6 +127,9 @@ func (u *BackupService) Create(req dto.BackupOperate) error { if req.Type == constant.Local { return buserr.New(constant.ErrBackupLocalCreate) } + if req.Type != constant.Sftp && req.BackupPath != "/" { + req.BackupPath = strings.TrimPrefix(req.BackupPath, "/") + } backup, _ := backupRepo.Get(repo.WithByName(req.Name)) if backup.ID != 0 { return constant.ErrRecordExist @@ -215,6 +221,9 @@ func (u *BackupService) Update(req dto.BackupOperate) error { if backup.ID == 0 { return constant.ErrRecordNotFound } + if req.Type != constant.Sftp && req.Type != constant.Local && req.BackupPath != "/" { + req.BackupPath = strings.TrimPrefix(req.BackupPath, "/") + } var newBackup model.BackupAccount if err := copier.Copy(&newBackup, &req); err != nil { return errors.WithMessage(constant.ErrStructTransform, err.Error()) @@ -428,14 +437,10 @@ func NewBackupClientMap(ids []string) (map[string]backupClientHelper, error) { if err != nil { return nil, err } - pathItem := item.BackupPath - if item.Type != constant.Sftp && item.Type != constant.Local && pathItem != "/" { - pathItem = strings.TrimPrefix(item.BackupPath, "/") - } clientMap[fmt.Sprintf("%v", item.ID)] = backupClientHelper{ client: backClient, name: item.Name, - backupPath: pathItem, + backupPath: item.BackupPath, accountType: item.Type, id: item.ID, } @@ -502,3 +507,28 @@ func loadRefreshTokenByCode(backup *model.BackupAccount) error { backup.Vars = string(itemVars) return nil } + +func loadBackupNamesByID(accountIDs string, downloadID uint) ([]string, string, error) { + accountIDList := strings.Split(accountIDs, ",") + var ids []uint + for _, item := range accountIDList { + if len(item) != 0 { + itemID, _ := strconv.Atoi(item) + ids = append(ids, uint(itemID)) + } + } + list, err := backupRepo.List(repo.WithByIDs(ids)) + if err != nil { + return nil, "", err + } + var accounts []string + var downloadAccount string + for _, item := range list { + itemName := fmt.Sprintf("%s - %s", item.Type, item.Name) + accounts = append(accounts, itemName) + if item.ID == downloadID { + downloadAccount = itemName + } + } + return accounts, downloadAccount, nil +} diff --git a/agent/app/service/backup_record.go b/agent/app/service/backup_record.go index bbe48efaae87..18bca392e980 100644 --- a/agent/app/service/backup_record.go +++ b/agent/app/service/backup_record.go @@ -5,8 +5,6 @@ import ( "fmt" "os" "path" - "sort" - "strings" "sync" "github.com/1Panel-dev/1Panel/agent/app/dto" @@ -14,9 +12,7 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/repo" "github.com/1Panel-dev/1Panel/agent/constant" "github.com/1Panel-dev/1Panel/agent/global" - "github.com/1Panel-dev/1Panel/agent/utils/cloud_storage" "github.com/jinzhu/copier" - "github.com/pkg/errors" ) type BackupRecordService struct{} @@ -30,6 +26,7 @@ type IBackupRecordService interface { ListAppRecords(name, detailName, fileName string) ([]model.BackupRecord, error) ListFiles(req dto.OperateByID) []string + LoadRecordSize(req dto.SearchForSize) ([]dto.RecordFileSize, error) } func NewIBackupRecordService() IBackupRecordService { @@ -47,15 +44,15 @@ func (u *BackupRecordService) SearchRecordsWithPage(search dto.RecordSearch) (in if err != nil { return 0, nil, err } - - if total == 0 { - return 0, nil, nil + var data []dto.BackupRecords + for _, account := range records { + var item dto.BackupRecords + if err := copier.Copy(&item, &account); err != nil { + global.LOG.Errorf("copy backup account to dto backup info failed, err: %v", err) + } + data = append(data, item) } - datas, err := u.loadRecordSize(records) - sort.Slice(datas, func(i, j int) bool { - return datas[i].CreatedAt.After(datas[j].CreatedAt) - }) - return total, datas, err + return total, data, err } func (u *BackupRecordService) SearchRecordsByCronjobWithPage(search dto.RecordSearchByCronjob) (int64, []dto.BackupRecords, error) { @@ -67,15 +64,15 @@ func (u *BackupRecordService) SearchRecordsByCronjobWithPage(search dto.RecordSe if err != nil { return 0, nil, err } - - if total == 0 { - return 0, nil, nil + var data []dto.BackupRecords + for _, account := range records { + var item dto.BackupRecords + if err := copier.Copy(&item, &account); err != nil { + global.LOG.Errorf("copy backup account to dto backup info failed, err: %v", err) + } + data = append(data, item) } - datas, err := u.loadRecordSize(records) - sort.Slice(datas, func(i, j int) bool { - return datas[i].CreatedAt.After(datas[j].CreatedAt) - }) - return total, datas, err + return total, data, err } func (u *BackupRecordService) DownloadRecord(info dto.DownloadRecord) (string, error) { @@ -94,7 +91,7 @@ func (u *BackupRecordService) DownloadRecord(info dto.DownloadRecord) (string, e } srcPath := fmt.Sprintf("%s/%s", info.FileDir, info.FileName) if len(account.BackupPath) != 0 { - srcPath = path.Join(strings.TrimPrefix(account.BackupPath, "/"), srcPath) + srcPath = path.Join(account.BackupPath, srcPath) } if exist, _ := client.Exist(srcPath); exist { isOK, err := client.Download(srcPath, targetPath) @@ -181,13 +178,52 @@ func (u *BackupRecordService) ListFiles(req dto.OperateByID) []string { return datas } -func (u *BackupRecordService) loadRecordSize(records []model.BackupRecord) ([]dto.BackupRecords, error) { +type backupSizeHelper struct { + ID uint `json:"id"` + DownloadID uint `json:"downloadID"` + FilePath string `json:"filePath"` + Size uint `json:"size"` +} + +func (u *BackupRecordService) LoadRecordSize(req dto.SearchForSize) ([]dto.RecordFileSize, error) { + var list []backupSizeHelper + switch req.Type { + case "snapshot": + _, records, err := snapshotRepo.Page(req.Page, req.PageSize, repo.WithByLikeName(req.Info)) + if err != nil { + return nil, err + } + for _, item := range records { + list = append(list, backupSizeHelper{ID: item.ID, DownloadID: item.DownloadAccountID, FilePath: fmt.Sprintf("system_snapshot/%s.tar.gz", item.Name)}) + } + case "cronjob": + _, records, err := backupRepo.PageRecord(req.Page, req.PageSize, backupRepo.WithByCronID(req.CronjobID)) + if err != nil { + return nil, err + } + for _, item := range records { + list = append(list, backupSizeHelper{ID: item.ID, DownloadID: item.DownloadAccountID, FilePath: path.Join(item.FileDir, item.FileName)}) + } + default: + _, records, err := backupRepo.PageRecord( + req.Page, req.PageSize, + repo.WithByName(req.Name), + repo.WithByType(req.Type), + repo.WithByDetailName(req.DetailName), + ) + if err != nil { + return nil, err + } + for _, item := range records { + list = append(list, backupSizeHelper{ID: item.ID, DownloadID: item.DownloadAccountID, FilePath: path.Join(item.FileDir, item.FileName)}) + } + } recordMap := make(map[uint]struct{}) var recordIds []string - for _, record := range records { - if _, ok := recordMap[record.DownloadAccountID]; !ok { - recordMap[record.DownloadAccountID] = struct{}{} - recordIds = append(recordIds, fmt.Sprintf("%v", record.DownloadAccountID)) + for _, record := range list { + if _, ok := recordMap[record.DownloadID]; !ok { + recordMap[record.DownloadID] = struct{}{} + recordIds = append(recordIds, fmt.Sprintf("%v", record.DownloadID)) } } clientMap, err := NewBackupClientMap(recordIds) @@ -195,22 +231,14 @@ func (u *BackupRecordService) loadRecordSize(records []model.BackupRecord) ([]dt return nil, err } - var datas []dto.BackupRecords + var datas []dto.RecordFileSize var wg sync.WaitGroup - for i := 0; i < len(records); i++ { - var item dto.BackupRecords - if err := copier.Copy(&item, &records[i]); err != nil { - return nil, errors.WithMessage(constant.ErrStructTransform, err.Error()) - } - - itemPath := path.Join(records[i].FileDir, records[i].FileName) - if val, ok := clientMap[fmt.Sprintf("%v", records[i].DownloadAccountID)]; ok { - item.AccountName = val.name - item.AccountType = val.accountType - item.DownloadAccountID = val.id + for i := 0; i < len(list); i++ { + item := dto.RecordFileSize{ID: list[i].ID} + if val, ok := clientMap[fmt.Sprintf("%v", list[i].DownloadID)]; ok { wg.Add(1) go func(index int) { - item.Size, _ = val.client.Size(path.Join(strings.TrimLeft(val.backupPath, "/"), itemPath)) + item.Size, _ = val.client.Size(path.Join(val.backupPath, list[i].FilePath)) datas = append(datas, item) wg.Done() }(i) @@ -221,10 +249,3 @@ func (u *BackupRecordService) loadRecordSize(records []model.BackupRecord) ([]dt wg.Wait() return datas, nil } - -type loadSizeHelper struct { - isOk bool - backupName string - backupPath string - client cloud_storage.CloudStorageClient -} diff --git a/agent/app/service/container.go b/agent/app/service/container.go index 8dffcaac8623..39f3642a0c3a 100644 --- a/agent/app/service/container.go +++ b/agent/app/service/container.go @@ -6,8 +6,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/1Panel-dev/1Panel/agent/app/repo" - "github.com/gin-gonic/gin" "io" "net/http" "net/url" @@ -22,6 +20,9 @@ import ( "syscall" "time" + "github.com/1Panel-dev/1Panel/agent/app/repo" + "github.com/gin-gonic/gin" + "github.com/pkg/errors" "github.com/1Panel-dev/1Panel/agent/app/dto" diff --git a/agent/app/service/cronjob.go b/agent/app/service/cronjob.go index 408688daee7b..92967a5f5e60 100644 --- a/agent/app/service/cronjob.go +++ b/agent/app/service/cronjob.go @@ -3,13 +3,14 @@ package service import ( "bufio" "fmt" - "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "path" "strconv" "strings" "time" + "github.com/1Panel-dev/1Panel/agent/app/repo" + "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/model" "github.com/1Panel-dev/1Panel/agent/constant" @@ -56,6 +57,7 @@ func (u *CronjobService) SearchWithPage(search dto.PageCronjob) (int64, interfac } else { item.LastRecordTime = "-" } + item.SourceAccounts, item.DownloadAccount, _ = loadBackupNamesByID(cronjob.SourceAccountIDs, cronjob.DownloadAccountID) dtoCronjobs = append(dtoCronjobs, item) } return total, dtoCronjobs, err diff --git a/agent/app/service/snapshot.go b/agent/app/service/snapshot.go index 0e83454a5201..429a9ee3e084 100644 --- a/agent/app/service/snapshot.go +++ b/agent/app/service/snapshot.go @@ -5,9 +5,7 @@ import ( "fmt" "os" "path" - "strconv" "strings" - "sync" "github.com/1Panel-dev/1Panel/agent/app/repo" @@ -30,7 +28,6 @@ type SnapshotService struct { type ISnapshotService interface { SearchWithPage(req dto.PageSnapshot) (int64, interface{}, error) - LoadSize(req dto.SearchWithPage) ([]dto.SnapshotFile, error) LoadSnapshotData() (dto.SnapshotData, error) SnapshotCreate(req dto.SnapshotCreate, isCron bool) error SnapshotReCreate(id uint) error @@ -57,58 +54,12 @@ func (u *SnapshotService) SearchWithPage(req dto.PageSnapshot) (int64, interface if err := copier.Copy(&item, &records[i]); err != nil { return 0, nil, err } + item.SourceAccounts, item.DownloadAccount, _ = loadBackupNamesByID(records[i].SourceAccountIDs, records[i].DownloadAccountID) datas = append(datas, item) } return total, datas, err } -func (u *SnapshotService) LoadSize(req dto.SearchWithPage) ([]dto.SnapshotFile, error) { - _, records, err := snapshotRepo.Page(req.Page, req.PageSize, repo.WithByLikeName(req.Info)) - if err != nil { - return nil, err - } - var datas []dto.SnapshotFile - var wg sync.WaitGroup - clientMap := make(map[uint]loadSizeHelper) - for i := 0; i < len(records); i++ { - itemPath := fmt.Sprintf("system_snapshot/%s.tar.gz", records[i].Name) - data := dto.SnapshotFile{ID: records[i].ID, Name: records[i].Name} - accounts := strings.Split(records[i].SourceAccountIDs, ",") - var accountNames []string - for _, account := range accounts { - itemVal, _ := strconv.Atoi(account) - if _, ok := clientMap[uint(itemVal)]; !ok { - backup, client, err := NewBackupClientWithID(uint(itemVal)) - if err != nil { - global.LOG.Errorf("load backup client from db failed, err: %v", err) - clientMap[records[i].DownloadAccountID] = loadSizeHelper{} - continue - } - backupName := fmt.Sprintf("%s - %s", backup.Type, backup.Name) - clientMap[uint(itemVal)] = loadSizeHelper{backupPath: strings.TrimLeft(backup.BackupPath, "/"), client: client, isOk: true, backupName: backupName} - accountNames = append(accountNames, backupName) - } else { - accountNames = append(accountNames, clientMap[uint(itemVal)].backupName) - } - } - data.DefaultDownload = clientMap[records[i].DownloadAccountID].backupName - data.From = strings.Join(accountNames, ",") - if clientMap[records[i].DownloadAccountID].isOk { - wg.Add(1) - go func(index int) { - data.Size, _ = clientMap[records[index].DownloadAccountID].client.Size(path.Join(clientMap[records[index].DownloadAccountID].backupPath, itemPath)) - datas = append(datas, data) - wg.Done() - }(i) - } else { - datas = append(datas, data) - } - } - wg.Wait() - - return datas, nil -} - func (u *SnapshotService) SnapshotImport(req dto.SnapshotImport) error { if len(req.Names) == 0 { return fmt.Errorf("incorrect snapshot request body: %v", req.Names) diff --git a/agent/router/backup.go b/agent/router/backup.go index b03ed67d407b..b239c1e311c2 100644 --- a/agent/router/backup.go +++ b/agent/router/backup.go @@ -28,6 +28,7 @@ func (s *BackupRouter) InitRouter(Router *gin.RouterGroup) { backupRouter.POST("/recover/byupload", baseApi.RecoverByUpload) backupRouter.POST("/search/files", baseApi.LoadFilesFromBackup) backupRouter.POST("/record/search", baseApi.SearchBackupRecords) + backupRouter.POST("/record/size", baseApi.LoadBackupRecordSize) backupRouter.POST("/record/search/bycronjob", baseApi.SearchBackupRecordsByCronjob) backupRouter.POST("/record/download", baseApi.DownloadRecord) backupRouter.POST("/record/del", baseApi.DeleteBackupRecord) diff --git a/agent/router/ro_setting.go b/agent/router/ro_setting.go index baa2cf2700c7..4bcb657e5691 100644 --- a/agent/router/ro_setting.go +++ b/agent/router/ro_setting.go @@ -20,7 +20,6 @@ func (s *SettingRouter) InitRouter(Router *gin.RouterGroup) { settingRouter.POST("/snapshot", baseApi.CreateSnapshot) settingRouter.POST("/snapshot/recreate", baseApi.RecreateSnapshot) settingRouter.POST("/snapshot/search", baseApi.SearchSnapshot) - settingRouter.POST("/snapshot/size", baseApi.LoadSnapshotSize) settingRouter.POST("/snapshot/import", baseApi.ImportSnapshot) settingRouter.POST("/snapshot/del", baseApi.DeleteSnapshot) settingRouter.POST("/snapshot/recover", baseApi.RecoverSnapshot) diff --git a/agent/utils/cloud_storage/client/helper.go b/agent/utils/cloud_storage/client/helper.go index f354de79beb2..94523dbc603d 100644 --- a/agent/utils/cloud_storage/client/helper.go +++ b/agent/utils/cloud_storage/client/helper.go @@ -8,7 +8,7 @@ import ( func loadParamFromVars(key string, vars map[string]interface{}) string { if _, ok := vars[key]; !ok { - if key != "bucket" && key != "port" { + if key != "bucket" && key != "port" && key != "authMode" && key != "passPhrase" { global.LOG.Errorf("load param %s from vars failed, err: not exist!", key) } return "" diff --git a/core/app/service/backup.go b/core/app/service/backup.go index 636339e6dfa7..6083991ffb47 100644 --- a/core/app/service/backup.go +++ b/core/app/service/backup.go @@ -83,6 +83,9 @@ func (u *BackupService) Create(req dto.BackupOperate) error { if backup.ID != 0 { return constant.ErrRecordExist } + if req.Type != constant.Sftp && req.BackupPath != "/" { + req.BackupPath = strings.TrimPrefix(req.BackupPath, "/") + } if err := copier.Copy(&backup, &req); err != nil { return errors.WithMessage(constant.ErrStructTransform, err.Error()) } @@ -189,6 +192,9 @@ func (u *BackupService) Update(req dto.BackupOperate) error { if backup.Type == constant.Local { return buserr.New(constant.ErrBackupLocal) } + if req.Type != constant.Sftp && req.BackupPath != "/" { + req.BackupPath = strings.TrimPrefix(req.BackupPath, "/") + } var newBackup model.BackupAccount if err := copier.Copy(&newBackup, &req); err != nil { return errors.WithMessage(constant.ErrStructTransform, err.Error()) diff --git a/frontend/src/api/interface/backup.ts b/frontend/src/api/interface/backup.ts index 44cf52ab986c..a2af0a80d710 100644 --- a/frontend/src/api/interface/backup.ts +++ b/frontend/src/api/interface/backup.ts @@ -68,6 +68,17 @@ export namespace Backup { name: string; detailName: string; } + export interface SearchForSize extends ReqPage { + type: string; + name: string; + detailName: string; + info: string; + cronjobID: number; + } + export interface RecordFileSize extends ReqPage { + id: number; + size: number; + } export interface SearchBackupRecordByCronjob extends ReqPage { cronjobID: number; } diff --git a/frontend/src/api/interface/setting.ts b/frontend/src/api/interface/setting.ts index e07c263dc240..14d88129880e 100644 --- a/frontend/src/api/interface/setting.ts +++ b/frontend/src/api/interface/setting.ts @@ -165,13 +165,6 @@ export namespace Setting { rollbackStatus: string; rollbackMessage: string; } - export interface SnapshotFile { - id: number; - name: string; - from: string; - defaultDownload: string; - size: number; - } export interface SnapshotData { appData: Array; panelData: Array; diff --git a/frontend/src/api/modules/backup.ts b/frontend/src/api/modules/backup.ts index 0535b02449fc..60f1875d6d98 100644 --- a/frontend/src/api/modules/backup.ts +++ b/frontend/src/api/modules/backup.ts @@ -35,6 +35,9 @@ export const deleteBackupRecord = (params: { ids: number[] }) => { export const searchBackupRecords = (params: Backup.SearchBackupRecord) => { return http.post>(`/backups/record/search`, params, TimeoutEnum.T_5M); }; +export const loadRecordSize = (param: Backup.SearchForSize) => { + return http.post>(`/backups/record/size`, param); +}; export const searchBackupRecordsByCronjob = (params: Backup.SearchBackupRecordByCronjob) => { return http.post>(`/backups/record/search/bycronjob`, params, TimeoutEnum.T_5M); }; diff --git a/frontend/src/api/modules/setting.ts b/frontend/src/api/modules/setting.ts index 89a29cce9720..6d7b18d2b146 100644 --- a/frontend/src/api/modules/setting.ts +++ b/frontend/src/api/modules/setting.ts @@ -139,9 +139,6 @@ export const snapshotRollback = (param: Setting.SnapshotRecover) => { export const searchSnapshotPage = (param: SearchWithPage) => { return http.post>(`/settings/snapshot/search`, param); }; -export const loadSnapshotSize = (param: SearchWithPage) => { - return http.post>(`/settings/snapshot/size`, param); -}; // upgrade export const loadUpgradeInfo = () => { diff --git a/frontend/src/components/backup/index.vue b/frontend/src/components/backup/index.vue index 64fe839ee74c..b4484cdd6ee2 100644 --- a/frontend/src/components/backup/index.vue +++ b/frontend/src/components/backup/index.vue @@ -38,10 +38,15 @@ @@ -108,6 +113,7 @@ import { deleteBackupRecord, downloadBackupRecord, searchBackupRecords, + loadRecordSize, } from '@/api/modules/backup'; import i18n from '@/lang'; import { Backup } from '@/api/interface/backup'; @@ -188,6 +194,7 @@ const search = async () => { await searchBackupRecords(params) .then((res) => { loading.value = false; + loadSize(params); data.value = res.data.items || []; paginationConfig.total = res.data.total; }) @@ -196,6 +203,28 @@ const search = async () => { }); }; +const loadSize = async (params: any) => { + await loadRecordSize(params) + .then((res) => { + let stats = res.data || []; + if (stats.length === 0) { + return; + } + for (const backup of data.value) { + for (const item of stats) { + if (backup.id === item.id) { + backup.hasLoad = true; + backup.size = item.size; + break; + } + } + } + }) + .catch(() => { + loading.value = false; + }); +}; + const openTaskLog = (taskID: string) => { taskLogRef.value.openWithTaskID(taskID); }; diff --git a/frontend/src/views/cronjob/backup/index.vue b/frontend/src/views/cronjob/backup/index.vue index a450207fda26..3a6bc23c1745 100644 --- a/frontend/src/views/cronjob/backup/index.vue +++ b/frontend/src/views/cronjob/backup/index.vue @@ -17,10 +17,15 @@ @@ -51,7 +56,7 @@ import { reactive, ref } from 'vue'; import { computeSize, dateFormat, downloadFile } from '@/utils/util'; import i18n from '@/lang'; -import { downloadBackupRecord, searchBackupRecordsByCronjob } from '@/api/modules/backup'; +import { downloadBackupRecord, loadRecordSize, searchBackupRecordsByCronjob } from '@/api/modules/backup'; import { Backup } from '@/api/interface/backup'; import { MsgError } from '@/utils/message'; import { GlobalStore } from '@/store'; @@ -96,6 +101,7 @@ const search = async () => { await searchBackupRecordsByCronjob(params) .then((res) => { loading.value = false; + loadSize(params); data.value = res.data.items || []; paginationConfig.total = res.data.total; }) @@ -104,6 +110,29 @@ const search = async () => { }); }; +const loadSize = async (params: any) => { + params.type = 'cronjob'; + await loadRecordSize(params) + .then((res) => { + let stats = res.data || []; + if (stats.length === 0) { + return; + } + for (const backup of data.value) { + for (const item of stats) { + if (backup.id === item.id) { + backup.hasLoad = true; + backup.size = item.size; + break; + } + } + } + }) + .catch(() => { + loading.value = false; + }); +}; + const onDownload = async (row: Backup.RecordInfo) => { if (row.accountType === 'ALIYUN' && row.size < 100 * 1024 * 1024) { MsgError(i18n.global.t('setting.ALIYUNHelper')); diff --git a/frontend/src/views/setting/snapshot/index.vue b/frontend/src/views/setting/snapshot/index.vue index 05687bb7f5e0..7deca57b62e5 100644 --- a/frontend/src/views/setting/snapshot/index.vue +++ b/frontend/src/views/setting/snapshot/index.vue @@ -181,7 +181,6 @@