Skip to content

Commit aba79bf

Browse files
committed
dump: use mariadb-dump when available
1 parent 5acb569 commit aba79bf

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

cmd/go-mysqldump/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var (
1515
addr = flag.String("addr", "127.0.0.1:3306", "MySQL addr")
1616
user = flag.String("user", "root", "MySQL user")
1717
password = flag.String("password", "", "MySQL password")
18-
execution = flag.String("exec", "mysqldump", "mysqldump execution path")
18+
execution = flag.String("exec", "", "mysqldump/mariadb-dump execution path")
1919
output = flag.String("o", "", "dump output, empty for stdout")
2020

2121
dbs = flag.String("dbs", "", "dump databases, separated by comma")
@@ -29,7 +29,7 @@ func main() {
2929

3030
d, err := dump.NewDumper(*execution, *addr, *user, *password)
3131
if err != nil {
32-
fmt.Printf("Create Dumper error %v\n", errors.ErrorStack(err))
32+
fmt.Printf("Create Dumper error: %v\n", errors.ErrorStack(err))
3333
os.Exit(1)
3434
}
3535

dump/dumper.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,18 @@ type Dumper struct {
5151
}
5252

5353
func NewDumper(executionPath string, addr string, user string, password string) (*Dumper, error) {
54-
if len(executionPath) == 0 {
55-
return nil, nil
56-
}
54+
var path string
55+
var err error
5756

58-
path, err := exec.LookPath(executionPath)
59-
if err != nil {
60-
return nil, errors.Trace(err)
57+
if len(executionPath) == 0 { // No explicit path set
58+
path, err = exec.LookPath("mysqldump")
59+
if err != nil {
60+
path, err = exec.LookPath("mariadb-dump")
61+
if err != nil {
62+
// Using a new error as `err` will only mention mariadb-dump and not mysqldump
63+
return nil, errors.New("not able to find mysqldump or mariadb-dump in path")
64+
}
65+
}
6166
}
6267

6368
d := new(Dumper)

0 commit comments

Comments
 (0)