diff --git a/cmd/mysql/binlog_fetch.go b/cmd/mysql/binlog_fetch.go index 0f674cad6..909a5318d 100644 --- a/cmd/mysql/binlog_fetch.go +++ b/cmd/mysql/binlog_fetch.go @@ -11,6 +11,7 @@ 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" @@ -18,6 +19,7 @@ const fetchUntilBinlogLastModifiedFlagShortDescr = "time in RFC3339 that is used var fetchBackupName string var fetchUntilTS string var fetchUntilBinlogLastModifiedTS string +var skipStartTime bool // binlogPushCmd represents the cron command var binlogFetchCmd = &cobra.Command{ @@ -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 @@ -46,5 +48,6 @@ func init() { "until-binlog-last-modified-time", "", fetchUntilBinlogLastModifiedFlagShortDescr) + binlogFetchCmd.PersistentFlags().BoolVar(&skipStartTime, "skip-start-time", false, skipStartTimeFlagShortDescr) cmd.AddCommand(binlogFetchCmd) } diff --git a/internal/databases/mysql/binlog_fetch_handler.go b/internal/databases/mysql/binlog_fetch_handler.go index f5cffcbca..3bb9ef462 100644 --- a/internal/databases/mysql/binlog_fetch_handler.go +++ b/internal/databases/mysql/binlog_fetch_handler.go @@ -4,6 +4,7 @@ import ( "os" "path" "path/filepath" + "time" "github.com/wal-g/tracelog" "github.com/wal-g/wal-g/internal" @@ -41,12 +42,16 @@ func (ih *indexHandler) createIndexFile() error { 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) + } else { + startTS, endTS, endBinlogTS, err = getTimestamps(folder, backupName, untilTS, untilBinlogLastModifiedTS) + tracelog.ErrorLogger.FatalOnError(err) + } handler := newIndexHandler(dstDir) diff --git a/internal/databases/mysql/binlog_replay_handler.go b/internal/databases/mysql/binlog_replay_handler.go index f9699f94b..118c5e2fd 100644 --- a/internal/databases/mysql/binlog_replay_handler.go +++ b/internal/databases/mysql/binlog_replay_handler.go @@ -111,3 +111,16 @@ func getTimestamps(folder storage.Folder, backupName, untilTS, untilBinlogLastMo } return startTS, endTS, endBinlogTS, nil } + +func getEndTimestamps(folder storage.Folder, untilTS, untilBinlogLastModifiedTS string) (time.Time, time.Time, time.Time, error) { + 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 +}