|
4 | 4 | "bytes" |
5 | 5 | "fmt" |
6 | 6 | "io" |
| 7 | + "net" |
7 | 8 | "os" |
8 | 9 | "os/exec" |
9 | 10 | "regexp" |
@@ -51,13 +52,23 @@ type Dumper struct { |
51 | 52 | } |
52 | 53 |
|
53 | 54 | func NewDumper(executionPath string, addr string, user string, password string) (*Dumper, error) { |
54 | | - if len(executionPath) == 0 { |
55 | | - return nil, nil |
56 | | - } |
| 55 | + var path string |
| 56 | + var err error |
57 | 57 |
|
58 | | - path, err := exec.LookPath(executionPath) |
59 | | - if err != nil { |
60 | | - return nil, errors.Trace(err) |
| 58 | + if len(executionPath) == 0 { // No explicit path set |
| 59 | + path, err = exec.LookPath("mysqldump") |
| 60 | + if err != nil { |
| 61 | + path, err = exec.LookPath("mariadb-dump") |
| 62 | + if err != nil { |
| 63 | + // Using a new error as `err` will only mention mariadb-dump and not mysqldump |
| 64 | + return nil, errors.New("not able to find mysqldump or mariadb-dump in path") |
| 65 | + } |
| 66 | + } |
| 67 | + } else { |
| 68 | + path, err = exec.LookPath(executionPath) |
| 69 | + if err != nil { |
| 70 | + return nil, err |
| 71 | + } |
61 | 72 | } |
62 | 73 |
|
63 | 74 | d := new(Dumper) |
@@ -202,10 +213,14 @@ func (d *Dumper) Dump(w io.Writer) error { |
202 | 213 | if strings.Contains(d.Addr, "/") { |
203 | 214 | args = append(args, fmt.Sprintf("--socket=%s", d.Addr)) |
204 | 215 | } else { |
205 | | - seps := strings.SplitN(d.Addr, ":", 2) |
206 | | - args = append(args, fmt.Sprintf("--host=%s", seps[0])) |
207 | | - if len(seps) > 1 { |
208 | | - args = append(args, fmt.Sprintf("--port=%s", seps[1])) |
| 216 | + host, port, err := net.SplitHostPort(d.Addr) |
| 217 | + if err != nil { |
| 218 | + host = d.Addr |
| 219 | + } |
| 220 | + |
| 221 | + args = append(args, fmt.Sprintf("--host=%s", host)) |
| 222 | + if port != "" { |
| 223 | + args = append(args, fmt.Sprintf("--port=%s", port)) |
209 | 224 | } |
210 | 225 | } |
211 | 226 |
|
|
0 commit comments