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 584bd01
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
8 changes: 6 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,11 @@ 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")

Check failure on line 36 in cmd/go-mysqldump/main.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.22 on ubuntu-22.04

fmt.Println arg list ends with redundant newline

Check failure on line 36 in cmd/go-mysqldump/main.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.22 on ubuntu-20.04

fmt.Println arg list ends with redundant newline

Check failure on line 36 in cmd/go-mysqldump/main.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.21 on ubuntu-22.04

fmt.Println arg list ends with redundant newline

Check failure on line 36 in cmd/go-mysqldump/main.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.21 on ubuntu-20.04

fmt.Println arg list ends with redundant newline
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 584bd01

Please sign in to comment.