@@ -71,6 +71,7 @@ const (
71
71
writerBufferSize = 2 * 1024 * 1024 /*2 MiB*/
72
72
xtrabackupBinaryName = "xtrabackup"
73
73
xtrabackupEngineName = "xtrabackup"
74
+ xtrabackupInfoFile = "xtrabackup_info"
74
75
xbstream = "xbstream"
75
76
)
76
77
@@ -292,14 +293,14 @@ func (be *XtrabackupEngine) backupFiles(
292
293
numStripes int ,
293
294
flavor string ,
294
295
) (replicationPosition replication.Position , finalErr error ) {
295
-
296
296
backupProgram := path .Join (xtrabackupEnginePath , xtrabackupBinaryName )
297
297
flagsToExec := []string {"--defaults-file=" + params .Cnf .Path ,
298
298
"--backup" ,
299
299
"--socket=" + params .Cnf .SocketFile ,
300
300
"--slave-info" ,
301
301
"--user=" + xtrabackupUser ,
302
302
"--target-dir=" + params .Cnf .TmpDir ,
303
+ "--extra-lsndir=" + params .Cnf .TmpDir ,
303
304
}
304
305
if xtrabackupStreamMode != "" {
305
306
flagsToExec = append (flagsToExec , "--stream=" + xtrabackupStreamMode )
@@ -398,27 +399,14 @@ func (be *XtrabackupEngine) backupFiles(
398
399
// the replication position. Note that if we don't read stderr as we go, the
399
400
// xtrabackup process gets blocked when the write buffer fills up.
400
401
stderrBuilder := & strings.Builder {}
401
- posBuilder := & strings.Builder {}
402
402
stderrDone := make (chan struct {})
403
403
go func () {
404
404
defer close (stderrDone )
405
405
406
406
scanner := bufio .NewScanner (backupErr )
407
- capture := false
408
407
for scanner .Scan () {
409
408
line := scanner .Text ()
410
409
params .Logger .Infof ("xtrabackup stderr: %s" , line )
411
-
412
- // Wait until we see the first line of the binlog position.
413
- // Then capture all subsequent lines. We need multiple lines since
414
- // the value we're looking for has newlines in it.
415
- if ! capture {
416
- if ! strings .Contains (line , "MySQL binlog position" ) {
417
- continue
418
- }
419
- capture = true
420
- }
421
- fmt .Fprintln (posBuilder , line )
422
410
}
423
411
if err := scanner .Err (); err != nil {
424
412
params .Logger .Errorf ("error reading from xtrabackup stderr: %v" , err )
@@ -462,8 +450,7 @@ func (be *XtrabackupEngine) backupFiles(
462
450
return replicationPosition , vterrors .Wrap (err , fmt .Sprintf ("xtrabackup failed with error. Output=%s" , sterrOutput ))
463
451
}
464
452
465
- posOutput := posBuilder .String ()
466
- replicationPosition , rerr := findReplicationPosition (posOutput , flavor , params .Logger )
453
+ replicationPosition , rerr := findReplicationPositionFromXtrabackupInfo (params .Cnf .TmpDir , flavor , params .Logger )
467
454
if rerr != nil {
468
455
return replicationPosition , vterrors .Wrap (rerr , "backup failed trying to find replication position" )
469
456
}
@@ -751,6 +738,22 @@ func (be *XtrabackupEngine) extractFiles(ctx context.Context, logger logutil.Log
751
738
return nil
752
739
}
753
740
741
+ func findReplicationPositionFromXtrabackupInfo (directory , flavor string , logger logutil.Logger ) (replication.Position , error ) {
742
+ f , err := os .Open (path .Join (directory , xtrabackupInfoFile ))
743
+ if err != nil {
744
+ return replication.Position {}, vterrors .Errorf (vtrpc .Code_INVALID_ARGUMENT ,
745
+ "couldn't open %q to read GTID position" , path .Join (directory , xtrabackupInfoFile ))
746
+ }
747
+ defer f .Close ()
748
+
749
+ contents , err := io .ReadAll (f )
750
+ if err != nil {
751
+ return replication.Position {}, vterrors .Errorf (vtrpc .Code_INVALID_ARGUMENT , "couldn't read GTID position from %q" , f .Name ())
752
+ }
753
+
754
+ return findReplicationPosition (string (contents ), flavor , logger )
755
+ }
756
+
754
757
var xtrabackupReplicationPositionRegexp = regexp .MustCompile (`GTID of the last change '([^']*)'` )
755
758
756
759
func findReplicationPosition (input , flavor string , logger logutil.Logger ) (replication.Position , error ) {
0 commit comments