Skip to content

Commit

Permalink
dump: use mariadb-dump when available
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden committed Nov 8, 2024
1 parent 5acb569 commit aba79bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cmd/go-mysqldump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -29,7 +29,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)
}

Expand Down
17 changes: 11 additions & 6 deletions dump/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit aba79bf

Please sign in to comment.