From 5851124dee2acf5397d93d2e432080d5790c3d49 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:45:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=A4=87=E4=BB=BD?= =?UTF-8?q?=E5=A5=97=E6=8E=A5=E5=AD=97=E5=BF=BD=E7=95=A5=E4=B8=8D=E5=AE=8C?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20(#6272)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/snapshot.go | 4 +- backend/app/dto/setting.go | 6 +++ backend/app/service/cronjob_helper.go | 11 ++++-- backend/app/service/snapshot.go | 6 +-- backend/app/service/snapshot_create.go | 11 ++++-- frontend/src/lang/modules/en.ts | 2 +- frontend/src/lang/modules/tw.ts | 2 +- frontend/src/lang/modules/zh.ts | 2 +- frontend/src/views/home/index.vue | 38 +++++++++---------- frontend/src/views/setting/snapshot/index.vue | 11 +++++- 10 files changed, 57 insertions(+), 36 deletions(-) diff --git a/backend/app/api/v1/snapshot.go b/backend/app/api/v1/snapshot.go index 3f79be8ac..a6dde9d8c 100644 --- a/backend/app/api/v1/snapshot.go +++ b/backend/app/api/v1/snapshot.go @@ -99,12 +99,12 @@ func (b *BaseApi) UpdateSnapDescription(c *gin.Context) { // @Summary Page system snapshot // @Description 获取系统快照列表分页 // @Accept json -// @Param request body dto.SearchWithPage true "request" +// @Param request body dto.PageSnapshot true "request" // @Success 200 {object} dto.PageResult // @Security ApiKeyAuth // @Router /settings/snapshot/search [post] func (b *BaseApi) SearchSnapshot(c *gin.Context) { - var req dto.SearchWithPage + var req dto.PageSnapshot if err := helper.CheckBindAndValidate(&req, c); err != nil { return } diff --git a/backend/app/dto/setting.go b/backend/app/dto/setting.go index 29f8b24a2..ed84c2c9f 100644 --- a/backend/app/dto/setting.go +++ b/backend/app/dto/setting.go @@ -98,6 +98,12 @@ type PortUpdate struct { ServerPort uint `json:"serverPort" validate:"required,number,max=65535,min=1"` } +type PageSnapshot struct { + PageInfo + Info string `json:"info"` + OrderBy string `json:"orderBy" validate:"required,oneof=name created_at"` + Order string `json:"order" validate:"required,oneof=null ascending descending"` +} type SnapshotStatus struct { Panel string `json:"panel"` PanelInfo string `json:"panelInfo"` diff --git a/backend/app/service/cronjob_helper.go b/backend/app/service/cronjob_helper.go index 3b2c63b37..e882bf16f 100644 --- a/backend/app/service/cronjob_helper.go +++ b/backend/app/service/cronjob_helper.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path" + pathUtils "path" "strings" "time" @@ -139,8 +140,6 @@ func handleTar(sourceDir, targetDir, name, exclusionRules string, secret string) excludes := strings.Split(exclusionRules, ",") excludeRules := "" - excludes = append(excludes, "*.sock") - excludes = append(excludes, "*.socket") for _, exclude := range excludes { if len(exclude) == 0 { continue @@ -163,10 +162,14 @@ func handleTar(sourceDir, targetDir, name, exclusionRules string, secret string) if len(secret) != 0 { extraCmd := "| openssl enc -aes-256-cbc -salt -k '" + secret + "' -out" - commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s %s %s", " -"+excludeRules, path, extraCmd, targetDir+"/"+name) + commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read --exclude-from=<(find %s -type s -print) -zcf %s %s %s %s", sourceDir, " -"+excludeRules, path, extraCmd, targetDir+"/"+name) global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******")) } else { - commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s %s", targetDir+"/"+name, excludeRules, path) + itemPrefix := pathUtils.Base(sourceDir) + if itemPrefix == "/" { + itemPrefix = "" + } + commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read --exclude-from=<(find %s -type s -printf '%s' | sed 's|^|%s/|') -zcf %s %s %s", sourceDir, "%P\n", itemPrefix, targetDir+"/"+name, excludeRules, path) global.LOG.Debug(commands) } stdout, err := cmd.ExecWithTimeOut(commands, 24*time.Hour) diff --git a/backend/app/service/snapshot.go b/backend/app/service/snapshot.go index 07f14bfdd..ae230d9d1 100644 --- a/backend/app/service/snapshot.go +++ b/backend/app/service/snapshot.go @@ -27,7 +27,7 @@ type SnapshotService struct { } type ISnapshotService interface { - SearchWithPage(req dto.SearchWithPage) (int64, interface{}, error) + SearchWithPage(req dto.PageSnapshot) (int64, interface{}, error) SnapshotCreate(req dto.SnapshotCreate) error SnapshotRecover(req dto.SnapshotRecover) error SnapshotRollback(req dto.SnapshotRecover) error @@ -46,8 +46,8 @@ func NewISnapshotService() ISnapshotService { return &SnapshotService{} } -func (u *SnapshotService) SearchWithPage(req dto.SearchWithPage) (int64, interface{}, error) { - total, systemBackups, err := snapshotRepo.Page(req.Page, req.PageSize, commonRepo.WithLikeName(req.Info)) +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)) if err != nil { return 0, nil, err } diff --git a/backend/app/service/snapshot_create.go b/backend/app/service/snapshot_create.go index 82d9763a0..705d4804e 100644 --- a/backend/app/service/snapshot_create.go +++ b/backend/app/service/snapshot_create.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "path" + pathUtils "path" "regexp" "strings" "sync" @@ -231,8 +232,6 @@ func handleSnapTar(sourceDir, targetDir, name, exclusionRules string, secret str exMap := make(map[string]struct{}) exStr := "" excludes := strings.Split(exclusionRules, ";") - excludes = append(excludes, "*.sock") - excludes = append(excludes, "*.socket") for _, exclude := range excludes { if len(exclude) == 0 { continue @@ -258,10 +257,14 @@ func handleSnapTar(sourceDir, targetDir, name, exclusionRules string, secret str commands := "" if len(secret) != 0 { extraCmd := "| openssl enc -aes-256-cbc -salt -k '" + secret + "' -out" - commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s %s %s", " -"+exStr, path, extraCmd, targetDir+"/"+name) + commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read --exclude-from=<(find %s -type s -print) -zcf %s %s %s %s", sourceDir, " -"+exStr, path, extraCmd, targetDir+"/"+name) global.LOG.Debug(strings.ReplaceAll(commands, fmt.Sprintf(" %s ", secret), "******")) } else { - commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read -zcf %s %s -C %s .", targetDir+"/"+name, exStr, sourceDir) + itemPrefix := pathUtils.Base(sourceDir) + if itemPrefix == "/" { + itemPrefix = "" + } + commands = fmt.Sprintf("tar --warning=no-file-changed --ignore-failed-read --exclude-from=<(find %s -type s -printf '%s' | sed 's|^|%s/|') -zcf %s %s -C %s .", sourceDir, "%P\n", itemPrefix, targetDir+"/"+name, exStr, sourceDir) global.LOG.Debug(commands) } stdout, err := cmd.ExecWithTimeOut(commands, 30*time.Minute) diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 95a87c2b1..24b32f3da 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -1573,7 +1573,7 @@ const message = { status: 'Snapshot status', ignoreRule: 'Ignore Rule', ignoreHelper: - 'This rule will be used to compress and backup the 1Panel data directory during snapshots, please modify with caution.', + 'This rule will be used to compress and backup the 1Panel data directory during snapshots, with socket files ignored by default.', ignoreHelper1: 'One item per line, e.g.: \n*.log\n/opt/1panel/cache', panelInfo: 'Write 1Panel basic information', panelBin: 'Backup 1Panel system files', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 77b22ea12..c37e3e6c2 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -1388,7 +1388,7 @@ const message = { deleteHelper: '將刪除該快照的所有備份文件,包括第三方備份賬號中的文件。', status: '快照狀態', ignoreRule: '排除規則', - ignoreHelper: '快照時將使用該規則對 1Panel 數據目錄進行壓縮備份,請謹慎修改。', + ignoreHelper: '快照時將使用該規則對 1Panel 數據目錄進行壓縮備份,預設忽略套接字檔案。', ignoreHelper1: '一行一個,例: \n*.log\n/opt/1panel/cache', panelInfo: '寫入 1Panel 基礎信息', panelBin: '備份 1Panel 系統文件', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 5c1251aba..e1dea0bb9 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -1391,7 +1391,7 @@ const message = { snapshot: '快照', deleteHelper: '将删除该快照的所有备份文件,包括第三方备份账号中的文件。', ignoreRule: '排除规则', - ignoreHelper: '快照时将使用该规则对 1Panel 数据目录进行压缩备份,请谨慎修改。', + ignoreHelper: '快照时将使用该规则对 1Panel 数据目录进行压缩备份,默认忽略套接字文件。', ignoreHelper1: '一行一个,例: \n*.log\n/opt/1panel/cache', status: '快照状态', panelInfo: '写入 1Panel 基础信息', diff --git a/frontend/src/views/home/index.vue b/frontend/src/views/home/index.vue index 8cf2ca861..93c715b9b 100644 --- a/frontend/src/views/home/index.vue +++ b/frontend/src/views/home/index.vue @@ -42,7 +42,7 @@ - + {{ baseInfo.kernelArch }} - - - {{ currentInfo.timeSinceUptime }} - - - - {{ loadUpTime(currentInfo.uptime) }} - {{ baseInfo.systemProxy }} + + + {{ currentInfo.timeSinceUptime }} + + + + {{ loadUpTime(currentInfo.uptime) }} + @@ -634,7 +634,7 @@ onBeforeUnmount(() => { .h-systemInfo { margin-left: 18px; - height: 216px; + height: 276px; } @-moz-document url-prefix() { .h-systemInfo { diff --git a/frontend/src/views/setting/snapshot/index.vue b/frontend/src/views/setting/snapshot/index.vue index 5bcb88613..5b8707055 100644 --- a/frontend/src/views/setting/snapshot/index.vue +++ b/frontend/src/views/setting/snapshot/index.vue @@ -28,6 +28,7 @@ :pagination-config="paginationConfig" v-model:selects="selects" :data="data" + @sort-change="search" style="margin-top: 20px" @search="search" > @@ -37,6 +38,7 @@ :label="$t('commons.table.name')" min-width="100" prop="name" + sortable fix /> @@ -104,6 +106,7 @@ { +const search = async (column?: any) => { + paginationConfig.orderBy = column?.order ? column.prop : paginationConfig.orderBy; + paginationConfig.order = column?.order ? column.order : paginationConfig.order; let params = { info: searchName.value, page: paginationConfig.currentPage, pageSize: paginationConfig.pageSize, + orderBy: paginationConfig.orderBy, + order: paginationConfig.order, }; loading.value = true; await searchSnapshotPage(params)