1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 16:29:17 +08:00

fix: 解决计划任务备份日志的一些问题 (#2798)

This commit is contained in:
ssongliu 2023-11-03 18:23:41 +08:00 committed by GitHub
parent 6546c10fb8
commit be46fc26df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 77 additions and 31 deletions

View File

@ -46,7 +46,7 @@ func (u *CronjobService) SearchWithPage(search dto.SearchWithPage) (int64, inter
if err := copier.Copy(&item, &cronjob); err != nil { if err := copier.Copy(&item, &cronjob); err != nil {
return 0, nil, errors.WithMessage(constant.ErrStructTransform, err.Error()) return 0, nil, errors.WithMessage(constant.ErrStructTransform, err.Error())
} }
if item.Type == "app" || item.Type == "website" || item.Type == "database" || item.Type == "directory" || item.Type == "snapshot" { if hasBackup(item.Type) {
backup, _ := backupRepo.Get(commonRepo.WithByID(uint(item.TargetDirID))) backup, _ := backupRepo.Get(commonRepo.WithByID(uint(item.TargetDirID)))
if len(backup.Type) != 0 { if len(backup.Type) != 0 {
item.TargetDir = backup.Type item.TargetDir = backup.Type
@ -103,7 +103,7 @@ func (u *CronjobService) CleanRecord(req dto.CronjobClean) error {
if err != nil { if err != nil {
return err return err
} }
if req.CleanData && (cronjob.Type == "app" || cronjob.Type == "database" || cronjob.Type == "website" || cronjob.Type == "directory" || cronjob.Type == "snapshot") { if req.CleanData && hasBackup(cronjob.Type) {
cronjob.RetainCopies = 0 cronjob.RetainCopies = 0
backup, err := backupRepo.Get(commonRepo.WithByID(uint(cronjob.TargetDirID))) backup, err := backupRepo.Get(commonRepo.WithByID(uint(cronjob.TargetDirID)))
if err != nil { if err != nil {

View File

@ -677,9 +677,14 @@ func (u *CronjobService) handleSystemLog(cronjob model.Cronjob, startTime time.T
global.LOG.Debug("backup ssh log successful!") global.LOG.Debug("backup ssh log successful!")
fileName := fmt.Sprintf("system_log_%s.tar.gz", startTime.Format("20060102150405")) fileName := fmt.Sprintf("system_log_%s.tar.gz", startTime.Format("20060102150405"))
if err := handleTar(pathItem, pathItem, fileName, ""); err != nil { targetDir := path.Dir(pathItem)
if err := handleTar(pathItem, targetDir, fileName, ""); err != nil {
return "", err return "", err
} }
defer func() {
os.RemoveAll(pathItem)
os.RemoveAll(path.Join(targetDir, fileName))
}()
client, err := NewIBackupService().NewClient(&backup) client, err := NewIBackupService().NewClient(&backup)
if err != nil { if err != nil {
@ -691,10 +696,14 @@ func (u *CronjobService) handleSystemLog(cronjob model.Cronjob, startTime time.T
targetPath = strings.TrimPrefix(backup.BackupPath, "/") + "/log/" + fileName targetPath = strings.TrimPrefix(backup.BackupPath, "/") + "/log/" + fileName
} }
if _, err = client.Upload(path.Join(pathItem, fileName), targetPath); err != nil { if _, err = client.Upload(path.Join(targetDir, fileName), targetPath); err != nil {
return "", err return "", err
} }
u.HandleRmExpired(backup.Type, backup.BackupPath, "", &cronjob, client) u.HandleRmExpired(backup.Type, backup.BackupPath, "", &cronjob, client)
return targetPath, nil return targetPath, nil
} }
func hasBackup(cronjobType string) bool {
return cronjobType == "app" || cronjobType == "database" || cronjobType == "website" || cronjobType == "directory" || cronjobType == "snapshot" || cronjobType == "log"
}

View File

@ -71,28 +71,31 @@ const acceptParams = (props: DialogProps): void => {
open.value = true; open.value = true;
}; };
const emit = defineEmits(['search', 'cancel']); const emit = defineEmits(['search', 'cancel', 'submit']);
const onConfirm = async () => { const onConfirm = async () => {
if (form.api) { if (form.api === null) {
loading.value = true; emit('submit');
await form open.value = false;
.api(form.params) return;
.then(() => {
emit('cancel');
emit('search');
if (successMsg.value) {
MsgSuccess(successMsg.value);
} else {
MsgSuccess(i18n.global.t('commons.msg.deleteSuccess'));
}
open.value = false;
loading.value = false;
})
.catch(() => {
loading.value = false;
});
} }
loading.value = true;
await form
.api(form.params)
.then(() => {
emit('cancel');
emit('search');
if (successMsg.value) {
MsgSuccess(successMsg.value);
} else {
MsgSuccess(i18n.global.t('commons.msg.deleteSuccess'));
}
open.value = false;
loading.value = false;
})
.catch(() => {
loading.value = false;
});
}; };
onMounted(() => {}); onMounted(() => {});

View File

@ -741,6 +741,7 @@ const message = {
record: 'Records', record: 'Records',
shell: 'Shell script', shell: 'Shell script',
log: 'Backup logs', log: 'Backup logs',
logHelper: 'Backup system log',
ogHelper1: '1.1Panel System log ', ogHelper1: '1.1Panel System log ',
logHelper2: '2. SSH login log of the server ', logHelper2: '2. SSH login log of the server ',
logHelper3: '3. All site logs ', logHelper3: '3. All site logs ',

View File

@ -713,6 +713,7 @@ const message = {
record: '報告', record: '報告',
shell: 'Shell 腳本', shell: 'Shell 腳本',
log: '備份日誌', log: '備份日誌',
logHelper: '備份系統日誌',
logHelper1: '1. 1Panel 系統日誌', logHelper1: '1. 1Panel 系統日誌',
logHelper2: '2. 服務器的 SSH 登錄日誌', logHelper2: '2. 服務器的 SSH 登錄日誌',
logHelper3: '3. 所有網站日誌', logHelper3: '3. 所有網站日誌',

View File

@ -714,6 +714,7 @@ const message = {
record: '报告', record: '报告',
shell: 'Shell 脚本', shell: 'Shell 脚本',
log: '备份日志', log: '备份日志',
logHelper: '备份系统日志',
logHelper1: '1. 1Panel 系统日志', logHelper1: '1. 1Panel 系统日志',
logHelper2: '2. 服务器的 SSH 登录日志', logHelper2: '2. 服务器的 SSH 登录日志',
logHelper3: '3. 所有网站日志', logHelper3: '3. 所有网站日志',

View File

@ -135,7 +135,7 @@
</template> </template>
</LayoutContent> </LayoutContent>
<OpDialog ref="opRef" @search="search"> <OpDialog ref="opRef" @search="search" @submit="onSubmitDelete()">
<template #content> <template #content>
<el-form class="mt-4 mb-1" v-if="showClean" ref="deleteForm" label-position="left"> <el-form class="mt-4 mb-1" v-if="showClean" ref="deleteForm" label-position="left">
<el-form-item> <el-form-item>
@ -169,6 +169,7 @@ import { MsgSuccess } from '@/utils/message';
const loading = ref(); const loading = ref();
const selects = ref<any>([]); const selects = ref<any>([]);
const isRecordShow = ref(); const isRecordShow = ref();
const operateIDs = ref();
const opRef = ref(); const opRef = ref();
const showClean = ref(); const showClean = ref();
@ -254,18 +255,20 @@ const onDelete = async (row: Cronjob.CronjobInfo | null) => {
if (row) { if (row) {
ids = [row.id]; ids = [row.id];
names = [row.name]; names = [row.name];
if (row.type === 'database' || row.type === 'website' || row.type === 'directory') { if (hasBackup(row.type)) {
showClean.value = true; showClean.value = true;
} }
return;
} else { } else {
for (const item of selects.value) { for (const item of selects.value) {
names.push(item.name); names.push(item.name);
ids.push(item.id); ids.push(item.id);
if (item.type === 'database' || item.type === 'website' || item.type === 'directory') { if (hasBackup(item.type)) {
showClean.value = true; showClean.value = true;
} }
} }
} }
operateIDs.value = ids;
opRef.value.acceptParams({ opRef.value.acceptParams({
title: i18n.global.t('commons.button.delete'), title: i18n.global.t('commons.button.delete'),
names: names, names: names,
@ -273,11 +276,17 @@ const onDelete = async (row: Cronjob.CronjobInfo | null) => {
i18n.global.t('cronjob.cronTask'), i18n.global.t('cronjob.cronTask'),
i18n.global.t('commons.button.delete'), i18n.global.t('commons.button.delete'),
]), ]),
api: deleteCronjob, api: null,
params: { ids: ids, cleanData: cleanData.value }, params: null,
}); });
}; };
const onSubmitDelete = async () => {
await deleteCronjob({ ids: operateIDs.value, cleanData: cleanData.value });
MsgSuccess(i18n.global.t('commons.msg.deleteSuccess'));
search();
};
const onChangeStatus = async (id: number, status: string) => { const onChangeStatus = async (id: number, status: string) => {
ElMessageBox.confirm(i18n.global.t('cronjob.' + status + 'Msg'), i18n.global.t('cronjob.changeStatus'), { ElMessageBox.confirm(i18n.global.t('cronjob.' + status + 'Msg'), i18n.global.t('cronjob.changeStatus'), {
confirmButtonText: i18n.global.t('commons.button.confirm'), confirmButtonText: i18n.global.t('commons.button.confirm'),
@ -317,6 +326,17 @@ const onHandle = async (row: Cronjob.CronjobInfo) => {
}); });
}; };
const hasBackup = (type: string) => {
return (
type === 'app' ||
type === 'website' ||
type === 'database' ||
type === 'directory' ||
type === 'snapshot' ||
type === 'log'
);
};
const loadDetail = (row: any) => { const loadDetail = (row: any) => {
isRecordShow.value = true; isRecordShow.value = true;
let params = { let params = {

View File

@ -30,7 +30,9 @@
<el-option value="snapshot" :label="$t('cronjob.snapshot')" /> <el-option value="snapshot" :label="$t('cronjob.snapshot')" />
<el-option value="ntp" :label="$t('cronjob.ntp')" /> <el-option value="ntp" :label="$t('cronjob.ntp')" />
</el-select> </el-select>
<el-tag v-else>{{ $t('cronjob.' + dialogData.rowData!.type) }}</el-tag> <div v-else style="width: 100%">
<el-tag>{{ $t('cronjob.' + dialogData.rowData!.type) }}</el-tag>
</div>
<div v-if="dialogData.rowData!.type === 'log'" class="logText"> <div v-if="dialogData.rowData!.type === 'log'" class="logText">
<span class="input-help"> <span class="input-help">
{{ $t('cronjob.logHelper1') }} {{ $t('cronjob.logHelper1') }}

View File

@ -179,7 +179,7 @@
</template> </template>
<span class="status-count">{{ dialogData.rowData!.targetDir }}</span> <span class="status-count">{{ dialogData.rowData!.targetDir }}</span>
<el-button <el-button
v-if="currentRecord?.status === 'Success' && dialogData.rowData!.type !== 'snapshot'" v-if="currentRecord?.status === 'Success' && dialogData.rowData!.type !== 'snapshot' && dialogData.rowData!.type !== 'log'"
type="primary" type="primary"
style="margin-left: 10px" style="margin-left: 10px"
link link
@ -211,6 +211,14 @@
{{ $t('commons.table.all') }} {{ $t('commons.table.all') }}
</span> </span>
</el-form-item> </el-form-item>
<el-form-item class="description" v-if="dialogData.rowData!.type === 'log'">
<template #label>
<span class="status-label">{{ $t('cronjob.log') }}</span>
</template>
<span class="status-count">
{{ $t('cronjob.logHelper') }}
</span>
</el-form-item>
<el-form-item class="description" v-if="dialogData.rowData!.type === 'database'"> <el-form-item class="description" v-if="dialogData.rowData!.type === 'database'">
<template #label> <template #label>
<span class="status-label">{{ $t('cronjob.database') }}</span> <span class="status-label">{{ $t('cronjob.database') }}</span>
@ -702,7 +710,8 @@ function isBackup() {
dialogData.value.rowData!.type === 'website' || dialogData.value.rowData!.type === 'website' ||
dialogData.value.rowData!.type === 'database' || dialogData.value.rowData!.type === 'database' ||
dialogData.value.rowData!.type === 'directory' || dialogData.value.rowData!.type === 'directory' ||
dialogData.value.rowData!.type === 'snapshot' dialogData.value.rowData!.type === 'snapshot' ||
dialogData.value.rowData!.type === 'log'
); );
} }
function loadWeek(i: number) { function loadWeek(i: number) {