mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-02-07 17:10:07 +08:00
parent
903f8ed5a7
commit
a3e4847744
@ -120,6 +120,28 @@ func (b *BaseApi) SearchSnapshot(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Tags System Setting
|
||||||
|
// @Summary Load system snapshot size
|
||||||
|
// @Description 获取系统快照大小
|
||||||
|
// @Accept json
|
||||||
|
// @Param request body dto.PageSnapshot true "request"
|
||||||
|
// @Success 200
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @Router /settings/snapshot/size [post]
|
||||||
|
func (b *BaseApi) LoadSnapshotSize(c *gin.Context) {
|
||||||
|
var req dto.PageSnapshot
|
||||||
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := snapshotService.LoadSize(req)
|
||||||
|
if err != nil {
|
||||||
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
helper.SuccessWithData(c, data)
|
||||||
|
}
|
||||||
|
|
||||||
// @Tags System Setting
|
// @Tags System Setting
|
||||||
// @Summary Recover system backup
|
// @Summary Recover system backup
|
||||||
// @Description 从系统快照恢复
|
// @Description 从系统快照恢复
|
||||||
|
@ -149,7 +149,6 @@ type SnapshotInfo struct {
|
|||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Size int64 `json:"size"`
|
|
||||||
|
|
||||||
InterruptStep string `json:"interruptStep"`
|
InterruptStep string `json:"interruptStep"`
|
||||||
RecoverStatus string `json:"recoverStatus"`
|
RecoverStatus string `json:"recoverStatus"`
|
||||||
@ -160,6 +159,12 @@ type SnapshotInfo struct {
|
|||||||
LastRollbackedAt string `json:"lastRollbackedAt"`
|
LastRollbackedAt string `json:"lastRollbackedAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SnapshotFile struct {
|
||||||
|
ID uint `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
}
|
||||||
|
|
||||||
type UpgradeInfo struct {
|
type UpgradeInfo struct {
|
||||||
TestVersion string `json:"testVersion"`
|
TestVersion string `json:"testVersion"`
|
||||||
NewVersion string `json:"newVersion"`
|
NewVersion string `json:"newVersion"`
|
||||||
|
@ -28,6 +28,7 @@ type SnapshotService struct {
|
|||||||
|
|
||||||
type ISnapshotService interface {
|
type ISnapshotService interface {
|
||||||
SearchWithPage(req dto.PageSnapshot) (int64, interface{}, error)
|
SearchWithPage(req dto.PageSnapshot) (int64, interface{}, error)
|
||||||
|
LoadSize(req dto.PageSnapshot) ([]dto.SnapshotFile, error)
|
||||||
SnapshotCreate(req dto.SnapshotCreate) error
|
SnapshotCreate(req dto.SnapshotCreate) error
|
||||||
SnapshotRecover(req dto.SnapshotRecover) error
|
SnapshotRecover(req dto.SnapshotRecover) error
|
||||||
SnapshotRollback(req dto.SnapshotRecover) error
|
SnapshotRollback(req dto.SnapshotRecover) error
|
||||||
@ -47,15 +48,31 @@ func NewISnapshotService() ISnapshotService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *SnapshotService) SearchWithPage(req dto.PageSnapshot) (int64, interface{}, error) {
|
func (u *SnapshotService) SearchWithPage(req dto.PageSnapshot) (int64, interface{}, error) {
|
||||||
total, systemBackups, err := snapshotRepo.Page(req.Page, req.PageSize, commonRepo.WithLikeName(req.Info), commonRepo.WithOrderRuleBy(req.OrderBy, req.Order))
|
total, records, err := snapshotRepo.Page(req.Page, req.PageSize, commonRepo.WithLikeName(req.Info), commonRepo.WithOrderRuleBy(req.OrderBy, req.Order))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
dtoSnap, err := loadSnapSize(systemBackups)
|
var data []dto.SnapshotInfo
|
||||||
if err != nil {
|
for _, record := range records {
|
||||||
return 0, nil, err
|
var item dto.SnapshotInfo
|
||||||
|
if err := copier.Copy(&item, &record); err != nil {
|
||||||
|
return 0, nil, errors.WithMessage(constant.ErrStructTransform, err.Error())
|
||||||
}
|
}
|
||||||
return total, dtoSnap, err
|
data = append(data, item)
|
||||||
|
}
|
||||||
|
return total, data, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *SnapshotService) LoadSize(req dto.PageSnapshot) ([]dto.SnapshotFile, error) {
|
||||||
|
_, records, err := snapshotRepo.Page(req.Page, req.PageSize, commonRepo.WithLikeName(req.Info), commonRepo.WithOrderRuleBy(req.OrderBy, req.Order))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
data, err := loadSnapSize(records)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return data, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *SnapshotService) SnapshotImport(req dto.SnapshotImport) error {
|
func (u *SnapshotService) SnapshotImport(req dto.SnapshotImport) error {
|
||||||
@ -510,15 +527,12 @@ func loadOs() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadSnapSize(records []model.Snapshot) ([]dto.SnapshotInfo, error) {
|
func loadSnapSize(records []model.Snapshot) ([]dto.SnapshotFile, error) {
|
||||||
var datas []dto.SnapshotInfo
|
var datas []dto.SnapshotFile
|
||||||
clientMap := make(map[string]loadSizeHelper)
|
clientMap := make(map[string]loadSizeHelper)
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for i := 0; i < len(records); i++ {
|
for i := 0; i < len(records); i++ {
|
||||||
var item dto.SnapshotInfo
|
item := dto.SnapshotFile{Name: records[i].Name, ID: records[i].ID}
|
||||||
if err := copier.Copy(&item, &records[i]); err != nil {
|
|
||||||
return nil, errors.WithMessage(constant.ErrStructTransform, err.Error())
|
|
||||||
}
|
|
||||||
itemPath := fmt.Sprintf("system_snapshot/%s.tar.gz", item.Name)
|
itemPath := fmt.Sprintf("system_snapshot/%s.tar.gz", item.Name)
|
||||||
if _, ok := clientMap[records[i].DefaultDownload]; !ok {
|
if _, ok := clientMap[records[i].DefaultDownload]; !ok {
|
||||||
backup, err := backupRepo.Get(commonRepo.WithByType(records[i].DefaultDownload))
|
backup, err := backupRepo.Get(commonRepo.WithByType(records[i].DefaultDownload))
|
||||||
|
@ -37,6 +37,7 @@ func (s *SettingRouter) InitRouter(Router *gin.RouterGroup) {
|
|||||||
settingRouter.POST("/snapshot", baseApi.CreateSnapshot)
|
settingRouter.POST("/snapshot", baseApi.CreateSnapshot)
|
||||||
settingRouter.POST("/snapshot/status", baseApi.LoadSnapShotStatus)
|
settingRouter.POST("/snapshot/status", baseApi.LoadSnapShotStatus)
|
||||||
settingRouter.POST("/snapshot/search", baseApi.SearchSnapshot)
|
settingRouter.POST("/snapshot/search", baseApi.SearchSnapshot)
|
||||||
|
settingRouter.POST("/snapshot/size", baseApi.LoadSnapshotSize)
|
||||||
settingRouter.POST("/snapshot/import", baseApi.ImportSnapshot)
|
settingRouter.POST("/snapshot/import", baseApi.ImportSnapshot)
|
||||||
settingRouter.POST("/snapshot/del", baseApi.DeleteSnapshot)
|
settingRouter.POST("/snapshot/del", baseApi.DeleteSnapshot)
|
||||||
settingRouter.POST("/snapshot/recover", baseApi.RecoverSnapshot)
|
settingRouter.POST("/snapshot/recover", baseApi.RecoverSnapshot)
|
||||||
|
@ -145,6 +145,11 @@ export namespace Setting {
|
|||||||
lastRollbackedAt: string;
|
lastRollbackedAt: string;
|
||||||
secret: string;
|
secret: string;
|
||||||
}
|
}
|
||||||
|
export interface SnapshotFile {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
size: number;
|
||||||
|
}
|
||||||
export interface SnapshotStatus {
|
export interface SnapshotStatus {
|
||||||
panel: string;
|
panel: string;
|
||||||
panelInfo: string;
|
panelInfo: string;
|
||||||
|
@ -196,6 +196,9 @@ export const snapshotRollback = (param: Setting.SnapshotRecover) => {
|
|||||||
export const searchSnapshotPage = (param: SearchWithPage) => {
|
export const searchSnapshotPage = (param: SearchWithPage) => {
|
||||||
return http.post<ResPage<Setting.SnapshotInfo>>(`/settings/snapshot/search`, param);
|
return http.post<ResPage<Setting.SnapshotInfo>>(`/settings/snapshot/search`, param);
|
||||||
};
|
};
|
||||||
|
export const loadSnapshotSize = (param: SearchWithPage) => {
|
||||||
|
return http.post<Array<Setting.SnapshotFile>>(`/settings/snapshot/size`, param);
|
||||||
|
};
|
||||||
|
|
||||||
// upgrade
|
// upgrade
|
||||||
export const loadUpgradeInfo = () => {
|
export const loadUpgradeInfo = () => {
|
||||||
|
@ -75,10 +75,15 @@
|
|||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column :label="$t('file.size')" prop="size" min-width="60" show-overflow-tooltip>
|
<el-table-column :label="$t('file.size')" prop="size" min-width="60" show-overflow-tooltip>
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
|
<div v-if="row.hasLoad">
|
||||||
<span v-if="row.size">
|
<span v-if="row.size">
|
||||||
{{ computeSize(row.size) }}
|
{{ computeSize(row.size) }}
|
||||||
</span>
|
</span>
|
||||||
<span v-else>-</span>
|
<span v-else>-</span>
|
||||||
|
</div>
|
||||||
|
<div v-if="!row.hasLoad">
|
||||||
|
<el-button link loading></el-button>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column :label="$t('commons.table.status')" min-width="80" prop="status">
|
<el-table-column :label="$t('commons.table.status')" min-width="80" prop="status">
|
||||||
@ -197,7 +202,13 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import DrawerHeader from '@/components/drawer-header/index.vue';
|
import DrawerHeader from '@/components/drawer-header/index.vue';
|
||||||
import { snapshotCreate, searchSnapshotPage, snapshotDelete, updateSnapshotDescription } from '@/api/modules/setting';
|
import {
|
||||||
|
snapshotCreate,
|
||||||
|
searchSnapshotPage,
|
||||||
|
snapshotDelete,
|
||||||
|
updateSnapshotDescription,
|
||||||
|
loadSnapshotSize,
|
||||||
|
} from '@/api/modules/setting';
|
||||||
import { onMounted, reactive, ref } from 'vue';
|
import { onMounted, reactive, ref } from 'vue';
|
||||||
import { computeSize, dateFormat } from '@/utils/util';
|
import { computeSize, dateFormat } from '@/utils/util';
|
||||||
import { ElForm } from 'element-plus';
|
import { ElForm } from 'element-plus';
|
||||||
@ -418,6 +429,7 @@ const search = async (column?: any) => {
|
|||||||
await searchSnapshotPage(params)
|
await searchSnapshotPage(params)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
loadSize(params);
|
||||||
cleanData.value = false;
|
cleanData.value = false;
|
||||||
data.value = res.data.items || [];
|
data.value = res.data.items || [];
|
||||||
paginationConfig.total = res.data.total;
|
paginationConfig.total = res.data.total;
|
||||||
@ -427,6 +439,28 @@ const search = async (column?: any) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loadSize = async (params: any) => {
|
||||||
|
await loadSnapshotSize(params)
|
||||||
|
.then((res) => {
|
||||||
|
let stats = res.data || [];
|
||||||
|
if (stats.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const snap of data.value) {
|
||||||
|
for (const item of stats) {
|
||||||
|
if (snap.id === item.id) {
|
||||||
|
snap.hasLoad = true;
|
||||||
|
snap.size = item.size;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
search();
|
search();
|
||||||
loadBackups();
|
loadBackups();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user