!96 删除数据库备份和恢复历史

* feat: 删除数据库备份历史
* refactor dbScheduler
* feat: 从数据库备份历史中恢复数据库
* feat: 删除数据库恢复历史记录
* refactor dbScheuler
This commit is contained in:
kanzihuang
2024-01-30 13:12:43 +00:00
committed by Coder慌
parent fc1b9ef35d
commit 3f828cc5b0
33 changed files with 1101 additions and 378 deletions

View File

@@ -10,10 +10,12 @@ var _ DbJob = (*DbRestore)(nil)
// DbRestore 数据库恢复任务
type DbRestore struct {
*DbJobBaseImpl
DbJobBaseImpl
DbInstanceId uint64 // 数据库实例ID
DbName string // 数据库名称
Enabled bool // 是否启用
EnabledDesc string // 启用状态描述
StartTime time.Time // 开始时间
Interval time.Duration // 间隔时间
Repeated bool // 是否重复执行
@@ -23,6 +25,10 @@ type DbRestore struct {
DbBackupHistoryName string `json:"dbBackupHistoryName"` // 数据库恢复历史名称
}
func (r *DbRestore) GetInstanceId() uint64 {
return r.DbInstanceId
}
func (r *DbRestore) GetDbName() string {
return r.DbName
}
@@ -36,7 +42,7 @@ func (r *DbRestore) Schedule() (time.Time, error) {
return time.Time{}, runner.ErrJobFinished
default:
if time.Now().Sub(r.StartTime) > time.Hour {
return time.Time{}, runner.ErrJobTimeout
return time.Time{}, runner.ErrJobExpired
}
return r.StartTime, nil
}
@@ -46,8 +52,13 @@ func (r *DbRestore) IsEnabled() bool {
return r.Enabled
}
func (r *DbRestore) SetEnabled(enabled bool) {
func (r *DbRestore) SetEnabled(enabled bool, desc string) {
r.Enabled = enabled
r.EnabledDesc = desc
}
func (r *DbRestore) IsExpired() bool {
return !r.Repeated && time.Now().After(r.StartTime.Add(time.Hour))
}
func (r *DbRestore) IsFinished() bool {
@@ -63,3 +74,19 @@ func (r *DbRestore) Update(job runner.Job) {
func (r *DbRestore) GetInterval() time.Duration {
return r.Interval
}
func (r *DbRestore) GetJobType() DbJobType {
return DbJobTypeRestore
}
func (r *DbRestore) SetLastStatus(status DbJobStatus, err error) {
r.setLastStatus(r.GetJobType(), status, err)
}
func (r *DbRestore) GetKey() DbJobKey {
return r.getKey(r.GetJobType())
}
func (r *DbRestore) SetStatus(status DbJobStatus, err error) {
r.setLastStatus(r.GetJobType(), status, err)
}