-
Notifications
You must be signed in to change notification settings - Fork 0
/
binlog_replay.go
49 lines (42 loc) · 1.88 KB
/
binlog_replay.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package mysql
import (
"time"
"github.com/spf13/cobra"
"github.com/wal-g/tracelog"
"github.com/apecloud/dataprotection-wal-g/internal"
"github.com/apecloud/dataprotection-wal-g/internal/databases/mysql"
"github.com/apecloud/dataprotection-wal-g/utility"
)
const replaySinceFlagShortDescr = "backup name starting from which you want to fetch binlogs"
const replayUntilFlagShortDescr = "time in RFC3339 for PITR"
const replayUntilBinlogLastModifiedFlagShortDescr = "time in RFC3339 that is used to prevent wal-g from replaying" +
" binlogs that was created/modified after this time"
var replayBackupName string
var replayUntilTS string
var replayUntilBinlogLastModifiedTS string
var replaySinceTS string
var binlogReplayCmd = &cobra.Command{
Use: "binlog-replay",
Short: "Fetch binlogs from storage and replays them to MySQL",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
folder, err := internal.ConfigureFolder()
tracelog.ErrorLogger.FatalOnError(err)
mysql.HandleBinlogReplay(folder, replayBackupName, replayUntilTS, replayUntilBinlogLastModifiedTS, replaySinceTS)
},
PreRun: func(cmd *cobra.Command, args []string) {
internal.RequiredSettings[internal.MysqlBinlogReplayCmd] = true
err := internal.AssertRequiredSettingsSet()
tracelog.ErrorLogger.FatalOnError(err)
},
}
func init() {
binlogReplayCmd.PersistentFlags().StringVar(&replayBackupName, "since", "LATEST", replaySinceFlagShortDescr)
binlogReplayCmd.PersistentFlags().StringVar(&replayUntilTS, "until",
utility.TimeNowCrossPlatformUTC().Format(time.RFC3339), replayUntilFlagShortDescr)
binlogReplayCmd.PersistentFlags().StringVar(&replayUntilBinlogLastModifiedTS, "until-binlog-last-modified-time",
"", replayUntilBinlogLastModifiedFlagShortDescr)
binlogReplayCmd.PersistentFlags().StringVar(&replaySinceTS, "since-time",
"", "binlog since time in RFC3339")
cmd.AddCommand(binlogReplayCmd)
}