replication.inc.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Replication helpers
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. use PhpMyAdmin\Replication;
  12. /**
  13. * get master replication from server
  14. */
  15. $server_master_replication = $GLOBALS['dbi']->fetchResult('SHOW MASTER STATUS');
  16. /**
  17. * set selected master server
  18. */
  19. if (! empty($_POST['master_connection'])) {
  20. /**
  21. * check for multi-master replication functionality
  22. */
  23. $server_slave_multi_replication = $GLOBALS['dbi']->fetchResult(
  24. 'SHOW ALL SLAVES STATUS'
  25. );
  26. if ($server_slave_multi_replication) {
  27. $GLOBALS['dbi']->query(
  28. "SET @@default_master_connection = '"
  29. . $GLOBALS['dbi']->escapeString(
  30. $_POST['master_connection']
  31. ) . "'"
  32. );
  33. $GLOBALS['url_params']['master_connection'] = $_POST['master_connection'];
  34. }
  35. }
  36. /**
  37. * get slave replication from server
  38. */
  39. $server_slave_replication = $GLOBALS['dbi']->fetchResult('SHOW SLAVE STATUS');
  40. /**
  41. * replication types
  42. */
  43. $replication_types = array('master', 'slave');
  44. /**
  45. * define variables for master status
  46. */
  47. $master_variables = array(
  48. 'File',
  49. 'Position',
  50. 'Binlog_Do_DB',
  51. 'Binlog_Ignore_DB',
  52. );
  53. /**
  54. * Define variables for slave status
  55. */
  56. $slave_variables = array(
  57. 'Slave_IO_State',
  58. 'Master_Host',
  59. 'Master_User',
  60. 'Master_Port',
  61. 'Connect_Retry',
  62. 'Master_Log_File',
  63. 'Read_Master_Log_Pos',
  64. 'Relay_Log_File',
  65. 'Relay_Log_Pos',
  66. 'Relay_Master_Log_File',
  67. 'Slave_IO_Running',
  68. 'Slave_SQL_Running',
  69. 'Replicate_Do_DB',
  70. 'Replicate_Ignore_DB',
  71. 'Replicate_Do_Table',
  72. 'Replicate_Ignore_Table',
  73. 'Replicate_Wild_Do_Table',
  74. 'Replicate_Wild_Ignore_Table',
  75. 'Last_Errno',
  76. 'Last_Error',
  77. 'Skip_Counter',
  78. 'Exec_Master_Log_Pos',
  79. 'Relay_Log_Space',
  80. 'Until_Condition',
  81. 'Until_Log_File',
  82. 'Until_Log_Pos',
  83. 'Master_SSL_Allowed',
  84. 'Master_SSL_CA_File',
  85. 'Master_SSL_CA_Path',
  86. 'Master_SSL_Cert',
  87. 'Master_SSL_Cipher',
  88. 'Master_SSL_Key',
  89. 'Seconds_Behind_Master',
  90. );
  91. /**
  92. * define important variables, which need to be watched for
  93. * correct running of replication in slave mode
  94. *
  95. * @usedby PhpMyAdmin\ReplicationGui::getHtmlForReplicationStatusTable()
  96. */
  97. // TODO change to regexp or something, to allow for negative match.
  98. // To e.g. highlight 'Last_Error'
  99. //
  100. $slave_variables_alerts = array(
  101. 'Slave_IO_Running' => 'No',
  102. 'Slave_SQL_Running' => 'No',
  103. );
  104. $slave_variables_oks = array(
  105. 'Slave_IO_Running' => 'Yes',
  106. 'Slave_SQL_Running' => 'Yes',
  107. );
  108. // check which replication is available and
  109. // set $server_{master/slave}_status and assign values
  110. // replication info is more easily passed to functions
  111. $GLOBALS['replication_info'] = array();
  112. foreach ($replication_types as $type) {
  113. if (count(${"server_{$type}_replication"}) > 0) {
  114. $GLOBALS['replication_info'][$type]['status'] = true;
  115. } else {
  116. $GLOBALS['replication_info'][$type]['status'] = false;
  117. }
  118. if ($GLOBALS['replication_info'][$type]['status']) {
  119. if ($type == "master") {
  120. Replication::fillInfo(
  121. $type, 'Do_DB', $server_master_replication[0],
  122. 'Binlog_Do_DB'
  123. );
  124. Replication::fillInfo(
  125. $type, 'Ignore_DB', $server_master_replication[0],
  126. 'Binlog_Ignore_DB'
  127. );
  128. } elseif ($type == "slave") {
  129. Replication::fillInfo(
  130. $type, 'Do_DB', $server_slave_replication[0],
  131. 'Replicate_Do_DB'
  132. );
  133. Replication::fillInfo(
  134. $type, 'Ignore_DB', $server_slave_replication[0],
  135. 'Replicate_Ignore_DB'
  136. );
  137. Replication::fillInfo(
  138. $type, 'Do_Table', $server_slave_replication[0],
  139. 'Replicate_Do_Table'
  140. );
  141. Replication::fillInfo(
  142. $type, 'Ignore_Table', $server_slave_replication[0],
  143. 'Replicate_Ignore_Table'
  144. );
  145. Replication::fillInfo(
  146. $type, 'Wild_Do_Table', $server_slave_replication[0],
  147. 'Replicate_Wild_Do_Table'
  148. );
  149. Replication::fillInfo(
  150. $type, 'Wild_Ignore_Table', $server_slave_replication[0],
  151. 'Replicate_Wild_Ignore_Table'
  152. );
  153. }
  154. }
  155. }