From 5361384a65554fb58f1b2f53aef29f29358c525b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Fri, 8 Nov 2024 08:45:54 +0100 Subject: [PATCH] dump: use mariadb-dump when available --- cmd/go-mysqldump/main.go | 11 +++++++++-- dump/dumper.go | 17 +++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/cmd/go-mysqldump/main.go b/cmd/go-mysqldump/main.go index b49f0c1ef..62f969094 100644 --- a/cmd/go-mysqldump/main.go +++ b/cmd/go-mysqldump/main.go @@ -15,13 +15,14 @@ var ( addr = flag.String("addr", "127.0.0.1:3306", "MySQL addr") user = flag.String("user", "root", "MySQL user") password = flag.String("password", "", "MySQL password") - execution = flag.String("exec", "mysqldump", "mysqldump execution path") + execution = flag.String("exec", "", "mysqldump/mariadb-dump execution path") output = flag.String("o", "", "dump output, empty for stdout") dbs = flag.String("dbs", "", "dump databases, separated by comma") tables = flag.String("tables", "", "dump tables, separated by comma, will overwrite dbs") tableDB = flag.String("table_db", "", "database for dump tables") ignoreTables = flag.String("ignore_tables", "", "ignore tables, must be database.table format, separated by comma") + skipBinlogPos = flag.Bool("skip-binlog-pos",false,"skip fetching binlog position via --master-data/--source-data") ) func main() { @@ -29,9 +30,15 @@ func main() { d, err := dump.NewDumper(*execution, *addr, *user, *password) if err != nil { - fmt.Printf("Create Dumper error %v\n", errors.ErrorStack(err)) + fmt.Printf("Create Dumper error: %v\n", errors.ErrorStack(err)) os.Exit(1) } + if d == nil { + fmt.Println("Failed to create Dumper\n") + os.Exit(1) + } + + d.SkipMasterData(*skipBinlogPos) if len(*ignoreTables) > 0 { subs := strings.Split(*ignoreTables, ",") diff --git a/dump/dumper.go b/dump/dumper.go index b56a44a0b..11e4d5104 100644 --- a/dump/dumper.go +++ b/dump/dumper.go @@ -51,13 +51,18 @@ type Dumper struct { } func NewDumper(executionPath string, addr string, user string, password string) (*Dumper, error) { - if len(executionPath) == 0 { - return nil, nil - } + var path string + var err error - path, err := exec.LookPath(executionPath) - if err != nil { - return nil, errors.Trace(err) + if len(executionPath) == 0 { // No explicit path set + path, err = exec.LookPath("mysqldump") + if err != nil { + path, err = exec.LookPath("mariadb-dump") + if err != nil { + // Using a new error as `err` will only mention mariadb-dump and not mysqldump + return nil, errors.New("not able to find mysqldump or mariadb-dump in path") + } + } } d := new(Dumper)