fix: 快照增加文件大小显示 (#2227)

pull/2252/head
ssongliu 1 year ago committed by GitHub
parent 9e5a452245
commit 645e6bbb79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -84,6 +84,7 @@ type SnapshotStatus struct {
BackupData string `json:"backupData"` BackupData string `json:"backupData"`
Compress string `json:"compress"` Compress string `json:"compress"`
Size string `json:"size"`
Upload string `json:"upload"` Upload string `json:"upload"`
} }

@ -29,5 +29,6 @@ type SnapshotStatus struct {
BackupData string `json:"backupData" gorm:"type:varchar(64);default:Running"` BackupData string `json:"backupData" gorm:"type:varchar(64);default:Running"`
Compress string `json:"compress" gorm:"type:varchar(64);default:Waiting"` 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"` 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 { func (u *SnapshotService) handlePanelDatas(snapID uint, fileOp files.FileOp, operation string, source, target, backupDir, dockerDir string) error {
switch operation { switch operation {
case "snapshot": case "snapshot":
exclusionRules := "./tmp;./log;./cache;./db/1Panel.db-*;" exclusionRules := "./tmp;./log;./cache;"
if strings.Contains(backupDir, source) { if strings.Contains(backupDir, source) {
exclusionRules += ("." + strings.ReplaceAll(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) return fmt.Errorf("backup panel data failed, err: %v", err)
} }
case "recover": case "recover":
exclusionRules := "./tmp;./log;./cache;./db/1Panel.db-*;" exclusionRules := "./tmp;./log;./cache;"
if strings.Contains(backupDir, target) { if strings.Contains(backupDir, target) {
exclusionRules += ("." + strings.ReplaceAll(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 installed apps from 1Panel: %s \n", status.AppData)
logs += fmt.Sprintf("Backup 1Panel data directory: %s \n", status.PanelData) 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("Backup local backup directory for 1Panel: %s \n", status.BackupData)
logs += fmt.Sprintf("Create snapshot file: %s \n", status.BackupData) logs += fmt.Sprintf("Create snapshot file: %s \n", status.Compress)
logs += fmt.Sprintf("Upload snapshot file: %s \n", status.BackupData) logs += fmt.Sprintf("Snapshot size: %s \n", status.Size)
logs += fmt.Sprintf("Upload snapshot file: %s \n", status.Upload)
return logs return logs
} }

@ -15,6 +15,7 @@ import (
"github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/cmd" "github.com/1Panel-dev/1Panel/backend/utils/cmd"
"github.com/1Panel-dev/1Panel/backend/utils/common"
"github.com/1Panel-dev/1Panel/backend/utils/files" "github.com/1Panel-dev/1Panel/backend/utils/files"
) )
@ -161,8 +162,16 @@ func snapCompress(snap snapHelper, rootDir string) {
return 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 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) { func snapUpload(snap snapHelper, account string, file string) {

@ -573,7 +573,7 @@ var UpdateCronjobWithDb = &gormigrate.Migration{
} }
var AddTableFirewall = &gormigrate.Migration{ var AddTableFirewall = &gormigrate.Migration{
ID: "20230828-add-table-firewall", ID: "20230908-add-table-firewall",
Migrate: func(tx *gorm.DB) error { Migrate: func(tx *gorm.DB) error {
if err := tx.AutoMigrate(&model.Firewall{}, model.SnapshotStatus{}, &model.Cronjob{}); err != nil { if err := tx.AutoMigrate(&model.Firewall{}, model.SnapshotStatus{}, &model.Cronjob{}); err != nil {
return err return err

@ -147,13 +147,16 @@ func RemoveRepeatElement(a interface{}) (ret []interface{}) {
} }
func LoadSizeUnit(value float64) string { func LoadSizeUnit(value float64) string {
if value > 1073741824 {
return fmt.Sprintf("%.2fM", value/1073741824)
}
if value > 1048576 { if value > 1048576 {
return fmt.Sprintf("%vM", value/1048576) return fmt.Sprintf("%.2fM", value/1048576)
} }
if value > 1024 { 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 { func LoadTimeZone() string {

@ -116,6 +116,7 @@ export namespace Setting {
backupData: string; backupData: string;
compress: string; compress: string;
size: string;
upload: string; upload: string;
} }
export interface UpgradeInfo { export interface UpgradeInfo {

@ -70,7 +70,9 @@
</el-alert> </el-alert>
<el-alert :type="loadStatus(status.upload)" :closable="false"> <el-alert :type="loadStatus(status.upload)" :closable="false">
<template #title> <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"> <div v-if="showErrorMsg(status.upload)" class="top-margin">
<span class="err-message">{{ status.upload }}</span> <span class="err-message">{{ status.upload }}</span>
</div> </div>
@ -104,6 +106,7 @@ const status = reactive<Setting.SnapshotStatus>({
backupData: '', backupData: '',
compress: '', compress: '',
size: '',
upload: '', upload: '',
}); });
@ -147,6 +150,7 @@ const loadCurrentStatus = async () => {
status.backupData = res.data.backupData; status.backupData = res.data.backupData;
status.compress = res.data.compress; status.compress = res.data.compress;
status.size = res.data.size;
status.upload = res.data.upload; status.upload = res.data.upload;
}) })
.catch(() => { .catch(() => {

Loading…
Cancel
Save