Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip MySQL binlog start time #21

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/mysql/binlog_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import (
)

const fetchSinceFlagShortDescr = "backup name starting from which you want to fetch binlogs"
const skipStartTimeFlagShortDescr = "skip start time starting from begin to fetch binlogs"
const fetchUntilFlagShortDescr = "time in RFC3339 for PITR"
const fetchUntilBinlogLastModifiedFlagShortDescr = "time in RFC3339 that is used to prevent wal-g from replaying" +
" binlogs that was created/modified after this time"

var fetchBackupName string
var fetchUntilTS string
var fetchUntilBinlogLastModifiedTS string
var skipStartTime bool

// binlogPushCmd represents the cron command
var binlogFetchCmd = &cobra.Command{
Expand All @@ -27,7 +29,7 @@ var binlogFetchCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
folder, err := internal.ConfigureFolder()
tracelog.ErrorLogger.FatalOnError(err)
mysql.HandleBinlogFetch(folder, fetchBackupName, fetchUntilTS, fetchUntilBinlogLastModifiedTS)
mysql.HandleBinlogFetch(folder, fetchBackupName, fetchUntilTS, fetchUntilBinlogLastModifiedTS, skipStartTime)
},
PreRun: func(cmd *cobra.Command, args []string) {
internal.RequiredSettings[internal.MysqlBinlogDstSetting] = true
Expand All @@ -46,5 +48,6 @@ func init() {
"until-binlog-last-modified-time",
"",
fetchUntilBinlogLastModifiedFlagShortDescr)
binlogFetchCmd.PersistentFlags().BoolVar(&skipStartTime, "skip-start-time", false, skipStartTimeFlagShortDescr)
cmd.AddCommand(binlogFetchCmd)
}
13 changes: 9 additions & 4 deletions internal/databases/mysql/binlog_fetch_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"os"
"path"
"path/filepath"
"time"

"github.com/wal-g/tracelog"
"github.com/wal-g/wal-g/internal"
Expand Down Expand Up @@ -41,12 +42,16 @@
return nil
}

func HandleBinlogFetch(folder storage.Folder, backupName string, untilTS string, untilBinlogLastModifiedTS string) {
func HandleBinlogFetch(folder storage.Folder, backupName string, untilTS string, untilBinlogLastModifiedTS string, skipStartTime bool) {
dstDir, err := internal.GetLogsDstSettings(internal.MysqlBinlogDstSetting)
tracelog.ErrorLogger.FatalOnError(err)

startTS, endTS, endBinlogTS, err := getTimestamps(folder, backupName, untilTS, untilBinlogLastModifiedTS)
tracelog.ErrorLogger.FatalOnError(err)
var startTS, endTS, endBinlogTS time.Time
if skipStartTime {
startTS, endTS, endBinlogTS, err = getEndTimestamps(folder, untilTS, untilBinlogLastModifiedTS)

Check failure on line 50 in internal/databases/mysql/binlog_fetch_handler.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)
} else {
startTS, endTS, endBinlogTS, err = getTimestamps(folder, backupName, untilTS, untilBinlogLastModifiedTS)
tracelog.ErrorLogger.FatalOnError(err)
}

handler := newIndexHandler(dstDir)

Expand Down
13 changes: 13 additions & 0 deletions internal/databases/mysql/binlog_replay_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,16 @@
}
return startTS, endTS, endBinlogTS, nil
}

func getEndTimestamps(folder storage.Folder, untilTS, untilBinlogLastModifiedTS string) (time.Time, time.Time, time.Time, error) {

Check failure on line 115 in internal/databases/mysql/binlog_replay_handler.go

View workflow job for this annotation

GitHub Actions / lint

`getEndTimestamps` - `folder` is unused (unparam)
endTS, err := utility.ParseUntilTS(untilTS)
if err != nil {
return time.Time{}, time.Time{}, time.Time{}, err
}

endBinlogTS, err := utility.ParseUntilTS(untilBinlogLastModifiedTS)
if err != nil {
return time.Time{}, time.Time{}, time.Time{}, err
}
return startTS, endTS, endBinlogTS, nil
}
Loading