1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-02-13 03:50:07 +08:00

fix: fix the issue of abnormal display of backup account size (#7827)

This commit is contained in:
ssongliu 2025-02-08 22:56:57 +08:00 committed by GitHub
parent 8b30308a4b
commit 368203443f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 35 additions and 60 deletions

View File

@ -43,12 +43,21 @@ func (u *BackupRecordService) SearchRecordsWithPage(search dto.RecordSearch) (in
if err != nil { if err != nil {
return 0, nil, err return 0, nil, err
} }
accounts, _ := backupRepo.List()
var data []dto.BackupRecords var data []dto.BackupRecords
for _, account := range records { for _, record := range records {
var item dto.BackupRecords var item dto.BackupRecords
if err := copier.Copy(&item, &account); err != nil { if err := copier.Copy(&item, &record); err != nil {
global.LOG.Errorf("copy backup account to dto backup info failed, err: %v", err) global.LOG.Errorf("copy backup account to dto backup info failed, err: %v", err)
} }
for _, account := range accounts {
if account.ID == record.DownloadAccountID {
item.DownloadAccountID = account.ID
item.AccountName = account.Name
item.AccountType = account.Type
break
}
}
data = append(data, item) data = append(data, item)
} }
return total, data, err return total, data, err
@ -63,12 +72,21 @@ func (u *BackupRecordService) SearchRecordsByCronjobWithPage(search dto.RecordSe
if err != nil { if err != nil {
return 0, nil, err return 0, nil, err
} }
accounts, _ := backupRepo.List()
var data []dto.BackupRecords var data []dto.BackupRecords
for _, account := range records { for _, record := range records {
var item dto.BackupRecords var item dto.BackupRecords
if err := copier.Copy(&item, &account); err != nil { if err := copier.Copy(&item, &record); err != nil {
global.LOG.Errorf("copy backup account to dto backup info failed, err: %v", err) global.LOG.Errorf("copy backup account to dto backup info failed, err: %v", err)
} }
for _, account := range accounts {
if account.ID == record.DownloadAccountID {
item.DownloadAccountID = account.ID
item.AccountName = account.Name
item.AccountType = account.Type
break
}
}
data = append(data, item) data = append(data, item)
} }
return total, data, err return total, data, err

View File

@ -492,7 +492,7 @@ func snapUpload(snap snapHelper, accounts string, file string) error {
targetAccounts := strings.Split(accounts, ",") targetAccounts := strings.Split(accounts, ",")
for _, item := range targetAccounts { for _, item := range targetAccounts {
snap.Task.LogStart(i18n.GetWithName("SnapUploadTo", fmt.Sprintf("[%s] %s", accountMap[item].name, path.Join("system_snapshot", path.Base(file))))) snap.Task.LogStart(i18n.GetWithName("SnapUploadTo", fmt.Sprintf("[%s] %s", accountMap[item].name, path.Join("system_snapshot", path.Base(file)))))
_, err := accountMap[item].client.Upload(source, path.Join("system_snapshot", path.Base(file))) _, err := accountMap[item].client.Upload(source, path.Join(accountMap[item].backupPath, "system_snapshot", path.Base(file)))
snap.Task.LogWithStatus(i18n.GetWithName("SnapUploadRes", accountMap[item].name), err) snap.Task.LogWithStatus(i18n.GetWithName("SnapUploadRes", accountMap[item].name), err)
if err != nil { if err != nil {
return err return err

View File

@ -1,47 +0,0 @@
package client
import (
"fmt"
"os"
"path"
"github.com/1Panel-dev/1Panel/core/utils/files"
)
type localClient struct {
dir string
}
func NewLocalClient(vars map[string]interface{}) (*localClient, error) {
dir := loadParamFromVars("dir", vars)
return &localClient{dir: dir}, nil
}
func (c localClient) ListBuckets() ([]interface{}, error) {
return nil, nil
}
func (c localClient) Upload(src, target string) (bool, error) {
targetFilePath := path.Join(c.dir, target)
if _, err := os.Stat(path.Dir(targetFilePath)); err != nil {
if os.IsNotExist(err) {
if err = os.MkdirAll(path.Dir(targetFilePath), os.ModePerm); err != nil {
return false, err
}
} else {
return false, err
}
}
if err := files.CopyFile(src, targetFilePath, false); err != nil {
return false, fmt.Errorf("cp file failed, err: %v", err)
}
return true, nil
}
func (c localClient) Delete(file string) (bool, error) {
if err := os.RemoveAll(file); err != nil {
return false, err
}
return true, nil
}

View File

@ -14,8 +14,6 @@ type CloudStorageClient interface {
func NewCloudStorageClient(backupType string, vars map[string]interface{}) (CloudStorageClient, error) { func NewCloudStorageClient(backupType string, vars map[string]interface{}) (CloudStorageClient, error) {
switch backupType { switch backupType {
case constant.Local:
return client.NewLocalClient(vars)
case constant.S3: case constant.S3:
return client.NewS3Client(vars) return client.NewS3Client(vars)
case constant.OSS: case constant.OSS:

View File

@ -371,7 +371,7 @@
<el-form-item v-if="dialogData.rowData!.type === 'directory'" :label="$t('cronjob.backupContent')"> <el-form-item v-if="dialogData.rowData!.type === 'directory'" :label="$t('cronjob.backupContent')">
<el-radio-group v-model="dialogData.rowData!.isDir"> <el-radio-group v-model="dialogData.rowData!.isDir">
<el-radio :value="true">{{ $t('file.dir') }}</el-radio> <el-radio :value="true">{{ $t('file.dir') }}</el-radio>
<el-radio :value="false">{{ $t('menu.file') }}</el-radio> <el-radio :value="false">{{ $t('menu.files') }}</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>

View File

@ -49,7 +49,7 @@
" "
/> />
</div> </div>
<LayoutContent :title="$t('menu.file')" v-loading="loading"> <LayoutContent :title="$t('menu.files')" v-loading="loading">
<template #prompt> <template #prompt>
<el-alert type="info" :closable="false"> <el-alert type="info" :closable="false">
<template #title> <template #title>
@ -73,7 +73,7 @@
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item command="file"> <el-dropdown-item command="file">
<svg-icon iconName="p-file-normal"></svg-icon> <svg-icon iconName="p-file-normal"></svg-icon>
{{ $t('menu.file') }} {{ $t('menu.files') }}
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</template> </template>

View File

@ -4,7 +4,7 @@
<div class="button-container"> <div class="button-container">
<div> <div>
<el-button type="primary" @click="upload('file')"> <el-button type="primary" @click="upload('file')">
{{ $t('commons.button.upload') }}{{ $t('menu.file') }} {{ $t('commons.button.upload') }}{{ $t('menu.files') }}
</el-button> </el-button>
<el-button type="primary" @click="upload('dir')"> <el-button type="primary" @click="upload('dir')">
{{ $t('commons.button.upload') }}{{ $t('file.dir') }} {{ $t('commons.button.upload') }}{{ $t('file.dir') }}

View File

@ -48,7 +48,7 @@
</el-tab-pane> </el-tab-pane>
<el-tab-pane :label="$t('process.openFiles')" name="openFiles"> <el-tab-pane :label="$t('process.openFiles')" name="openFiles">
<el-table :data="data.openFiles" border style="width: 100%"> <el-table :data="data.openFiles" border style="width: 100%">
<el-table-column prop="path" :label="$t('menu.file')" /> <el-table-column prop="path" :label="$t('menu.files')" />
<el-table-column prop="fd" label="fd" width="100px" /> <el-table-column prop="fd" label="fd" width="100px" />
</el-table> </el-table>
</el-tab-pane> </el-tab-pane>

View File

@ -259,6 +259,9 @@ const beforeLeave = async (stepItem: any) => {
loadCheckForSubmit(panelChecks, form.panelData); loadCheckForSubmit(panelChecks, form.panelData);
return true; return true;
case 'backupData': case 'backupData':
if (!form.appData || form.appData.length === 0) {
return true;
}
if (form.backupData && form.backupData.length !== 0) { if (form.backupData && form.backupData.length !== 0) {
let backupChecks = backupRef.value.getCheckedNodes(); let backupChecks = backupRef.value.getCheckedNodes();
loadCheckForSubmit(backupChecks, form.backupData); loadCheckForSubmit(backupChecks, form.backupData);
@ -497,6 +500,9 @@ const setPanelDefaultCheck = async (list: any) => {
} }
}; };
const setBackupDefaultCheck = async (list: any) => { const setBackupDefaultCheck = async (list: any) => {
if (!form.appData || form.appData.length === 0) {
return;
}
for (const item of list) { for (const item of list) {
if (item.isCheck) { if (item.isCheck) {
backupRef.value.setChecked(item.id, true, true); backupRef.value.setChecked(item.id, true, true);

View File

@ -17,7 +17,7 @@
{{ loadOperation(row.operation) }} {{ loadOperation(row.operation) }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column :label="$t('menu.file')" show-overflow-tooltip> <el-table-column :label="$t('menu.files')" show-overflow-tooltip>
<template #default="{ row }"> <template #default="{ row }">
{{ loadFileName(row.operation) }} {{ loadFileName(row.operation) }}
</template> </template>