mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-04 00:10:25 +08:00
* feat: 删除数据库备份历史 * refactor dbScheduler * feat: 从数据库备份历史中恢复数据库 * feat: 删除数据库恢复历史记录 * refactor dbScheuler
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package dbi
|
|
|
|
import (
|
|
"context"
|
|
"mayfly-go/internal/db/domain/entity"
|
|
"path/filepath"
|
|
"time"
|
|
)
|
|
|
|
type DbProgram interface {
|
|
CheckBinlogEnabled(ctx context.Context) (bool, error)
|
|
CheckBinlogRowFormat(ctx context.Context) (bool, error)
|
|
|
|
Backup(ctx context.Context, backupHistory *entity.DbBackupHistory) (*entity.BinlogInfo, error)
|
|
|
|
FetchBinlogs(ctx context.Context, downloadLatestBinlogFile bool, earliestBackupSequence, latestBinlogSequence int64) ([]*entity.BinlogFile, error)
|
|
|
|
ReplayBinlog(ctx context.Context, originalDatabase, targetDatabase string, restoreInfo *RestoreInfo) error
|
|
|
|
RestoreBackupHistory(ctx context.Context, dbName string, dbBackupId uint64, dbBackupHistoryUuid string) error
|
|
|
|
RemoveBackupHistory(ctx context.Context, dbBackupId uint64, dbBackupHistoryUuid string) error
|
|
|
|
GetBinlogEventPositionAtOrAfterTime(ctx context.Context, binlogName string, targetTime time.Time) (position int64, parseErr error)
|
|
}
|
|
|
|
type RestoreInfo struct {
|
|
BackupHistory *entity.DbBackupHistory
|
|
BinlogHistories []*entity.DbBinlogHistory
|
|
StartPosition int64
|
|
TargetPosition int64
|
|
TargetTime time.Time
|
|
}
|
|
|
|
func (ri *RestoreInfo) GetBinlogPaths(binlogDir string) []string {
|
|
files := make([]string, 0, len(ri.BinlogHistories))
|
|
for _, history := range ri.BinlogHistories {
|
|
files = append(files, filepath.Join(binlogDir, history.FileName))
|
|
}
|
|
return files
|
|
}
|