diff --git a/backend/app/service/snapshot.go b/backend/app/service/snapshot.go index 1d2e7a9a6..a62bb3cd4 100644 --- a/backend/app/service/snapshot.go +++ b/backend/app/service/snapshot.go @@ -544,10 +544,6 @@ func (u *SnapshotService) HandleSnapshot(isCronjob bool, req dto.SnapshotCreate, wg.Add(1) go snapBackup(itemHelper, localDir, backupPanelDir) } - if snapStatus.PanelData != constant.StatusDone { - wg.Add(1) - go snapPanelData(itemHelper, localDir, backupPanelDir) - } if !isCronjob { 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}) return } + snapPanelData(itemHelper, localDir, backupPanelDir) + if snapStatus.PanelData != constant.StatusDone { + _ = snapshotRepo.Update(snap.ID, map[string]interface{}{"status": constant.StatusFailed}) + return + } snapCompress(itemHelper, rootDir) if snapStatus.Compress != constant.StatusDone { _ = snapshotRepo.Update(snap.ID, map[string]interface{}{"status": constant.StatusFailed}) return } - snapUpload(itemHelper, req.From, fmt.Sprintf("%s.tar.gz", rootDir)) if snapStatus.Upload != constant.StatusDone { _ = 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) } case "recover": - exclusionRules := "./tmp;./log;./cache;" + exclusionRules := "./tmp;./log;./cache;./db/1Panel.db-*;" if strings.Contains(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": ""}) + checkPointOfWal() if err := handleSnapTar(target, u.OriginalPath, "1panel_data.tar.gz", exclusionRules); err != nil { return fmt.Errorf("restore original panel data failed, err: %v", err) } _ = snapshotRepo.Update(snapID, map[string]interface{}{"recover_status": constant.StatusWaiting}) _ = fileOp.Fs.RemoveAll(path.Join(target, "apps")) + checkPointOfWal() if err := u.handleUnTar(source+"/1panel/1panel_data.tar.gz", target); err != nil { return fmt.Errorf("recover panel data failed, err: %v", err) } case "re-recover": _ = fileOp.Fs.RemoveAll(path.Join(target, "apps")) + checkPointOfWal() if err := u.handleUnTar(source+"/1panel/1panel_data.tar.gz", target); err != nil { return fmt.Errorf("retry recover panel data failed, err: %v", err) } case "rollback": _ = fileOp.Fs.RemoveAll(path.Join(target, "apps")) + checkPointOfWal() if err := u.handleUnTar(source+"/1panel_data.tar.gz", target); err != nil { return fmt.Errorf("rollback panel data failed, err: %v", err) } @@ -1045,9 +1049,6 @@ func checkIsAllDone(snapID uint) bool { if status.AppData != constant.StatusDone { return false } - if status.PanelData != constant.StatusDone { - return false - } if status.BackupData != constant.StatusDone { return false } diff --git a/backend/app/service/snapshot_create.go b/backend/app/service/snapshot_create.go index 57546bc09..04b1c86a5 100644 --- a/backend/app/service/snapshot_create.go +++ b/backend/app/service/snapshot_create.go @@ -129,16 +129,16 @@ func snapBackup(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}) status := constant.StatusDone dataDir := path.Join(global.CONF.System.BaseDir, "1panel") - exclusionRules := "./tmp;./log;./cache;" + exclusionRules := "./tmp;./log;./cache;./db/1Panel.db-*;" if strings.Contains(localDir, dataDir) { exclusionRules += ("." + strings.ReplaceAll(localDir, dataDir, "") + ";") } _ = snapshotRepo.Update(snap.SnapID, map[string]interface{}{"status": "OnSaveData"}) + checkPointOfWal() if err := handleSnapTar(dataDir, targetDir, "1panel_data.tar.gz", exclusionRules); err != nil { status = err.Error() } @@ -235,3 +235,9 @@ func handleSnapTar(sourceDir, targetDir, name, exclusionRules string) error { } 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) + } +} diff --git a/backend/app/service/upgrade.go b/backend/app/service/upgrade.go index 952831032..04ef61ca5 100644 --- a/backend/app/service/upgrade.go +++ b/backend/app/service/upgrade.go @@ -158,6 +158,7 @@ func (u *UpgradeService) Upgrade(req dto.Upgrade) error { go writeLogs(req.Version) _ = settingRepo.Update("SystemVersion", req.Version) _ = settingRepo.Update("SystemStatus", "Free") + checkPointOfWal() _, _ = cmd.ExecWithTimeOut("systemctl daemon-reload && systemctl restart 1panel.service", 1*time.Minute) }() return nil diff --git a/frontend/src/views/setting/snapshot/snap_status/index.vue b/frontend/src/views/setting/snapshot/snap_status/index.vue index cce1f0533..51ad3ecb3 100644 --- a/frontend/src/views/setting/snapshot/snap_status/index.vue +++ b/frontend/src/views/setting/snapshot/snap_status/index.vue @@ -44,14 +44,6 @@ - - - {{ $t('setting.panelData') }} - - {{ status.panelData }} - - - {{ $t('setting.backupData') }} @@ -60,6 +52,14 @@ + + + {{ $t('setting.panelData') }} + + {{ status.panelData }} + + +