mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 00:09:16 +08:00
parent
a02f160adf
commit
e044d92075
@ -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
|
||||
}
|
||||
|
@ -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,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
|
||||
}
|
||||
|
||||
|
@ -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": [
|
||||
|
@ -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": [
|
||||
|
@ -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
|
||||
|
@ -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) => {
|
||||
|
@ -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:
|
||||
|
@ -1298,6 +1298,7 @@ const message = {
|
||||
backupJump: '未在當前備份列表中的備份檔案,請嘗試從檔案目錄中下載後導入備份。',
|
||||
|
||||
snapshot: '快照',
|
||||
deleteHelper: '將刪除該快照的所有備份文件,包括第三方備份賬號中的文件。',
|
||||
status: '快照狀態',
|
||||
ignoreRule: '排除規則',
|
||||
ignoreHelper: '快照時將使用該規則對 1Panel 數據目錄進行壓縮備份,請謹慎修改。',
|
||||
|
@ -1299,6 +1299,7 @@ const message = {
|
||||
backupJump: '未在当前备份列表中的备份文件,请尝试从文件目录中下载后导入备份。',
|
||||
|
||||
snapshot: '快照',
|
||||
deleteHelper: '将删除该快照的所有备份文件,包括第三方备份账号中的文件。',
|
||||
ignoreRule: '排除规则',
|
||||
ignoreHelper: '快照时将使用该规则对 1Panel 数据目录进行压缩备份,请谨慎修改。',
|
||||
ignoreHelper1: '一行一个,例: \n*.log\n/opt/1panel/cache',
|
||||
|
@ -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…
x
Reference in New Issue
Block a user