mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 16:29:17 +08:00
fix: 修改快照备份失败的问题 (#3500)
This commit is contained in:
parent
9561336934
commit
e9f876853b
@ -544,10 +544,6 @@ func (u *SnapshotService) HandleSnapshot(isCronjob bool, req dto.SnapshotCreate,
|
|||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go snapBackup(itemHelper, localDir, backupPanelDir)
|
go snapBackup(itemHelper, localDir, backupPanelDir)
|
||||||
}
|
}
|
||||||
if snapStatus.PanelData != constant.StatusDone {
|
|
||||||
wg.Add(1)
|
|
||||||
go snapPanelData(itemHelper, localDir, backupPanelDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !isCronjob {
|
if !isCronjob {
|
||||||
go func() {
|
go func() {
|
||||||
@ -556,12 +552,16 @@ func (u *SnapshotService) HandleSnapshot(isCronjob bool, req dto.SnapshotCreate,
|
|||||||
_ = snapshotRepo.Update(snap.ID, map[string]interface{}{"status": constant.StatusFailed})
|
_ = snapshotRepo.Update(snap.ID, map[string]interface{}{"status": constant.StatusFailed})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
snapPanelData(itemHelper, localDir, backupPanelDir)
|
||||||
|
if snapStatus.PanelData != constant.StatusDone {
|
||||||
|
_ = snapshotRepo.Update(snap.ID, map[string]interface{}{"status": constant.StatusFailed})
|
||||||
|
return
|
||||||
|
}
|
||||||
snapCompress(itemHelper, rootDir)
|
snapCompress(itemHelper, rootDir)
|
||||||
if snapStatus.Compress != constant.StatusDone {
|
if snapStatus.Compress != constant.StatusDone {
|
||||||
_ = snapshotRepo.Update(snap.ID, map[string]interface{}{"status": constant.StatusFailed})
|
_ = snapshotRepo.Update(snap.ID, map[string]interface{}{"status": constant.StatusFailed})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
snapUpload(itemHelper, req.From, fmt.Sprintf("%s.tar.gz", rootDir))
|
snapUpload(itemHelper, req.From, fmt.Sprintf("%s.tar.gz", rootDir))
|
||||||
if snapStatus.Upload != constant.StatusDone {
|
if snapStatus.Upload != constant.StatusDone {
|
||||||
_ = snapshotRepo.Update(snap.ID, map[string]interface{}{"status": constant.StatusFailed})
|
_ = snapshotRepo.Update(snap.ID, map[string]interface{}{"status": constant.StatusFailed})
|
||||||
@ -778,7 +778,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;"
|
exclusionRules := "./tmp;./log;./cache;./db/1Panel.db-*;"
|
||||||
if strings.Contains(backupDir, target) {
|
if strings.Contains(backupDir, target) {
|
||||||
exclusionRules += ("." + strings.ReplaceAll(backupDir, target, "") + ";")
|
exclusionRules += ("." + strings.ReplaceAll(backupDir, target, "") + ";")
|
||||||
}
|
}
|
||||||
@ -787,22 +787,26 @@ func (u *SnapshotService) handlePanelDatas(snapID uint, fileOp files.FileOp, ope
|
|||||||
}
|
}
|
||||||
|
|
||||||
_ = snapshotRepo.Update(snapID, map[string]interface{}{"recover_status": ""})
|
_ = snapshotRepo.Update(snapID, map[string]interface{}{"recover_status": ""})
|
||||||
|
checkPointOfWal()
|
||||||
if err := handleSnapTar(target, u.OriginalPath, "1panel_data.tar.gz", exclusionRules); err != nil {
|
if err := handleSnapTar(target, u.OriginalPath, "1panel_data.tar.gz", exclusionRules); err != nil {
|
||||||
return fmt.Errorf("restore original panel data failed, err: %v", err)
|
return fmt.Errorf("restore original panel data failed, err: %v", err)
|
||||||
}
|
}
|
||||||
_ = snapshotRepo.Update(snapID, map[string]interface{}{"recover_status": constant.StatusWaiting})
|
_ = snapshotRepo.Update(snapID, map[string]interface{}{"recover_status": constant.StatusWaiting})
|
||||||
|
|
||||||
_ = fileOp.Fs.RemoveAll(path.Join(target, "apps"))
|
_ = fileOp.Fs.RemoveAll(path.Join(target, "apps"))
|
||||||
|
checkPointOfWal()
|
||||||
if err := u.handleUnTar(source+"/1panel/1panel_data.tar.gz", target); err != nil {
|
if err := u.handleUnTar(source+"/1panel/1panel_data.tar.gz", target); err != nil {
|
||||||
return fmt.Errorf("recover panel data failed, err: %v", err)
|
return fmt.Errorf("recover panel data failed, err: %v", err)
|
||||||
}
|
}
|
||||||
case "re-recover":
|
case "re-recover":
|
||||||
_ = fileOp.Fs.RemoveAll(path.Join(target, "apps"))
|
_ = fileOp.Fs.RemoveAll(path.Join(target, "apps"))
|
||||||
|
checkPointOfWal()
|
||||||
if err := u.handleUnTar(source+"/1panel/1panel_data.tar.gz", target); err != nil {
|
if err := u.handleUnTar(source+"/1panel/1panel_data.tar.gz", target); err != nil {
|
||||||
return fmt.Errorf("retry recover panel data failed, err: %v", err)
|
return fmt.Errorf("retry recover panel data failed, err: %v", err)
|
||||||
}
|
}
|
||||||
case "rollback":
|
case "rollback":
|
||||||
_ = fileOp.Fs.RemoveAll(path.Join(target, "apps"))
|
_ = fileOp.Fs.RemoveAll(path.Join(target, "apps"))
|
||||||
|
checkPointOfWal()
|
||||||
if err := u.handleUnTar(source+"/1panel_data.tar.gz", target); err != nil {
|
if err := u.handleUnTar(source+"/1panel_data.tar.gz", target); err != nil {
|
||||||
return fmt.Errorf("rollback panel data failed, err: %v", err)
|
return fmt.Errorf("rollback panel data failed, err: %v", err)
|
||||||
}
|
}
|
||||||
@ -1045,9 +1049,6 @@ func checkIsAllDone(snapID uint) bool {
|
|||||||
if status.AppData != constant.StatusDone {
|
if status.AppData != constant.StatusDone {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if status.PanelData != constant.StatusDone {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if status.BackupData != constant.StatusDone {
|
if status.BackupData != constant.StatusDone {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -129,16 +129,16 @@ func snapBackup(snap snapHelper, localDir, targetDir string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func snapPanelData(snap snapHelper, localDir, targetDir string) {
|
func snapPanelData(snap snapHelper, localDir, targetDir string) {
|
||||||
defer snap.Wg.Done()
|
|
||||||
_ = snapshotRepo.UpdateStatus(snap.Status.ID, map[string]interface{}{"panel_data": constant.Running})
|
_ = snapshotRepo.UpdateStatus(snap.Status.ID, map[string]interface{}{"panel_data": constant.Running})
|
||||||
status := constant.StatusDone
|
status := constant.StatusDone
|
||||||
dataDir := path.Join(global.CONF.System.BaseDir, "1panel")
|
dataDir := path.Join(global.CONF.System.BaseDir, "1panel")
|
||||||
exclusionRules := "./tmp;./log;./cache;"
|
exclusionRules := "./tmp;./log;./cache;./db/1Panel.db-*;"
|
||||||
if strings.Contains(localDir, dataDir) {
|
if strings.Contains(localDir, dataDir) {
|
||||||
exclusionRules += ("." + strings.ReplaceAll(localDir, dataDir, "") + ";")
|
exclusionRules += ("." + strings.ReplaceAll(localDir, dataDir, "") + ";")
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = snapshotRepo.Update(snap.SnapID, map[string]interface{}{"status": "OnSaveData"})
|
_ = snapshotRepo.Update(snap.SnapID, map[string]interface{}{"status": "OnSaveData"})
|
||||||
|
checkPointOfWal()
|
||||||
if err := handleSnapTar(dataDir, targetDir, "1panel_data.tar.gz", exclusionRules); err != nil {
|
if err := handleSnapTar(dataDir, targetDir, "1panel_data.tar.gz", exclusionRules); err != nil {
|
||||||
status = err.Error()
|
status = err.Error()
|
||||||
}
|
}
|
||||||
@ -235,3 +235,9 @@ func handleSnapTar(sourceDir, targetDir, name, exclusionRules string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkPointOfWal() {
|
||||||
|
if err := global.DB.Exec("PRAGMA wal_checkpoint(TRUNCATE);").Error; err != nil {
|
||||||
|
global.LOG.Errorf("handle check point failed, err: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -158,6 +158,7 @@ func (u *UpgradeService) Upgrade(req dto.Upgrade) error {
|
|||||||
go writeLogs(req.Version)
|
go writeLogs(req.Version)
|
||||||
_ = settingRepo.Update("SystemVersion", req.Version)
|
_ = settingRepo.Update("SystemVersion", req.Version)
|
||||||
_ = settingRepo.Update("SystemStatus", "Free")
|
_ = settingRepo.Update("SystemStatus", "Free")
|
||||||
|
checkPointOfWal()
|
||||||
_, _ = cmd.ExecWithTimeOut("systemctl daemon-reload && systemctl restart 1panel.service", 1*time.Minute)
|
_, _ = cmd.ExecWithTimeOut("systemctl daemon-reload && systemctl restart 1panel.service", 1*time.Minute)
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
|
@ -44,14 +44,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-alert>
|
</el-alert>
|
||||||
<el-alert :type="loadStatus(status.panelData)" :closable="false">
|
|
||||||
<template #title>
|
|
||||||
<el-button :icon="loadIcon(status.panelData)" link>{{ $t('setting.panelData') }}</el-button>
|
|
||||||
<div v-if="showErrorMsg(status.panelData)" class="top-margin">
|
|
||||||
<span class="err-message">{{ status.panelData }}</span>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</el-alert>
|
|
||||||
<el-alert :type="loadStatus(status.backupData)" :closable="false">
|
<el-alert :type="loadStatus(status.backupData)" :closable="false">
|
||||||
<template #title>
|
<template #title>
|
||||||
<el-button :icon="loadIcon(status.backupData)" link>{{ $t('setting.backupData') }}</el-button>
|
<el-button :icon="loadIcon(status.backupData)" link>{{ $t('setting.backupData') }}</el-button>
|
||||||
@ -60,6 +52,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-alert>
|
</el-alert>
|
||||||
|
<el-alert :type="loadStatus(status.panelData)" :closable="false">
|
||||||
|
<template #title>
|
||||||
|
<el-button :icon="loadIcon(status.panelData)" link>{{ $t('setting.panelData') }}</el-button>
|
||||||
|
<div v-if="showErrorMsg(status.panelData)" class="top-margin">
|
||||||
|
<span class="err-message">{{ status.panelData }}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-alert>
|
||||||
<el-alert :type="loadStatus(status.compress)" :closable="false">
|
<el-alert :type="loadStatus(status.compress)" :closable="false">
|
||||||
<template #title>
|
<template #title>
|
||||||
<el-button :icon="loadIcon(status.compress)" link>
|
<el-button :icon="loadIcon(status.compress)" link>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user