Browse Source

fix: 快照删除增加备份文件删除选项 (#5237)

Refs #4962
pull/5241/head
ssongliu 6 months ago committed by GitHub
parent
commit
e044d92075
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      backend/app/api/v1/snapshot.go
  2. 4
      backend/app/dto/setting.go
  3. 32
      backend/app/service/snapshot.go
  4. 19
      cmd/server/docs/docs.go
  5. 19
      cmd/server/docs/swagger.json
  6. 13
      cmd/server/docs/swagger.yaml
  7. 2
      frontend/src/api/modules/setting.ts
  8. 2
      frontend/src/lang/modules/en.ts
  9. 1
      frontend/src/lang/modules/tw.ts
  10. 1
      frontend/src/lang/modules/zh.ts
  11. 16
      frontend/src/views/setting/snapshot/index.vue

4
backend/app/api/v1/snapshot.go

@ -168,13 +168,13 @@ func (b *BaseApi) RollbackSnapshot(c *gin.Context) {
// @Summary Delete system backup
// @Description 删除系统快照
// @Accept json
// @Param request body dto.BatchDeleteReq true "request"
// @Param request body dto.SnapshotBatchDelete true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /settings/snapshot/del [post]
// @x-panel-log {"bodyKeys":["ids"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"ids","isList":true,"db":"snapshots","output_column":"name","output_value":"name"}],"formatZH":"删除系统快照 [name]","formatEN":"Delete system backup [name]"}
func (b *BaseApi) DeleteSnapshot(c *gin.Context) {
var req dto.BatchDeleteReq
var req dto.SnapshotBatchDelete
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}

4
backend/app/dto/setting.go

@ -122,6 +122,10 @@ type SnapshotRecover struct {
ReDownload bool `json:"reDownload"`
ID uint `json:"id" validate:"required"`
}
type SnapshotBatchDelete struct {
DeleteWithFile bool `json:"deleteWithFile"`
Ids []uint `json:"ids" validate:"required"`
}
type SnapshotImport struct {
From string `json:"from"`
Names []string `json:"names"`

32
backend/app/service/snapshot.go

@ -32,7 +32,7 @@ type ISnapshotService interface {
SnapshotRecover(req dto.SnapshotRecover) error
SnapshotRollback(req dto.SnapshotRecover) error
SnapshotImport(req dto.SnapshotImport) error
Delete(req dto.BatchDeleteReq) error
Delete(req dto.SnapshotBatchDelete) error
LoadSnapShotStatus(id uint) (*dto.SnapshotStatus, error)
@ -323,25 +323,23 @@ func (u *SnapshotService) HandleSnapshot(isCronjob bool, logPath string, req dto
return snap.Name, nil
}
func (u *SnapshotService) Delete(req dto.BatchDeleteReq) error {
backups, _ := snapshotRepo.GetList(commonRepo.WithIdsIn(req.Ids))
localDir, err := loadLocalDir()
if err != nil {
return err
}
for _, snap := range backups {
itemFile := path.Join(localDir, "system", snap.Name)
_ = os.RemoveAll(itemFile)
itemTarFile := path.Join(global.CONF.System.TmpDir, "system", snap.Name+".tar.gz")
_ = os.Remove(itemTarFile)
func (u *SnapshotService) Delete(req dto.SnapshotBatchDelete) error {
snaps, _ := snapshotRepo.GetList(commonRepo.WithIdsIn(req.Ids))
for _, snap := range snaps {
targetAccounts, err := loadClientMap(snap.From)
if err != nil {
return err
}
for _, item := range targetAccounts {
global.LOG.Debugf("remove snapshot file %s.tar.gz from %s", snap.Name, item.backType)
_, _ = item.client.Delete(path.Join(item.backupPath, "system_snapshot", snap.Name+".tar.gz"))
}
_ = snapshotRepo.DeleteStatus(snap.ID)
if err := snapshotRepo.Delete(commonRepo.WithByID(snap.ID)); err != nil {
return err
}
}
if err := snapshotRepo.Delete(commonRepo.WithIdsIn(req.Ids)); err != nil {
return err
}
return nil
}

19
cmd/server/docs/docs.go

@ -10501,7 +10501,7 @@ const docTemplate = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.BatchDeleteReq"
"$ref": "#/definitions/dto.SnapshotBatchDelete"
}
}
],
@ -18607,6 +18607,23 @@ const docTemplate = `{
}
}
},
"dto.SnapshotBatchDelete": {
"type": "object",
"required": [
"ids"
],
"properties": {
"deleteWithFile": {
"type": "boolean"
},
"ids": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"dto.SnapshotCreate": {
"type": "object",
"required": [

19
cmd/server/docs/swagger.json

@ -10494,7 +10494,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.BatchDeleteReq"
"$ref": "#/definitions/dto.SnapshotBatchDelete"
}
}
],
@ -18600,6 +18600,23 @@
}
}
},
"dto.SnapshotBatchDelete": {
"type": "object",
"required": [
"ids"
],
"properties": {
"deleteWithFile": {
"type": "boolean"
},
"ids": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"dto.SnapshotCreate": {
"type": "object",
"required": [

13
cmd/server/docs/swagger.yaml

@ -2744,6 +2744,17 @@ definitions:
required:
- key
type: object
dto.SnapshotBatchDelete:
properties:
deleteWithFile:
type: boolean
ids:
items:
type: integer
type: array
required:
- ids
type: object
dto.SnapshotCreate:
properties:
defaultDownload:
@ -11846,7 +11857,7 @@ paths:
name: request
required: true
schema:
$ref: '#/definitions/dto.BatchDeleteReq'
$ref: '#/definitions/dto.SnapshotBatchDelete'
responses:
"200":
description: OK

2
frontend/src/api/modules/setting.ts

@ -183,7 +183,7 @@ export const snapshotImport = (param: Setting.SnapshotImport) => {
export const updateSnapshotDescription = (param: DescriptionUpdate) => {
return http.post(`/settings/snapshot/description/update`, param);
};
export const snapshotDelete = (param: { ids: number[] }) => {
export const snapshotDelete = (param: { ids: number[]; deleteWithFile: boolean }) => {
return http.post(`/settings/snapshot/del`, param);
};
export const snapshotRecover = (param: Setting.SnapshotRecover) => {

2
frontend/src/lang/modules/en.ts

@ -1472,6 +1472,8 @@ const message = {
'Backup files not in the current backup list, please try downloading from the file directory and importing for backup.',
snapshot: 'Snapshot',
deleteHelper:
'All backup files for the snapshot, including those in the third-party backup account, will be deleted.',
status: 'Snapshot status',
ignoreRule: 'Ignore Rule',
ignoreHelper:

1
frontend/src/lang/modules/tw.ts

@ -1298,6 +1298,7 @@ const message = {
backupJump: '未在當前備份列表中的備份檔案請嘗試從檔案目錄中下載後導入備份',
snapshot: '快照',
deleteHelper: '將刪除該快照的所有備份文件包括第三方備份賬號中的文件',
status: '快照狀態',
ignoreRule: '排除規則',
ignoreHelper: '快照時將使用該規則對 1Panel 數據目錄進行壓縮備份請謹慎修改',

1
frontend/src/lang/modules/zh.ts

@ -1299,6 +1299,7 @@ const message = {
backupJump: '未在当前备份列表中的备份文件请尝试从文件目录中下载后导入备份',
snapshot: '快照',
deleteHelper: '将删除该快照的所有备份文件包括第三方备份账号中的文件',
ignoreRule: '排除规则',
ignoreHelper: '快照时将使用该规则对 1Panel 数据目录进行压缩备份请谨慎修改',
ignoreHelper1: '一行一个 \n*.log\n/opt/1panel/cache',

16
frontend/src/views/setting/snapshot/index.vue

@ -164,7 +164,18 @@
</template>
</el-drawer>
<OpDialog ref="opRef" @search="search" />
<OpDialog ref="opRef" @search="search">
<template #content>
<el-form class="mt-4 mb-1" ref="deleteForm" label-position="left">
<el-form-item>
<el-checkbox v-model="cleanData" :label="$t('cronjob.cleanData')" />
<span class="input-help">
{{ $t('setting.deleteHelper') }}
</span>
</el-form-item>
</el-form>
</template>
</OpDialog>
<SnapStatus ref="snapStatusRef" @search="search" />
<IgnoreRule ref="ignoreRef" />
</div>
@ -221,6 +232,7 @@ let snapInfo = reactive<Setting.SnapshotCreate>({
fromAccounts: [],
description: '',
});
const cleanData = ref();
const drawerVisible = ref<boolean>(false);
@ -332,7 +344,7 @@ const batchDelete = async (row: Setting.SnapshotInfo | null) => {
i18n.global.t('commons.button.delete'),
]),
api: snapshotDelete,
params: { ids: ids },
params: { ids: ids, deleteWithFile: cleanData.value },
});
};

Loading…
Cancel
Save