|
|
|
@ -12,9 +12,12 @@ import (
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"regexp"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
bigThan int
|
|
|
|
|
smallThan int
|
|
|
|
|
startPos int
|
|
|
|
|
endPos int
|
|
|
|
|
startTime int64
|
|
|
|
@ -25,9 +28,12 @@ var (
|
|
|
|
|
outPath string
|
|
|
|
|
vbo bool
|
|
|
|
|
skipquery bool
|
|
|
|
|
pos int64
|
|
|
|
|
prefix string
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
cmd.Flags().IntVarP(&endPos, "pos", "P", 0, "skipPos of binlog")
|
|
|
|
|
cmd.Flags().IntVarP(&startPos, "start-pos", "S", 0, "startPos of binlog")
|
|
|
|
|
cmd.Flags().IntVarP(&endPos, "end-pos", "E", 0, "endPos of binlog")
|
|
|
|
|
cmd.Flags().StringVarP(&includeGtid, "include-gtid", "i", "", "include gtid")
|
|
|
|
@ -38,7 +44,9 @@ func init() {
|
|
|
|
|
cmd.Flags().Int64Var(&endTime, "endtime", 0, "end unix timestamp")
|
|
|
|
|
cmd.Flags().BoolVarP(&vbo, "verbose", "v", false, "show the detail verbose")
|
|
|
|
|
cmd.Flags().BoolVarP(&skipquery, "skip-query", "s", true, "skip query write to xlsx like BEGIN COMMIT")
|
|
|
|
|
|
|
|
|
|
cmd.Flags().IntVar(&bigThan, "big", 0, "show tx big than x bytes")
|
|
|
|
|
cmd.Flags().IntVar(&smallThan, "small", 0, "show tx small than x bytes")
|
|
|
|
|
cmd.Flags().StringVar(&prefix, "prefix", "mysql-bin", "mysql binlog prefix")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var cmd = &cobra.Command{
|
|
|
|
@ -60,21 +68,6 @@ func main() {
|
|
|
|
|
|
|
|
|
|
func ParseBinlog() {
|
|
|
|
|
var err error
|
|
|
|
|
var igtid, egtid *gtid.Gtid
|
|
|
|
|
if includeGtid != "" {
|
|
|
|
|
igtid, err = gtid.Parse(includeGtid)
|
|
|
|
|
if err != nil {
|
|
|
|
|
starlog.Errorln(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if excludeGtid != "" {
|
|
|
|
|
egtid, err = gtid.Parse(excludeGtid)
|
|
|
|
|
if err != nil {
|
|
|
|
|
starlog.Errorln(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foundCount := 0
|
|
|
|
|
var totalGtid *gtid.Gtid
|
|
|
|
|
var owrt *xlsx.File
|
|
|
|
@ -111,32 +104,32 @@ func ParseBinlog() {
|
|
|
|
|
res.SetColWidth(15, 15, 40)
|
|
|
|
|
owrt.Save(outPath)
|
|
|
|
|
}
|
|
|
|
|
getParser := func(fpath string) {
|
|
|
|
|
err = binlog.ParseBinlogFile(fpath, func(tx binlog.Transaction) {
|
|
|
|
|
if startTime != 0 && tx.Timestamp < startTime {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if endTime != 0 && tx.Timestamp > endTime {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if tx.StartPos < startPos {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if endPos > 0 && tx.EndPos > endPos {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if igtid != nil {
|
|
|
|
|
if c, _ := igtid.Contain(tx.GTID); !c {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if egtid != nil {
|
|
|
|
|
if c, _ := egtid.Contain(tx.GTID); c {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getParser := func(fpath string) string {
|
|
|
|
|
var sTime, eTime time.Time
|
|
|
|
|
if startTime != 0 {
|
|
|
|
|
sTime = time.Unix(startTime, 0)
|
|
|
|
|
}
|
|
|
|
|
if endTime != 0 {
|
|
|
|
|
eTime = time.Unix(endTime, 0)
|
|
|
|
|
}
|
|
|
|
|
var filter = binlog.BinlogFilter{
|
|
|
|
|
IncludeGtid: includeGtid,
|
|
|
|
|
ExcludeGtid: excludeGtid,
|
|
|
|
|
StartPos: startPos,
|
|
|
|
|
EndPos: endPos,
|
|
|
|
|
StartDate: sTime,
|
|
|
|
|
EndDate: eTime,
|
|
|
|
|
BigThan: bigThan,
|
|
|
|
|
SmallThan: smallThan,
|
|
|
|
|
}
|
|
|
|
|
var cGtid *gtid.Gtid
|
|
|
|
|
err = binlog.ParseBinlogWithFilter(fpath, pos, filter, func(tx binlog.Transaction) {
|
|
|
|
|
foundCount++
|
|
|
|
|
if cGtid == nil {
|
|
|
|
|
cGtid, _ = gtid.Parse(tx.GTID)
|
|
|
|
|
} else {
|
|
|
|
|
cGtid.Add(tx.GTID)
|
|
|
|
|
}
|
|
|
|
|
if totalGtid == nil {
|
|
|
|
|
totalGtid, _ = gtid.Parse(tx.GTID)
|
|
|
|
|
} else {
|
|
|
|
@ -174,18 +167,24 @@ func ParseBinlog() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
var cGtidStr string
|
|
|
|
|
if cGtid != nil {
|
|
|
|
|
cGtidStr = cGtid.String()
|
|
|
|
|
}
|
|
|
|
|
if outPath != "" {
|
|
|
|
|
err = owrt.Save(outPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
starlog.Errorln(err)
|
|
|
|
|
return
|
|
|
|
|
return cGtidStr
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
starlog.Errorln(err)
|
|
|
|
|
return
|
|
|
|
|
return cGtidStr
|
|
|
|
|
}
|
|
|
|
|
return cGtidStr
|
|
|
|
|
}
|
|
|
|
|
var gtidRes [][]string
|
|
|
|
|
for _, fp := range filePath {
|
|
|
|
|
if staros.IsFolder(fp) {
|
|
|
|
|
files, err := os.ReadDir(fp)
|
|
|
|
@ -193,21 +192,26 @@ func ParseBinlog() {
|
|
|
|
|
starlog.Errorln("read folder failed:", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
rgp := regexp.MustCompile(`^mysql-bin\.\d+$`)
|
|
|
|
|
rgp := regexp.MustCompile(`^` + prefix + `\.\d+$`)
|
|
|
|
|
for _, v := range files {
|
|
|
|
|
if !v.IsDir() && rgp.MatchString(v.Name()) {
|
|
|
|
|
getParser(filepath.Join(fp, v.Name()))
|
|
|
|
|
gtidRes = append(gtidRes, []string{v.Name(), getParser(filepath.Join(fp, v.Name()))})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
getParser(fp)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if outPath != "" {
|
|
|
|
|
owrt.Save(outPath)
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("")
|
|
|
|
|
if len(gtidRes) != 0 {
|
|
|
|
|
for _, v := range gtidRes {
|
|
|
|
|
fmt.Printf("%s:%s\n", v[0], v[1])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("")
|
|
|
|
|
allGtid := ""
|
|
|
|
|
if totalGtid != nil {
|
|
|
|
|
allGtid = totalGtid.String()
|
|
|
|
|