Skip to content

Commit 2ae5c9f

Browse files
authored
fix: Fix some snapshot anomaly issues (#8926)
Refs #8917 Refs #8924 Refs #8897
1 parent 8614e63 commit 2ae5c9f

3 files changed

Lines changed: 18 additions & 15 deletions

File tree

agent/app/service/snapshot.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,14 @@ func (u *SnapshotService) LoadSnapshotData() (dto.SnapshotData, error) {
118118
if err != nil {
119119
return data, err
120120
}
121-
for i, item := range itemBackups {
122-
if item.Label == "app" {
123-
itemBackups = append(itemBackups[:i], itemBackups[i+1:]...)
124-
}
125-
if item.Label == "system_snapshot" {
126-
itemBackups = append(itemBackups[:i], itemBackups[i+1:]...)
121+
i := 0
122+
for _, item := range itemBackups {
123+
if item.Label != "app" && item.Label != "system_snapshot" {
124+
itemBackups[i] = item
125+
i++
127126
}
128127
}
129-
data.BackupData = itemBackups
128+
data.BackupData = itemBackups[:i]
130129

131130
return data, nil
132131
}
@@ -329,7 +328,7 @@ func loadPanelFile(fileOp fileUtils.FileOp) ([]dto.DataTree, error) {
329328
itemData.IsDisable = true
330329
case "clamav", "download", "resource":
331330
panelPath := path.Join(global.Dir.DataDir, itemData.Label)
332-
itemData.Children, _ = loadFile(panelPath, 5, fileOp)
331+
itemData.Children, _ = loadFile(panelPath, 3, fileOp)
333332
case "apps", "backup", "log", "db", "tmp":
334333
continue
335334
}
@@ -376,7 +375,6 @@ func loadFile(pathItem string, index int, fileOp fileUtils.FileOp) ([]dto.DataTr
376375
if err != nil {
377376
return data, err
378377
}
379-
i := 0
380378
for _, fileItem := range snapFiles {
381379
itemData := dto.DataTree{
382380
ID: uuid.NewString(),
@@ -391,7 +389,9 @@ func loadFile(pathItem string, index int, fileOp fileUtils.FileOp) ([]dto.DataTr
391389
continue
392390
}
393391
itemData.Size = uint64(sizeItem)
394-
itemData.Children, _ = loadFile(path.Join(pathItem, itemData.Label), index-1, fileOp)
392+
if index > 1 {
393+
itemData.Children, _ = loadFile(path.Join(pathItem, itemData.Label), index-1, fileOp)
394+
}
395395
} else {
396396
fileInfo, err := fileItem.Info()
397397
if err != nil {
@@ -400,7 +400,6 @@ func loadFile(pathItem string, index int, fileOp fileUtils.FileOp) ([]dto.DataTr
400400
itemData.Size = uint64(fileInfo.Size())
401401
}
402402
data = append(data, itemData)
403-
i++
404403
}
405404
return data, nil
406405
}

agent/app/service/snapshot_create.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,14 @@ func loadDbConn(snap *snapHelper, targetDir string, req dto.SnapshotCreate) erro
267267
}
268268
_ = taskDB.Where("id = ?", req.TaskID).Delete(&model.Task{}).Error
269269
}
270-
if !req.WithOperationLog {
271-
_ = snap.snapCoreDB.Exec("DELETE FROM operation_logs").Error
270+
if !req.WithOperationLog && global.IsMaster {
271+
err = snap.snapCoreDB.Exec("DELETE FROM operation_logs").Error
272+
snap.Task.LogWithStatus(i18n.GetMsgByKey("SnapDeleteOperationLog"), err)
273+
if err != nil {
274+
return err
275+
}
272276
}
273-
if !req.WithLoginLog {
277+
if !req.WithLoginLog && global.IsMaster {
274278
err = snap.snapCoreDB.Exec("DELETE FROM login_logs").Error
275279
snap.Task.LogWithStatus(i18n.GetMsgByKey("SnapDeleteLoginLog"), err)
276280
if err != nil {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
<template #footer>
148148
<el-button @click="drawerVisible = false">{{ $t('commons.button.cancel') }}</el-button>
149149
<el-button @click="prev" v-if="nowIndex !== 0">{{ $t('commons.button.prev') }}</el-button>
150-
<el-button type="primary" v-if="nowIndex === 4" @click="submitAddSnapshot">
150+
<el-button type="primary" v-if="nowIndex === 4" :disabled="loading" @click="submitAddSnapshot">
151151
{{ $t('commons.button.create') }}
152152
</el-button>
153153
<el-button @click="next" v-else>{{ $t('commons.button.next') }}</el-button>

0 commit comments

Comments
 (0)