Skip to content

Commit 90be745

Browse files
authored
feat: Support the retention of remote backup files when deleting sche… (#8296)
Refs #8236
1 parent bba8aab commit 90be745

File tree

14 files changed

+70
-25
lines changed

14 files changed

+70
-25
lines changed

Diff for: backend/app/dto/cronjob.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,16 @@ type CronjobDownload struct {
7171
}
7272

7373
type CronjobClean struct {
74-
IsDelete bool `json:"isDelete"`
75-
CleanData bool `json:"cleanData"`
76-
CronjobID uint `json:"cronjobID" validate:"required"`
74+
IsDelete bool `json:"isDelete"`
75+
CleanData bool `json:"cleanData"`
76+
CleanRemoteData bool `json:"cleanRemoteData"`
77+
CronjobID uint `json:"cronjobID" validate:"required"`
7778
}
7879

7980
type CronjobBatchDelete struct {
80-
CleanData bool `json:"cleanData"`
81-
IDs []uint `json:"ids" validate:"required"`
81+
CleanData bool `json:"cleanData"`
82+
CleanRemoteData bool `json:"cleanRemoteData"`
83+
IDs []uint `json:"ids" validate:"required"`
8284
}
8385

8486
type CronjobInfo struct {

Diff for: backend/app/service/cronjob.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ func (u *CronjobService) CleanRecord(req dto.CronjobClean) error {
114114
if err != nil {
115115
return err
116116
}
117+
if !req.CleanRemoteData {
118+
for key := range accountMap {
119+
if key != constant.Local {
120+
delete(accountMap, key)
121+
}
122+
}
123+
}
117124
cronjob.RetainCopies = 0
118125
u.removeExpiredBackup(cronjob, accountMap, model.BackupRecord{})
119126
} else {
@@ -249,7 +256,7 @@ func (u *CronjobService) Delete(req dto.CronjobBatchDelete) error {
249256
global.Cron.Remove(cron.EntryID(idItem))
250257
}
251258
global.LOG.Infof("stop cronjob entryID: %s", cronjob.EntryIDs)
252-
if err := u.CleanRecord(dto.CronjobClean{CronjobID: id, CleanData: req.CleanData, IsDelete: true}); err != nil {
259+
if err := u.CleanRecord(dto.CronjobClean{CronjobID: id, CleanData: req.CleanData, CleanRemoteData: req.CleanRemoteData, IsDelete: true}); err != nil {
253260
return err
254261
}
255262
if err := cronjobRepo.Delete(commonRepo.WithByID(id)); err != nil {

Diff for: frontend/src/api/interface/cronjob.ts

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export namespace Cronjob {
8181
export interface CronjobDelete {
8282
ids: Array<number>;
8383
cleanData: boolean;
84+
cleanRemoteData: boolean;
8485
}
8586
export interface UpdateStatus {
8687
id: number;

Diff for: frontend/src/api/modules/cronjob.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ export const searchRecords = (params: Cronjob.SearchRecord) => {
2727
return http.post<ResPage<Cronjob.Record>>(`cronjobs/search/records`, params);
2828
};
2929

30-
export const cleanRecords = (id: number, cleanData: boolean) => {
31-
return http.post(`cronjobs/records/clean`, { cronjobID: id, cleanData: cleanData });
30+
export const cleanRecords = (id: number, cleanData: boolean, cleanRemoteData: boolean) => {
31+
return http.post(`cronjobs/records/clean`, {
32+
cronjobID: id,
33+
cleanData: cleanData,
34+
cleanRemoteData: cleanRemoteData,
35+
});
3236
};
3337

3438
export const getRecordDetail = (params: string) => {

Diff for: frontend/src/lang/modules/en.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,7 @@ const message = {
10131013
errHandle: 'Cronjob execution failure',
10141014
noRecord: 'Trigger the Cron Job, and you will see the records here.',
10151015
cleanData: 'Clean data',
1016+
cleanRemoteData: 'Delete remote data',
10161017
cleanDataHelper: 'Delete the backup file generated during this task.',
10171018
noLogs: 'No task output yet...',
10181019
errPath: 'Backup path [{0}] error, cannot download!',

Diff for: frontend/src/lang/modules/ja.ts

+1
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@ const message = {
998998
errHandle: 'cronjob実行障害',
999999
noRecord: 'Cronジョブをトリガーすると、ここにレコードが表示されます。',
10001000
cleanData: 'クリーンデータ',
1001+
cleanRemoteData: 'リモートデータを削除',
10011002
cleanDataHelper: 'このタスク中に生成されたバックアップファイルを削除します。',
10021003
noLogs: 'タスク出力はまだありません...',
10031004
errPath: 'バックアップパス[{0}]エラー、ダウンロードできません!',

Diff for: frontend/src/lang/modules/ko.ts

+1
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,7 @@ const message = {
992992
errHandle: '크론 작업 실행 실패',
993993
noRecord: '크론 작업을 트리거하고 나면 여기에 레코드가 표시됩니다.',
994994
cleanData: '데이터 정리',
995+
cleanRemoteData: '원격 데이터 삭제',
995996
cleanDataHelper: '이 작업에서 생성된 백업 파일을 삭제합니다.',
996997
noLogs: '작업 출력이 아직 없습니다...',
997998
errPath: '백업 경로 [{0}] 오류, 다운로드할 수 없습니다!',

Diff for: frontend/src/lang/modules/ms.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@ const message = {
10271027
errHandle: 'Kegagalan pelaksanaan tugas cron',
10281028
noRecord: 'Picu Tugas Cron, dan anda akan melihat rekod di sini.',
10291029
cleanData: 'Bersihkan data',
1030+
cleanRemoteData: 'Padam data jarak jauh',
10301031
cleanDataHelper: 'Padam fail sandaran yang dijana semasa tugas ini.',
10311032
noLogs: 'Tiada keluaran tugas lagi...',
10321033
errPath: 'Laluan sandaran [{0}] salah, tidak boleh dimuat turun!',

Diff for: frontend/src/lang/modules/pt-br.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,7 @@ const message = {
10181018
errHandle: 'Falha na execução do Cronjob',
10191019
noRecord: 'Acione a tarefa Cron e você verá os registros aqui.',
10201020
cleanData: 'Limpar dados',
1021+
cleanRemoteData: 'Excluir dados remotos',
10211022
cleanDataHelper: 'Excluir o arquivo de backup gerado durante esta tarefa.',
10221023
noLogs: 'Ainda não há saída de tarefa...',
10231024
errPath: 'Caminho de backup [{0}] com erro, não é possível fazer o download!',

Diff for: frontend/src/lang/modules/ru.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ const message = {
10211021
errHandle: 'Сбой выполнения задачи Cron',
10221022
noRecord: 'Запустите задачу Cron, и вы увидите записи здесь.',
10231023
cleanData: 'Очистить данные',
1024+
cleanRemoteData: 'Удалить удалённые данные',
10241025
cleanDataHelper: 'Удалить файл резервной копии, созданный во время этой задачи.',
10251026
noLogs: 'Пока нет вывода задачи...',
10261027
errPath: 'Ошибка пути резервной копии [{0}], невозможно скачать!',

Diff for: frontend/src/lang/modules/tw.ts

+1
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ const message = {
965965
errHandle: '任務執行失敗',
966966
noRecord: '目前計劃任務暫未產生記錄',
967967
cleanData: '刪除備份檔案',
968+
cleanRemoteData: '刪除遠端備份檔案',
968969
cleanDataHelper: '刪除該任務執行過程中產生的備份檔案',
969970
noLogs: '暫無任務輸出...',
970971
errPath: '備份路徑 [{0}] 錯誤,無法下載!',

Diff for: frontend/src/lang/modules/zh.ts

+1
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ const message = {
966966
errHandle: '任务执行失败',
967967
noRecord: '当前计划任务暂未产生记录',
968968
cleanData: '删除备份文件',
969+
cleanRemoteData: '删除远程备份文件',
969970
cleanDataHelper: '删除该任务执行过程中产生的备份文件',
970971
noLogs: '暂无任务输出...',
971972
errPath: '备份路径 [{0}] 错误,无法下载!',

Diff for: frontend/src/views/cronjob/index.vue

+7-1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@
163163
<el-form class="mt-4 mb-1" v-if="showClean" ref="deleteForm" label-position="left">
164164
<el-form-item>
165165
<el-checkbox v-model="cleanData" :label="$t('cronjob.cleanData')" />
166+
<el-checkbox
167+
v-if="cleanData"
168+
v-model="cleanRemoteData"
169+
:label="$t('cronjob.cleanRemoteData')"
170+
/>
166171
<span class="input-help">
167172
{{ $t('cronjob.cleanDataHelper') }}
168173
</span>
@@ -197,6 +202,7 @@ const operateIDs = ref();
197202
const opRef = ref();
198203
const showClean = ref();
199204
const cleanData = ref();
205+
const cleanRemoteData = ref(true);
200206
201207
const data = ref();
202208
const paginationConfig = reactive({
@@ -312,7 +318,7 @@ const onDelete = async (row: Cronjob.CronjobInfo | null) => {
312318
313319
const onSubmitDelete = async () => {
314320
loading.value = true;
315-
await deleteCronjob({ ids: operateIDs.value, cleanData: cleanData.value })
321+
await deleteCronjob({ ids: operateIDs.value, cleanData: cleanData.value, cleanRemoteData: cleanRemoteData.value })
316322
.then(() => {
317323
loading.value = false;
318324
MsgSuccess(i18n.global.t('commons.msg.deleteSuccess'));

Diff for: frontend/src/views/cronjob/record/index.vue

+33-16
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@
223223
<el-form ref="deleteForm" label-position="left" v-loading="delLoading">
224224
<el-form-item>
225225
<el-checkbox v-model="cleanData" :label="$t('cronjob.cleanData')" />
226+
<el-checkbox v-if="cleanData" v-model="cleanRemoteData" :label="$t('cronjob.cleanRemoteData')" />
226227
<span class="input-help">
227228
{{ $t('cronjob.cleanDataHelper') }}
228229
</span>
@@ -282,6 +283,7 @@ const currentRecordDetail = ref<string>('');
282283
const deleteVisible = ref();
283284
const delLoading = ref();
284285
const cleanData = ref();
286+
const cleanRemoteData = ref(true);
285287
286288
const acceptParams = async (params: DialogProps): Promise<void> => {
287289
let itemSize = Number(localStorage.getItem(searchInfo.cacheSizeKey));
@@ -433,26 +435,30 @@ const loadRecord = async (row: Cronjob.Record) => {
433435
};
434436
435437
const onClean = async () => {
436-
ElMessageBox.confirm(i18n.global.t('commons.msg.clean'), i18n.global.t('commons.msg.deleteTitle'), {
437-
confirmButtonText: i18n.global.t('commons.button.confirm'),
438-
cancelButtonText: i18n.global.t('commons.button.cancel'),
439-
type: 'warning',
440-
}).then(async () => {
441-
await cleanRecords(dialogData.value.rowData.id, cleanData.value)
442-
.then(() => {
443-
delLoading.value = false;
444-
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
445-
search();
446-
})
447-
.catch(() => {
448-
delLoading.value = false;
449-
});
450-
});
438+
if (!isBackup()) {
439+
ElMessageBox.confirm(i18n.global.t('commons.msg.clean'), i18n.global.t('commons.msg.deleteTitle'), {
440+
confirmButtonText: i18n.global.t('commons.button.confirm'),
441+
cancelButtonText: i18n.global.t('commons.button.cancel'),
442+
type: 'warning',
443+
}).then(async () => {
444+
await cleanRecords(dialogData.value.rowData.id, cleanData.value, cleanRemoteData.value)
445+
.then(() => {
446+
delLoading.value = false;
447+
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
448+
search();
449+
})
450+
.catch(() => {
451+
delLoading.value = false;
452+
});
453+
});
454+
} else {
455+
deleteVisible.value = true;
456+
}
451457
};
452458
453459
const cleanRecord = async () => {
454460
delLoading.value = true;
455-
await cleanRecords(dialogData.value.rowData.id, cleanData.value)
461+
await cleanRecords(dialogData.value.rowData.id, cleanData.value, cleanRemoteData.value)
456462
.then(() => {
457463
delLoading.value = false;
458464
deleteVisible.value = false;
@@ -464,6 +470,17 @@ const cleanRecord = async () => {
464470
});
465471
};
466472
473+
function isBackup() {
474+
return (
475+
dialogData.value.rowData!.type === 'app' ||
476+
dialogData.value.rowData!.type === 'website' ||
477+
dialogData.value.rowData!.type === 'database' ||
478+
dialogData.value.rowData!.type === 'directory' ||
479+
dialogData.value.rowData!.type === 'snapshot' ||
480+
dialogData.value.rowData!.type === 'log'
481+
);
482+
}
483+
467484
onBeforeUnmount(() => {
468485
clearInterval(Number(timer));
469486
timer = null;

0 commit comments

Comments
 (0)