From 7691d9e4e820786681b289e3bfd0702e61fc4fdc 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 | 4 ++-- dump/dumper.go | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/cmd/go-mysqldump/main.go b/cmd/go-mysqldump/main.go index ea2d81bd2..144c7a31e 100644 --- a/cmd/go-mysqldump/main.go +++ b/cmd/go-mysqldump/main.go @@ -15,7 +15,7 @@ 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") @@ -30,7 +30,7 @@ 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) } diff --git a/dump/dumper.go b/dump/dumper.go index b56a44a0b..c7ea56db7 100644 --- a/dump/dumper.go +++ b/dump/dumper.go @@ -51,13 +51,23 @@ 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") + } + } + } else { + path, err = exec.LookPath(executionPath) + if err != nil { + return nil, err + } } d := new(Dumper)