@@ -525,6 +525,7 @@ func (e *TaskExecutor) deploySingleInstance(ctx context.Context, req DeployTaskR
525525 osUser , _ := req .Config ["os_user" ].(string )
526526 mysqlUser , _ := req .Config ["mysql_user" ].(string )
527527 mysqlPass , _ := req .Config ["mysql_pass" ].(string )
528+ serverID := configInt (req .Config , "server_id" )
528529
529530 // MGR配置参数
530531 installType , _ := req .Config ["install_type" ].(string )
@@ -542,6 +543,9 @@ func (e *TaskExecutor) deploySingleInstance(ctx context.Context, req DeployTaskR
542543 if port == 0 {
543544 port = 3306
544545 }
546+ if serverID == 0 {
547+ serverID = port
548+ }
545549 if dataDir == "" {
546550 dataDir = fmt .Sprintf ("/data/mysql/%d" , port )
547551 }
@@ -653,7 +657,7 @@ func (e *TaskExecutor) deploySingleInstance(ctx context.Context, req DeployTaskR
653657 "--daemonize" ,
654658 "--datadir=" + dataDir ,
655659 "--port=" + fmt .Sprintf ("%d" , port ),
656- "--server-id=" + fmt .Sprintf ("%d" , port ),
660+ "--server-id=" + fmt .Sprintf ("%d" , serverID ),
657661 "--log-bin=mysql-bin" ,
658662 "--binlog-format=ROW" ,
659663 "--gtid-mode=ON" ,
@@ -1030,7 +1034,7 @@ func (e *TaskExecutor) configureMaster(ctx context.Context, config MasterSlaveCo
10301034 _ = mysqlExecCommand (ctx , config .MasterHost , config .MasterPort , config .MySQLUser , config .MySQLPass ,
10311035 fmt .Sprintf ("ALTER USER '%s'@'%%' IDENTIFIED WITH mysql_native_password BY '%s';" , escapeSQL (config .ReplicateUser ), escapeSQL (config .ReplicatePass ))).Run ()
10321036
1033- if out , err := setServerID (ctx , config .MasterHost , config .MasterPort , config .MySQLUser , config .MySQLPass , 1 ); err != nil {
1037+ if out , err := setServerID (ctx , config .MasterHost , config .MasterPort , config .MySQLUser , config .MySQLPass , config . ServerID ); err != nil {
10341038 return & TaskResult {
10351039 Status : "failed" ,
10361040 Progress : 30 ,
@@ -1048,7 +1052,7 @@ func (e *TaskExecutor) configureMaster(ctx context.Context, config MasterSlaveCo
10481052}
10491053
10501054func (e * TaskExecutor ) configureSlave (ctx context.Context , config MasterSlaveConfig ) * TaskResult {
1051- if out , err := setServerID (ctx , config .SlaveHost , config .SlavePort , config .MySQLUser , config .MySQLPass , config .ServerID + 2 ); err != nil {
1055+ if out , err := setServerID (ctx , config .SlaveHost , config .SlavePort , config .MySQLUser , config .MySQLPass , config .ServerID ); err != nil {
10521056 return & TaskResult {
10531057 Status : "failed" ,
10541058 Progress : 50 ,
@@ -1565,13 +1569,18 @@ func (e *TaskExecutor) executeGTIDIncrementalBackup(ctx context.Context, config
15651569 }, nil
15661570 }
15671571 baseGTID , err := parseGTIDFromDump (config .BaseBackupPath )
1572+ gtidWarning := ""
15681573 if err != nil {
1569- return & TaskResult {
1570- Status : "failed" ,
1571- Progress : 0 ,
1572- Message : fmt .Sprintf ("parse GTID from base mysqldump failed: %v" , err ),
1573- Timestamp : time .Now (),
1574- }, nil
1574+ if strings .Contains (err .Error (), "GTID_PURGED not found" ) {
1575+ gtidWarning = "base mysqldump has no GTID_PURGED; mysqlbinlog will not exclude transactions already included in the base dump"
1576+ } else {
1577+ return & TaskResult {
1578+ Status : "failed" ,
1579+ Progress : 0 ,
1580+ Message : fmt .Sprintf ("parse GTID from base mysqldump failed: %v" , err ),
1581+ Timestamp : time .Now (),
1582+ }, nil
1583+ }
15751584 }
15761585 binlogs , err := fetchBinaryLogFiles (ctx , config )
15771586 if err != nil {
@@ -1608,9 +1617,11 @@ func (e *TaskExecutor) executeGTIDIncrementalBackup(ctx context.Context, config
16081617 "--port=" + fmt .Sprintf ("%d" , config .MySQLPort ),
16091618 "--user=" + defaultString (config .MySQLUser , "root" ),
16101619 "--password=" + config .MySQLPass ,
1611- "--exclude-gtids=" + baseGTID ,
16121620 "--result-file=" + backupFile ,
16131621 }
1622+ if strings .TrimSpace (baseGTID ) != "" {
1623+ args = append (args , "--exclude-gtids=" + baseGTID )
1624+ }
16141625 args = append (args , binlogs ... )
16151626 cmd := exec .CommandContext (ctx , "mysqlbinlog" , args ... )
16161627 if out , err := cmd .CombinedOutput (); err != nil {
@@ -1647,21 +1658,29 @@ func (e *TaskExecutor) executeGTIDIncrementalBackup(ctx context.Context, config
16471658 Timestamp : time .Now (),
16481659 }, nil
16491660 }
1661+ message := fmt .Sprintf ("Incremental backup completed successfully. Path: %s, Checksum: %s" , backupFile , checksum )
1662+ if gtidWarning != "" {
1663+ message += ". " + gtidWarning
1664+ }
1665+ data := map [string ]any {
1666+ "backup_path" : backupFile ,
1667+ "backup_type" : config .BackupType ,
1668+ "backup_method" : "mysqlbinlog" ,
1669+ "base_backup_path" : config .BaseBackupPath ,
1670+ "base_backup_label" : config .BaseBackupLabel ,
1671+ "base_backup_gtid" : baseGTID ,
1672+ "file_size" : sizeBytes ,
1673+ "checksum" : checksum ,
1674+ }
1675+ if gtidWarning != "" {
1676+ data ["gtid_warning" ] = gtidWarning
1677+ }
16501678 return & TaskResult {
16511679 Status : "completed" ,
16521680 Progress : 100 ,
1653- Message : fmt . Sprintf ( "Incremental backup completed successfully. Path: %s, Checksum: %s" , backupFile , checksum ) ,
1681+ Message : message ,
16541682 Timestamp : time .Now (),
1655- Data : map [string ]any {
1656- "backup_path" : backupFile ,
1657- "backup_type" : config .BackupType ,
1658- "backup_method" : "mysqlbinlog" ,
1659- "base_backup_path" : config .BaseBackupPath ,
1660- "base_backup_label" : config .BaseBackupLabel ,
1661- "base_backup_gtid" : baseGTID ,
1662- "file_size" : sizeBytes ,
1663- "checksum" : checksum ,
1664- },
1683+ Data : data ,
16651684 }, nil
16661685}
16671686
0 commit comments