forked from TencentBlueKing/blueking-dbm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mysql): flashback支持记录闪回 TencentBlueKing#7331
- Loading branch information
Showing
21 changed files
with
1,780 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package mysqlcomm | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/cast" | ||
) | ||
|
||
// GetSequenceFromFilename get number suffix from binlog file name | ||
func GetSequenceFromFilename(binlogFileName string) int { | ||
file0Arr := strings.Split(binlogFileName, ".") | ||
return cast.ToInt(strings.TrimLeft(file0Arr[1], "0")) | ||
} | ||
|
||
// ConstructBinlogFilename build new binlog filename with number sufffix | ||
func ConstructBinlogFilename(fileNameTmpl string, sequenceSuffix int) string { | ||
file0Arr := strings.Split(fileNameTmpl, ".") | ||
file0Arr1Len := cast.ToString(len(file0Arr[1])) | ||
fileNameFmt := "%s." + "%0" + file0Arr1Len + "d" | ||
newFileName := fmt.Sprintf(fileNameFmt, file0Arr[0], sequenceSuffix) | ||
return newFileName | ||
} |
90 changes: 90 additions & 0 deletions
90
dbm-services/mysql/db-tools/dbactuator/internal/subcmd/mysqlcmd/goflashback.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package mysqlcmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"dbm-services/common/go-pubpkg/logger" | ||
"dbm-services/mysql/db-tools/dbactuator/internal/subcmd" | ||
"dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/rollback" | ||
"dbm-services/mysql/db-tools/dbactuator/pkg/util" | ||
_ "dbm-services/mysql/db-tools/dbactuator/pkg/util/mysqlutil" // mysqlutil TODO | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// GoFlashbackBinlogAct TODO | ||
type GoFlashbackBinlogAct struct { | ||
*subcmd.BaseOptions | ||
Payload rollback.GoFlashbackComp | ||
} | ||
|
||
// GoFlashbackBinlogCommand godoc | ||
// | ||
// @Summary 导入 binlog | ||
// @Description 通过 `mysqlbinlog --flashback xxx | mysql` 导入 binlog | ||
// @Tags mysql | ||
// @Accept json | ||
// @Param body body rollback.GoFlashbackComp true "short description" | ||
// @Router /mysql/flashback-binlog [post] | ||
func GoFlashbackBinlogCommand() *cobra.Command { | ||
act := GoFlashbackBinlogAct{ | ||
BaseOptions: subcmd.GBaseOptions, | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "goflashback-binlog", | ||
Short: "导入binlog", | ||
Example: fmt.Sprintf( | ||
"dbactuator mysql goflashback-binlog %s %s", | ||
subcmd.CmdBaseExampleStr, | ||
subcmd.ToPrettyJson(act.Payload.Example()), | ||
), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
util.CheckErr(act.Validate()) | ||
util.CheckErr(act.Init()) | ||
util.CheckErr(act.Run()) | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
// Init TODO | ||
func (d *GoFlashbackBinlogAct) Init() (err error) { | ||
if err = d.BaseOptions.Validate(); err != nil { | ||
return err | ||
} | ||
if err = d.Deserialize(&d.Payload.Params); err != nil { | ||
logger.Error("Deserialize err %s", err.Error()) | ||
return err | ||
} | ||
d.Payload.GeneralParam = subcmd.GeneralRuntimeParam | ||
return | ||
} | ||
|
||
// Validate TODO | ||
func (d *GoFlashbackBinlogAct) Validate() error { | ||
return nil | ||
} | ||
|
||
// Run TODO | ||
func (d *GoFlashbackBinlogAct) Run() (err error) { | ||
defer util.LoggerErrorStack(logger.Error, err) | ||
steps := subcmd.Steps{ | ||
{ | ||
FunName: "初始化", | ||
Func: d.Payload.Params.Init, | ||
}, | ||
{ | ||
FunName: "预检查", | ||
Func: d.Payload.Params.PreCheck, | ||
}, | ||
{ | ||
FunName: "开始 flashback binlog", | ||
Func: d.Payload.Params.Start, | ||
}, | ||
} | ||
if err = steps.Run(); err != nil { | ||
return err | ||
} | ||
logger.Info("import binlog successfully") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.