Files
mayfly-go/server/internal/db/dbm/dbi/db_program.go
kanzihuang de5b9e46d3 !87 fix: 修复数据库备份与恢复问题
* feat: 修复数据库备份与恢复问题
* feat: 启用 BINLOG 支持全量备份和增量备份,未启用 BINLOG 仅支持全量备份
* feat: 数据库恢复后自动备份,避免数据丢失
2024-01-22 03:12:16 +00:00

40 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
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
}