fix: 解决备份套接字忽略不完的问题 (#6272)

This commit is contained in:
ssongliu 2024-08-28 13:45:22 +08:00 committed by GitHub
parent b18689a0d6
commit 5851124dee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 57 additions and 36 deletions

View File

@ -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
}

View File

@ -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"`

View File

@ -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)

View File

@ -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
}

View File

@ -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)

View File

@ -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',

View File

@ -1388,7 +1388,7 @@ const message = {
deleteHelper: '將刪除該快照的所有備份文件包括第三方備份賬號中的文件',
status: '快照狀態',
ignoreRule: '排除規則',
ignoreHelper: '快照時將使用該規則對 1Panel 數據目錄進行壓縮備份請謹慎修改',
ignoreHelper: '快照時將使用該規則對 1Panel 數據目錄進行壓縮備份預設忽略套接字檔案',
ignoreHelper1: '一行一個 \n*.log\n/opt/1panel/cache',
panelInfo: '寫入 1Panel 基礎信息',
panelBin: '備份 1Panel 系統文件',

View File

@ -1391,7 +1391,7 @@ const message = {
snapshot: '快照',
deleteHelper: '将删除该快照的所有备份文件包括第三方备份账号中的文件',
ignoreRule: '排除规则',
ignoreHelper: '快照时将使用该规则对 1Panel 数据目录进行压缩备份请谨慎修改',
ignoreHelper: '快照时将使用该规则对 1Panel 数据目录进行压缩备份默认忽略套接字文件',
ignoreHelper1: '一行一个 \n*.log\n/opt/1panel/cache',
status: '快照状态',
panelInfo: '写入 1Panel 基础信息',

View File

@ -42,7 +42,7 @@
<el-row :gutter="20" style="margin-top: 20px">
<el-col :xs="24" :sm="24" :md="16" :lg="16" :xl="16">
<CardWithHeader :header="$t('home.overview')" height="146px">
<CardWithHeader :header="$t('home.overview')" height="166px">
<template #body>
<div class="h-overview">
<el-row>
@ -80,7 +80,7 @@
</CardWithHeader>
<CardWithHeader :header="$t('commons.table.status')" style="margin-top: 20px">
<template #body>
<Status ref="statusRef" style="margin-top: -7px" />
<Status ref="statusRef" style="margin-bottom: 33px" />
</template>
</CardWithHeader>
<CardWithHeader :header="$t('menu.monitor')" style="margin-top: 20px; margin-bottom: 20px">
@ -209,22 +209,6 @@
</template>
{{ baseInfo.kernelArch }}
</el-descriptions-item>
<el-descriptions-item class-name="system-content">
<template #label>
<span class="system-label">
{{ $t('home.uptime') }}
</span>
</template>
{{ currentInfo.timeSinceUptime }}
</el-descriptions-item>
<el-descriptions-item class-name="system-content">
<template #label>
<span class="system-label">
{{ $t('home.runningTime') }}
</span>
</template>
{{ loadUpTime(currentInfo.uptime) }}
</el-descriptions-item>
<el-descriptions-item
v-if="baseInfo.ipv4Addr && baseInfo.ipv4Addr !== 'IPNotFound'"
class-name="system-content"
@ -247,6 +231,22 @@
</template>
{{ baseInfo.systemProxy }}
</el-descriptions-item>
<el-descriptions-item class-name="system-content">
<template #label>
<span class="system-label">
{{ $t('home.uptime') }}
</span>
</template>
{{ currentInfo.timeSinceUptime }}
</el-descriptions-item>
<el-descriptions-item class-name="system-content">
<template #label>
<span class="system-label">
{{ $t('home.runningTime') }}
</span>
</template>
{{ loadUpTime(currentInfo.uptime) }}
</el-descriptions-item>
</el-descriptions>
</el-scrollbar>
</template>
@ -634,7 +634,7 @@ onBeforeUnmount(() => {
.h-systemInfo {
margin-left: 18px;
height: 216px;
height: 276px;
}
@-moz-document url-prefix() {
.h-systemInfo {

View File

@ -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
/>
<el-table-column prop="version" :label="$t('app.version')" />
@ -104,6 +106,7 @@
</el-table-column>
<el-table-column
prop="createdAt"
sortable
:label="$t('commons.table.date')"
:formatter="dateFormat"
show-overflow-tooltip
@ -216,6 +219,8 @@ const paginationConfig = reactive({
currentPage: 1,
pageSize: 10,
total: 0,
orderBy: 'created_at',
order: 'null',
});
const searchName = ref();
@ -399,11 +404,15 @@ const buttons = [
},
];
const search = async () => {
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)