diff --git a/backend/app/service/backup.go b/backend/app/service/backup.go index 8a8b677a9..934634b13 100644 --- a/backend/app/service/backup.go +++ b/backend/app/service/backup.go @@ -86,34 +86,11 @@ func (u *BackupService) SearchRecordsWithPage(search dto.RecordSearch) (int64, [ commonRepo.WithByType(search.Type), backupRepo.WithByDetailName(search.DetailName), ) - - var datas []dto.BackupRecords - clientMap := make(map[string]loadSizeHelper) - for i := 0; i < len(records); i++ { - var item dto.BackupRecords - if err := copier.Copy(&item, &records[i]); err != nil { - return 0, nil, errors.WithMessage(constant.ErrStructTransform, err.Error()) - } - itemPath := path.Join(records[i].FileDir, records[i].FileName) - if _, ok := clientMap[records[i].Source]; !ok { - backup, err := backupRepo.Get(commonRepo.WithByType(records[i].Source)) - if err != nil { - global.LOG.Errorf("load backup model %s from db failed, err: %v", records[i].Source, err) - return total, datas, err - } - client, err := u.NewClient(&backup) - if err != nil { - global.LOG.Errorf("load backup client %s from db failed, err: %v", records[i].Source, err) - return total, datas, err - } - item.Size, _ = client.Size(path.Join(strings.TrimLeft(backup.BackupPath, "/"), itemPath)) - datas = append(datas, item) - clientMap[records[i].Source] = loadSizeHelper{backupPath: strings.TrimLeft(backup.BackupPath, "/"), client: client} - continue - } - item.Size, _ = clientMap[records[i].Source].client.Size(path.Join(clientMap[records[i].Source].backupPath, itemPath)) - datas = append(datas, item) + if err != nil { + return 0, nil, err } + + datas, err := u.loadRecordSize(records) return total, datas, err } @@ -123,38 +100,16 @@ func (u *BackupService) SearchRecordsByCronjobWithPage(search dto.RecordSearchBy commonRepo.WithOrderBy("created_at desc"), backupRepo.WithByCronID(search.CronjobID), ) - - var datas []dto.BackupRecords - clientMap := make(map[string]loadSizeHelper) - for i := 0; i < len(records); i++ { - var item dto.BackupRecords - if err := copier.Copy(&item, &records[i]); err != nil { - return 0, nil, errors.WithMessage(constant.ErrStructTransform, err.Error()) - } - itemPath := path.Join(records[i].FileDir, records[i].FileName) - if _, ok := clientMap[records[i].Source]; !ok { - backup, err := backupRepo.Get(commonRepo.WithByType(records[i].Source)) - if err != nil { - global.LOG.Errorf("load backup model %s from db failed, err: %v", records[i].Source, err) - return total, datas, err - } - client, err := u.NewClient(&backup) - if err != nil { - global.LOG.Errorf("load backup client %s from db failed, err: %v", records[i].Source, err) - return total, datas, err - } - item.Size, _ = client.Size(path.Join(strings.TrimLeft(backup.BackupPath, "/"), itemPath)) - datas = append(datas, item) - clientMap[records[i].Source] = loadSizeHelper{backupPath: strings.TrimLeft(backup.BackupPath, "/"), client: client} - continue - } - item.Size, _ = clientMap[records[i].Source].client.Size(path.Join(clientMap[records[i].Source].backupPath, itemPath)) - datas = append(datas, item) + if err != nil { + return 0, nil, err } + + datas, err := u.loadRecordSize(records) return total, datas, err } type loadSizeHelper struct { + isOk bool backupPath string client cloud_storage.CloudStorageClient } @@ -479,6 +434,43 @@ func (u *BackupService) loadAccessToken(backup *model.BackupAccount) error { return nil } +func (u *BackupService) loadRecordSize(records []model.BackupRecord) ([]dto.BackupRecords, error) { + var datas []dto.BackupRecords + clientMap := make(map[string]loadSizeHelper) + 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 _, ok := clientMap[records[i].Source]; !ok { + backup, err := backupRepo.Get(commonRepo.WithByType(records[i].Source)) + if err != nil { + global.LOG.Errorf("load backup model %s from db failed, err: %v", records[i].Source, err) + clientMap[records[i].Source] = loadSizeHelper{} + datas = append(datas, item) + continue + } + client, err := u.NewClient(&backup) + if err != nil { + global.LOG.Errorf("load backup client %s from db failed, err: %v", records[i].Source, err) + clientMap[records[i].Source] = loadSizeHelper{} + datas = append(datas, item) + continue + } + item.Size, _ = client.Size(path.Join(strings.TrimLeft(backup.BackupPath, "/"), itemPath)) + datas = append(datas, item) + clientMap[records[i].Source] = loadSizeHelper{backupPath: strings.TrimLeft(backup.BackupPath, "/"), client: client, isOk: true} + continue + } + if clientMap[records[i].Source].isOk { + item.Size, _ = clientMap[records[i].Source].client.Size(path.Join(clientMap[records[i].Source].backupPath, itemPath)) + } + datas = append(datas, item) + } + return datas, nil +} + func loadLocalDir() (string, error) { backup, err := backupRepo.Get(commonRepo.WithByType("LOCAL")) if err != nil { diff --git a/backend/app/service/cronjob_helper.go b/backend/app/service/cronjob_helper.go index 1f6976803..1dae58797 100644 --- a/backend/app/service/cronjob_helper.go +++ b/backend/app/service/cronjob_helper.go @@ -290,9 +290,11 @@ func (u *CronjobService) uploadCronjobBackFile(cronjob model.Cronjob, accountMap cloudSrc := strings.TrimPrefix(file, global.CONF.System.TmpDir+"/") for _, account := range accounts { if len(account) != 0 { + global.LOG.Debugf("start upload file to %s, dir: %s", account, path.Join(accountMap[account].backupPath, cloudSrc)) if _, err := accountMap[account].client.Upload(file, path.Join(accountMap[account].backupPath, cloudSrc)); err != nil { return "", err } + global.LOG.Debugf("upload successful!") } } return cloudSrc, nil diff --git a/frontend/src/api/modules/setting.ts b/frontend/src/api/modules/setting.ts index efc1080f1..5ca748d93 100644 --- a/frontend/src/api/modules/setting.ts +++ b/frontend/src/api/modules/setting.ts @@ -94,10 +94,10 @@ export const deleteBackupRecord = (params: { ids: number[] }) => { return http.post(`/settings/backup/record/del`, params); }; export const searchBackupRecords = (params: Backup.SearchBackupRecord) => { - return http.post>(`/settings/backup/record/search`, params); + return http.post>(`/settings/backup/record/search`, params, TimeoutEnum.T_5M); }; export const searchBackupRecordsByCronjob = (params: Backup.SearchBackupRecordByCronjob) => { - return http.post>(`/settings/backup/record/search/bycronjob`, params); + return http.post>(`/settings/backup/record/search/bycronjob`, params, TimeoutEnum.T_5M); }; export const getBackupList = () => { diff --git a/frontend/src/components/backup/index.vue b/frontend/src/components/backup/index.vue index 175b8ea6b..edb1d016e 100644 --- a/frontend/src/components/backup/index.vue +++ b/frontend/src/components/backup/index.vue @@ -220,12 +220,18 @@ const buttons = [ }, { label: i18n.global.t('commons.button.recover'), + disabled: (row: any) => { + return row.size === 0; + }, click: (row: Backup.RecordInfo) => { onRecover(row); }, }, { label: i18n.global.t('commons.button.download'), + disabled: (row: any) => { + return row.size === 0; + }, click: (row: Backup.RecordInfo) => { onDownload(row); }, diff --git a/frontend/src/views/app-store/installed/index.vue b/frontend/src/views/app-store/installed/index.vue index 03e2a09cd..911aee7f7 100644 --- a/frontend/src/views/app-store/installed/index.vue +++ b/frontend/src/views/app-store/installed/index.vue @@ -69,10 +69,10 @@ diff --git a/frontend/src/views/cronjob/backup/index.vue b/frontend/src/views/cronjob/backup/index.vue index d4ad274b6..dfef0b475 100644 --- a/frontend/src/views/cronjob/backup/index.vue +++ b/frontend/src/views/cronjob/backup/index.vue @@ -121,6 +121,9 @@ const onDownload = async (row: Backup.RecordInfo) => { const buttons = [ { label: i18n.global.t('commons.button.download'), + disabled: (row: any) => { + return row.size === 0; + }, click: (row: Backup.RecordInfo) => { onDownload(row); },