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 5361384
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
11 changes: 9 additions & 2 deletions cmd/go-mysqldump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,30 @@ 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")
tables = flag.String("tables", "", "dump tables, separated by comma, will overwrite dbs")
tableDB = flag.String("table_db", "", "database for dump tables")
ignoreTables = flag.String("ignore_tables", "", "ignore tables, must be database.table format, separated by comma")
skipBinlogPos = flag.Bool("skip-binlog-pos",false,"skip fetching binlog position via --master-data/--source-data")
)

func main() {
flag.Parse()

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 37 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 37 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 37 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 37 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)
}

d.SkipMasterData(*skipBinlogPos)

if len(*ignoreTables) > 0 {
subs := strings.Split(*ignoreTables, ",")
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 5361384

Please sign in to comment.