Skip to content

Commit 37a3291

Browse files
dveedenlance6716
andauthored
dump: use mariadb-dump when available (#942)
Co-authored-by: lance6716 <[email protected]>
1 parent 5b7ff06 commit 37a3291

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-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")
@@ -30,7 +30,7 @@ func main() {
3030

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

dump/dumper.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,23 @@ 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+
}
66+
} else {
67+
path, err = exec.LookPath(executionPath)
68+
if err != nil {
69+
return nil, err
70+
}
6171
}
6272

6373
d := new(Dumper)

0 commit comments

Comments
 (0)