mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 08:19:15 +08:00
fix: 快照增加文件大小显示 (#2227)
This commit is contained in:
parent
9e5a452245
commit
645e6bbb79
@ -84,6 +84,7 @@ type SnapshotStatus struct {
|
||||
BackupData string `json:"backupData"`
|
||||
|
||||
Compress string `json:"compress"`
|
||||
Size string `json:"size"`
|
||||
Upload string `json:"upload"`
|
||||
}
|
||||
|
||||
|
@ -29,5 +29,6 @@ type SnapshotStatus struct {
|
||||
BackupData string `json:"backupData" gorm:"type:varchar(64);default:Running"`
|
||||
|
||||
Compress string `json:"compress" gorm:"type:varchar(64);default:Waiting"`
|
||||
Size string `json:"size" gorm:"type:varchar(64)"`
|
||||
Upload string `json:"upload" gorm:"type:varchar(64);default:Waiting"`
|
||||
}
|
||||
|
@ -764,7 +764,7 @@ func (u *SnapshotService) handleBackupDatas(fileOp files.FileOp, operation strin
|
||||
func (u *SnapshotService) handlePanelDatas(snapID uint, fileOp files.FileOp, operation string, source, target, backupDir, dockerDir string) error {
|
||||
switch operation {
|
||||
case "snapshot":
|
||||
exclusionRules := "./tmp;./log;./cache;./db/1Panel.db-*;"
|
||||
exclusionRules := "./tmp;./log;./cache;"
|
||||
if strings.Contains(backupDir, source) {
|
||||
exclusionRules += ("." + strings.ReplaceAll(backupDir, source, "") + ";")
|
||||
}
|
||||
@ -776,7 +776,7 @@ func (u *SnapshotService) handlePanelDatas(snapID uint, fileOp files.FileOp, ope
|
||||
return fmt.Errorf("backup panel data failed, err: %v", err)
|
||||
}
|
||||
case "recover":
|
||||
exclusionRules := "./tmp;./log;./cache;./db/1Panel.db-*;"
|
||||
exclusionRules := "./tmp;./log;./cache;"
|
||||
if strings.Contains(backupDir, target) {
|
||||
exclusionRules += ("." + strings.ReplaceAll(backupDir, target, "") + ";")
|
||||
}
|
||||
@ -1038,8 +1038,9 @@ func loadLogByStatus(status model.SnapshotStatus) string {
|
||||
logs += fmt.Sprintf("Backup installed apps from 1Panel: %s \n", status.AppData)
|
||||
logs += fmt.Sprintf("Backup 1Panel data directory: %s \n", status.PanelData)
|
||||
logs += fmt.Sprintf("Backup local backup directory for 1Panel: %s \n", status.BackupData)
|
||||
logs += fmt.Sprintf("Create snapshot file: %s \n", status.BackupData)
|
||||
logs += fmt.Sprintf("Upload snapshot file: %s \n", status.BackupData)
|
||||
logs += fmt.Sprintf("Create snapshot file: %s \n", status.Compress)
|
||||
logs += fmt.Sprintf("Snapshot size: %s \n", status.Size)
|
||||
logs += fmt.Sprintf("Upload snapshot file: %s \n", status.Upload)
|
||||
|
||||
return logs
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||
"github.com/1Panel-dev/1Panel/backend/global"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/common"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
||||
)
|
||||
|
||||
@ -161,8 +162,16 @@ func snapCompress(snap snapHelper, rootDir string) {
|
||||
return
|
||||
}
|
||||
|
||||
stat, err := os.Stat(path.Join(tmpDir, fileName))
|
||||
if err != nil {
|
||||
snap.Status.Compress = err.Error()
|
||||
_ = snapshotRepo.UpdateStatus(snap.Status.ID, map[string]interface{}{"compress": err.Error()})
|
||||
return
|
||||
}
|
||||
size := common.LoadSizeUnit(float64(stat.Size()))
|
||||
global.LOG.Debugf("compress successful! size of file: %s", size)
|
||||
snap.Status.Compress = constant.StatusDone
|
||||
_ = snapshotRepo.UpdateStatus(snap.Status.ID, map[string]interface{}{"compress": constant.StatusDone})
|
||||
_ = snapshotRepo.UpdateStatus(snap.Status.ID, map[string]interface{}{"compress": constant.StatusDone, "size": size})
|
||||
}
|
||||
|
||||
func snapUpload(snap snapHelper, account string, file string) {
|
||||
|
@ -573,7 +573,7 @@ var UpdateCronjobWithDb = &gormigrate.Migration{
|
||||
}
|
||||
|
||||
var AddTableFirewall = &gormigrate.Migration{
|
||||
ID: "20230828-add-table-firewall",
|
||||
ID: "20230908-add-table-firewall",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.AutoMigrate(&model.Firewall{}, model.SnapshotStatus{}, &model.Cronjob{}); err != nil {
|
||||
return err
|
||||
|
@ -147,13 +147,16 @@ func RemoveRepeatElement(a interface{}) (ret []interface{}) {
|
||||
}
|
||||
|
||||
func LoadSizeUnit(value float64) string {
|
||||
if value > 1073741824 {
|
||||
return fmt.Sprintf("%.2fM", value/1073741824)
|
||||
}
|
||||
if value > 1048576 {
|
||||
return fmt.Sprintf("%vM", value/1048576)
|
||||
return fmt.Sprintf("%.2fM", value/1048576)
|
||||
}
|
||||
if value > 1024 {
|
||||
return fmt.Sprintf("%vK", value/1024)
|
||||
return fmt.Sprintf("%.2fK", value/1024)
|
||||
}
|
||||
return fmt.Sprintf("%v", value)
|
||||
return fmt.Sprintf("%.2f", value)
|
||||
}
|
||||
|
||||
func LoadTimeZone() string {
|
||||
|
@ -116,6 +116,7 @@ export namespace Setting {
|
||||
backupData: string;
|
||||
|
||||
compress: string;
|
||||
size: string;
|
||||
upload: string;
|
||||
}
|
||||
export interface UpgradeInfo {
|
||||
|
@ -70,7 +70,9 @@
|
||||
</el-alert>
|
||||
<el-alert :type="loadStatus(status.upload)" :closable="false">
|
||||
<template #title>
|
||||
<el-button :icon="loadIcon(status.upload)" link>{{ $t('setting.upload') }}</el-button>
|
||||
<el-button :icon="loadIcon(status.upload)" link>
|
||||
{{ $t('setting.upload') }} {{ status.size }}
|
||||
</el-button>
|
||||
<div v-if="showErrorMsg(status.upload)" class="top-margin">
|
||||
<span class="err-message">{{ status.upload }}</span>
|
||||
</div>
|
||||
@ -104,6 +106,7 @@ const status = reactive<Setting.SnapshotStatus>({
|
||||
backupData: '',
|
||||
|
||||
compress: '',
|
||||
size: '',
|
||||
upload: '',
|
||||
});
|
||||
|
||||
@ -147,6 +150,7 @@ const loadCurrentStatus = async () => {
|
||||
status.backupData = res.data.backupData;
|
||||
|
||||
status.compress = res.data.compress;
|
||||
status.size = res.data.size;
|
||||
status.upload = res.data.upload;
|
||||
})
|
||||
.catch(() => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user