2023-12-27 22:59:20 +08:00
|
|
|
package entity
|
|
|
|
|
|
|
|
|
|
import (
|
2024-01-17 08:37:22 +00:00
|
|
|
"mayfly-go/pkg/runner"
|
2023-12-27 22:59:20 +08:00
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
2024-01-17 08:37:22 +00:00
|
|
|
const (
|
|
|
|
|
BinlogDownloadInterval = time.Minute * 15
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// BinlogFile is the metadata of the MySQL binlog file.
|
|
|
|
|
type BinlogFile struct {
|
2024-02-06 07:16:56 +00:00
|
|
|
Name string
|
|
|
|
|
RemoteSize int64
|
|
|
|
|
LocalSize int64
|
2024-01-17 08:37:22 +00:00
|
|
|
|
|
|
|
|
// Sequence is parsed from Name and is for the sorting purpose.
|
|
|
|
|
Sequence int64
|
|
|
|
|
FirstEventTime time.Time
|
|
|
|
|
LastEventTime time.Time
|
2024-02-06 07:16:56 +00:00
|
|
|
|
|
|
|
|
Downloaded bool
|
2024-01-17 08:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var _ DbJob = (*DbBinlog)(nil)
|
|
|
|
|
|
2023-12-27 22:59:20 +08:00
|
|
|
// DbBinlog 数据库备份任务
|
|
|
|
|
type DbBinlog struct {
|
2024-01-17 08:37:22 +00:00
|
|
|
DbJobBaseImpl
|
2024-01-30 13:12:43 +00:00
|
|
|
DbInstanceId uint64 // 数据库实例ID
|
2023-12-27 22:59:20 +08:00
|
|
|
}
|
|
|
|
|
|
2024-01-05 08:55:34 +08:00
|
|
|
func NewDbBinlog(instanceId uint64) *DbBinlog {
|
2024-01-11 11:35:51 +08:00
|
|
|
job := &DbBinlog{}
|
|
|
|
|
job.Id = instanceId
|
|
|
|
|
job.DbInstanceId = instanceId
|
|
|
|
|
return job
|
2023-12-27 22:59:20 +08:00
|
|
|
}
|
|
|
|
|
|
2024-01-30 13:12:43 +00:00
|
|
|
func (b *DbBinlog) GetInstanceId() uint64 {
|
|
|
|
|
return b.DbInstanceId
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-17 08:37:22 +00:00
|
|
|
func (b *DbBinlog) GetDbName() string {
|
|
|
|
|
// binlog 是全库级别的
|
|
|
|
|
return ""
|
|
|
|
|
}
|
2023-12-27 22:59:20 +08:00
|
|
|
|
2024-01-17 08:37:22 +00:00
|
|
|
func (b *DbBinlog) Schedule() (time.Time, error) {
|
2024-01-30 13:12:43 +00:00
|
|
|
switch b.LastStatus {
|
2024-01-17 08:37:22 +00:00
|
|
|
case DbJobSuccess:
|
2024-01-19 00:40:44 +00:00
|
|
|
return time.Time{}, runner.ErrJobFinished
|
2024-01-17 08:37:22 +00:00
|
|
|
case DbJobFailed:
|
|
|
|
|
return time.Now().Add(BinlogDownloadInterval), nil
|
|
|
|
|
default:
|
|
|
|
|
return time.Now(), nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *DbBinlog) Update(_ runner.Job) {}
|
|
|
|
|
|
|
|
|
|
func (b *DbBinlog) IsEnabled() bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 13:12:43 +00:00
|
|
|
func (b *DbBinlog) IsExpired() bool {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *DbBinlog) SetEnabled(_ bool, _ string) {}
|
2024-01-17 08:37:22 +00:00
|
|
|
|
|
|
|
|
func (b *DbBinlog) GetInterval() time.Duration {
|
|
|
|
|
return 0
|
2023-12-27 22:59:20 +08:00
|
|
|
}
|
2024-01-30 13:12:43 +00:00
|
|
|
|
|
|
|
|
func (b *DbBinlog) GetJobType() DbJobType {
|
|
|
|
|
return DbJobTypeBinlog
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *DbBinlog) GetKey() DbJobKey {
|
|
|
|
|
return b.getKey(b.GetJobType())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *DbBinlog) SetStatus(status DbJobStatus, err error) {
|
|
|
|
|
b.setLastStatus(b.GetJobType(), status, err)
|
|
|
|
|
}
|