@@ -497,35 +497,22 @@ func (h *Handler) Progress(w http.ResponseWriter, r *http.Request) {
497497 })
498498}
499499
500- // findMySQLBinlog locates the mysqlbinlog binary. If mysqlbinlogPath is
501- // non-empty it is validated and returned directly. Otherwise the function
502- // checks PATH, queries MySQL basedir (if conn is non-nil), and finally
503- // common installation paths.
504- func findMySQLBinlog (mysqlbinlogPath string , ctx context.Context , conn * connector.MySQLConnector ) (string , error ) {
505- // 0. Explicit path from config.
506- if mysqlbinlogPath != "" {
507- if fi , err := os .Stat (mysqlbinlogPath ); err == nil && fi .Mode ().IsRegular () {
508- abs , _ := filepath .Abs (mysqlbinlogPath )
509- return abs , nil
510- }
511- return "" , fmt .Errorf ("specified mysqlbinlog path %q does not exist" , mysqlbinlogPath )
512- }
513-
500+ // findMySQLBinlog locates the mysqlbinlog binary by checking PATH first, then
501+ // querying MySQL's basedir, and finally checking common installation paths.
502+ func findMySQLBinlog (ctx context.Context , conn * connector.MySQLConnector ) (string , error ) {
514503 // 1. Try PATH first.
515504 if path , err := exec .LookPath ("mysqlbinlog" ); err == nil {
516505 return path , nil
517506 }
518507
519508 // 2. Try MySQL basedir (SHOW VARIABLES LIKE 'basedir').
520- if conn != nil {
521- basedir , err := conn .GetBasedir (ctx )
522- if err == nil && basedir != "" {
523- for _ , name := range []string {"mysqlbinlog" , "mysqlbinlog.exe" } {
524- candidate := filepath .Join (basedir , "bin" , name )
525- if fi , statErr := os .Stat (candidate ); statErr == nil && fi .Mode ().IsRegular () {
526- abs , _ := filepath .Abs (candidate )
527- return abs , nil
528- }
509+ basedir , err := conn .GetBasedir (ctx )
510+ if err == nil && basedir != "" {
511+ for _ , name := range []string {"mysqlbinlog" , "mysqlbinlog.exe" } {
512+ candidate := filepath .Join (basedir , "bin" , name )
513+ if fi , statErr := os .Stat (candidate ); statErr == nil && fi .Mode ().IsRegular () {
514+ abs , _ := filepath .Abs (candidate )
515+ return abs , nil
529516 }
530517 }
531518 }
@@ -546,7 +533,7 @@ func findMySQLBinlog(mysqlbinlogPath string, ctx context.Context, conn *connecto
546533 }
547534 }
548535
549- return "" , fmt .Errorf ("mysqlbinlog not found; install mysql-client or specify the path via DSN parameter mysqlbinlog_path (e.g. ?mysqlbinlog_path=C: \\ mysql \\ bin \\ mysqlbinlog.exe) " )
536+ return "" , fmt .Errorf ("mysqlbinlog not found in $PATH, MySQL basedir, or common installation paths ; install mysql-client or add mysqlbinlog to your PATH " )
550537}
551538
552539// parseBinlogRemote uses mysqlbinlog --read-from-remote-server to parse binlog
@@ -805,32 +792,20 @@ func (h *Handler) runOperation(op *Operation, operator string) {
805792 }
806793
807794 var parseRes * connector.ParseResult
808- var downloadCleanup string // temp dir to clean up if LOAD_FILE was used
809795
810- // Check if binlog files are accessible locally; if not, try alternatives .
796+ // Check if binlog files are accessible locally; if not, try mysqlbinlog remote .
811797 if len (paths ) > 0 {
812798 if _ , statErr := os .Stat (paths [0 ]); os .IsNotExist (statErr ) {
813- // Binlog files are not on the local filesystem.
814- // Try mysqlbinlog --read-from-remote-server first.
815- mysqlbinlogPath , findErr := findMySQLBinlog (connCfg .MySQLBinlogPath , ctx , conn )
816- if findErr == nil {
817- log .Printf ("pitr: trying mysqlbinlog remote for op %s" , op .ID )
818- parseRes , err = h .parseBinlogRemote (mysqlbinlogPath , connCfg , binlogNames , op .TargetTable , op .RecoveryTime )
819- if err != nil {
820- h .failOperation (op , "parse binlogs (remote): %v" , err )
821- return
822- }
823- } else {
824- // mysqlbinlog not available. Try downloading binlog files via
825- // MySQL LOAD_FILE() and parsing them with the Go-native parser.
826- log .Printf ("pitr: mysqlbinlog not found (%v), trying LOAD_FILE download for op %s" , findErr , op .ID )
827- downloaded , dlErr := conn .DownloadBinlogFiles (ctx , binlogDir , binlogNames )
828- if dlErr != nil {
829- h .failOperation (op , "cannot parse binlogs: mysqlbinlog not found and LOAD_FILE download failed: %v" , dlErr )
830- return
831- }
832- downloadCleanup = filepath .Dir (downloaded [0 ])
833- paths = downloaded
799+ log .Printf ("pitr: binlog files not accessible locally, trying mysqlbinlog remote for op %s" , op .ID )
800+ mysqlbinlogPath , findErr := findMySQLBinlog (ctx , conn )
801+ if findErr != nil {
802+ h .failOperation (op , "parse binlogs (remote): %v" , findErr )
803+ return
804+ }
805+ parseRes , err = h .parseBinlogRemote (mysqlbinlogPath , connCfg , binlogNames , op .TargetTable , op .RecoveryTime )
806+ if err != nil {
807+ h .failOperation (op , "parse binlogs (remote): %v" , err )
808+ return
834809 }
835810 }
836811 }
@@ -849,11 +824,6 @@ func (h *Handler) runOperation(op *Operation, operator string) {
849824 }
850825 }
851826
852- // Clean up downloaded binlog files.
853- if downloadCleanup != "" {
854- os .RemoveAll (downloadCleanup )
855- }
856-
857827 reverseSqls , err := parser .ReverseSQLBatch (parseRes .Events , nil )
858828 if err != nil {
859829 h .failOperation (op , "generate reverse SQL: %v" , err )
0 commit comments