Translated using Weblate (Tatar)
[phpmyadmin.git] / server_replication.php
blobfa4696ce202978278c1752e63ec120112e959bfe
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package PhpMyAdmin
6 */
8 /**
11 require_once 'libraries/common.inc.php';
13 /**
14 * Does the common work
16 $response = PMA_Response::getInstance();
17 $header = $response->getHeader();
18 $scripts = $header->getScripts();
19 $scripts->addFile('server_privileges.js');
20 $scripts->addFile('replication.js');
22 require 'libraries/server_common.inc.php';
23 require 'libraries/replication.inc.php';
24 require 'libraries/replication_gui.lib.php';
26 /**
27 * Checks if the user is allowed to do what he tries to...
29 if (! $is_superuser) {
30 echo '<h2>' . "\n"
31 . PMA_Util::getIcon('s_replication.png')
32 . __('Replication') . "\n"
33 . '</h2>' . "\n";
34 PMA_Message::error(__('No Privileges'))->display();
35 exit;
38 /**
39 * Sets globals from $_REQUEST
41 $request_params = array(
42 'hostname',
43 'mr_adduser',
44 'mr_configure',
45 'pma_pw',
46 'port',
47 'repl_clear_scr',
48 'repl_data',
49 'sl_configure',
50 'slave_changemaster',
51 'sr_skip_errors_count',
52 'sr_slave_action',
53 'sr_slave_control_parm',
54 'sr_slave_server_control',
55 'sr_slave_skip_error',
56 'sr_take_action',
57 'url_params',
58 'username'
61 foreach ($request_params as $one_request_param) {
62 if (isset($_REQUEST[$one_request_param])) {
63 $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
67 /**
68 * Handling control requests
70 if (isset($GLOBALS['sr_take_action'])) {
71 $refresh = false;
72 if (isset($GLOBALS['slave_changemaster'])) {
73 $_SESSION['replication']['m_username'] = $sr['username'] = PMA_Util::sqlAddSlashes($GLOBALS['username']);
74 $_SESSION['replication']['m_password'] = $sr['pma_pw'] = PMA_Util::sqlAddSlashes($GLOBALS['pma_pw']);
75 $_SESSION['replication']['m_hostname'] = $sr['hostname'] = PMA_Util::sqlAddSlashes($GLOBALS['hostname']);
76 $_SESSION['replication']['m_port'] = $sr['port'] = PMA_Util::sqlAddSlashes($GLOBALS['port']);
77 $_SESSION['replication']['m_correct'] = '';
78 $_SESSION['replication']['sr_action_status'] = 'error';
79 $_SESSION['replication']['sr_action_info'] = __('Unknown error');
81 // Attempt to connect to the new master server
82 $link_to_master = PMA_replication_connect_to_master(
83 $sr['username'], $sr['pma_pw'], $sr['hostname'], $sr['port']
86 if (! $link_to_master) {
87 $_SESSION['replication']['sr_action_status'] = 'error';
88 $_SESSION['replication']['sr_action_info'] = sprintf(
89 __('Unable to connect to master %s.'),
90 htmlspecialchars($sr['hostname'])
92 } else {
93 // Read the current master position
94 $position = PMA_replication_slave_bin_log_master($link_to_master);
96 if (empty($position)) {
97 $_SESSION['replication']['sr_action_status'] = 'error';
98 $_SESSION['replication']['sr_action_info'] = __('Unable to read master log position. Possible privilege problem on master.');
99 } else {
100 $_SESSION['replication']['m_correct'] = true;
102 if (! PMA_replication_slave_change_master($sr['username'], $sr['pma_pw'], $sr['hostname'], $sr['port'], $position, true, false)) {
103 $_SESSION['replication']['sr_action_status'] = 'error';
104 $_SESSION['replication']['sr_action_info'] = __('Unable to change master');
105 } else {
106 $_SESSION['replication']['sr_action_status'] = 'success';
107 $_SESSION['replication']['sr_action_info'] = sprintf(
108 __('Master server changed successfully to %s'),
109 htmlspecialchars($sr['hostname'])
114 } elseif (isset($GLOBALS['sr_slave_server_control'])) {
115 if ($GLOBALS['sr_slave_action'] == 'reset') {
116 PMA_replication_slave_control("STOP");
117 PMA_DBI_try_query("RESET SLAVE;");
118 PMA_replication_slave_control("START");
119 } else {
120 PMA_replication_slave_control(
121 $GLOBALS['sr_slave_action'],
122 $GLOBALS['sr_slave_control_parm']
125 $refresh = true;
127 } elseif (isset($GLOBALS['sr_slave_skip_error'])) {
128 $count = 1;
129 if (isset($GLOBALS['sr_skip_errors_count'])) {
130 $count = $GLOBALS['sr_skip_errors_count'] * 1;
132 PMA_replication_slave_control("STOP");
133 PMA_DBI_try_query("SET GLOBAL SQL_SLAVE_SKIP_COUNTER = ".$count.";");
134 PMA_replication_slave_control("START");
138 if ($refresh) {
139 Header("Location: server_replication.php" . PMA_generate_common_url($GLOBALS['url_params']));
141 unset($refresh);
145 echo '<div id="replication">';
146 echo ' <h2>';
147 echo ' ' . PMA_Util::getImage('s_replication.png');
148 echo __('Replication');
149 echo ' </h2>';
151 // Display error messages
152 if (isset($_SESSION['replication']['sr_action_status'])
153 && isset($_SESSION['replication']['sr_action_info'])
155 if ($_SESSION['replication']['sr_action_status'] == 'error') {
156 PMA_Message::error($_SESSION['replication']['sr_action_info'])->display();
157 $_SESSION['replication']['sr_action_status'] = 'unknown';
158 } elseif ($_SESSION['replication']['sr_action_status'] == 'success') {
159 PMA_Message::success($_SESSION['replication']['sr_action_info'])->display();
160 $_SESSION['replication']['sr_action_status'] = 'unknown';
164 if ($server_master_status) {
165 if (! isset($GLOBALS['repl_clear_scr'])) {
166 echo '<fieldset>';
167 echo '<legend>' . __('Master replication') . '</legend>';
168 echo __('This server is configured as master in a replication process.');
169 echo '<ul>';
170 echo ' <li><a href="#" id="master_status_href">' . __('Show master status') . '</a>';
171 PMA_replication_print_status_table('master', true, false);
172 echo ' </li>';
174 echo ' <li><a href="#" id="master_slaves_href">' . __('Show connected slaves') . '</a>';
175 PMA_replication_print_slaves_table(true);
176 echo ' </li>';
178 $_url_params = $GLOBALS['url_params'];
179 $_url_params['mr_adduser'] = true;
180 $_url_params['repl_clear_scr'] = true;
182 echo ' <li><a href="server_replication.php' . PMA_generate_common_url($_url_params) . '" id="master_addslaveuser_href">';
183 echo __('Add slave replication user') . '</a></li>';
186 // Display 'Add replication slave user' form
187 if (isset($GLOBALS['mr_adduser'])) {
188 PMA_replication_gui_master_addslaveuser();
189 } elseif (! isset($GLOBALS['repl_clear_scr'])) {
190 echo "</ul>";
191 echo "</fieldset>";
193 } elseif (! isset($GLOBALS['mr_configure']) && ! isset($GLOBALS['repl_clear_scr'])) {
194 $_url_params = $GLOBALS['url_params'];
195 $_url_params['mr_configure'] = true;
197 echo '<fieldset>';
198 echo '<legend>' . __('Master replication') . '</legend>';
199 echo sprintf(__('This server is not configured as master in a replication process. Would you like to <a href="%s">configure</a> it?'), 'server_replication.php' . PMA_generate_common_url($_url_params));
200 echo '</fieldset>';
203 if (isset($GLOBALS['mr_configure'])) {
204 // Render the 'Master configuration' section
205 echo '<fieldset>';
206 echo '<legend>' . __('Master configuration') . '</legend>';
207 echo __('This server is not configured as master server in a replication process. You can choose from either replicating all databases and ignoring certain (useful if you want to replicate majority of databases) or you can choose to ignore all databases by default and allow only certain databases to be replicated. Please select the mode:') . '<br /><br />';
209 echo '<select name="db_type" id="db_type">';
210 echo '<option value="all">' . __('Replicate all databases; Ignore:') . '</option>';
211 echo '<option value="ign">' . __('Ignore all databases; Replicate:') . '</option>';
212 echo '</select>';
213 echo '<br /><br />';
214 echo __('Please select databases:') . '<br />';
215 echo PMA_replication_db_multibox();
216 echo '<br /><br />';
217 echo __('Now, add the following lines at the end of [mysqld] section in your my.cnf and please restart the MySQL server afterwards.') . '<br />';
218 echo '<pre id="rep"></pre>';
219 echo __('Once you restarted MySQL server, please click on Go button. Afterwards, you should see a message informing you, that this server <b>is</b> configured as master');
220 echo '</fieldset>';
221 echo '<fieldset class="tblFooters">';
222 echo ' <form method="post" action="server_replication.php" >';
223 echo PMA_generate_common_hidden_inputs('', '');
224 echo ' <input type="submit" value="' . __('Go') . '" id="goButton" />';
225 echo ' </form>';
226 echo '</fieldset>';
228 exit;
231 echo '</div>';
233 if (! isset($GLOBALS['repl_clear_scr'])) {
234 // Render the 'Slave configuration' section
235 echo '<fieldset>';
236 echo '<legend>' . __('Slave replication') . '</legend>';
237 if ($server_slave_status) {
238 echo '<div id="slave_configuration_gui">';
240 $_url_params = $GLOBALS['url_params'];
241 $_url_params['sr_take_action'] = true;
242 $_url_params['sr_slave_server_control'] = true;
244 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') {
245 $_url_params['sr_slave_action'] = 'start';
246 } else {
247 $_url_params['sr_slave_action'] = 'stop';
250 $_url_params['sr_slave_control_parm'] = 'IO_THREAD';
251 $slave_control_io_link = 'server_replication.php' . PMA_generate_common_url($_url_params);
253 if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') {
254 $_url_params['sr_slave_action'] = 'start';
255 } else {
256 $_url_params['sr_slave_action'] = 'stop';
259 $_url_params['sr_slave_control_parm'] = 'SQL_THREAD';
260 $slave_control_sql_link = 'server_replication.php' . PMA_generate_common_url($_url_params);
262 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No'
263 || $server_slave_replication[0]['Slave_SQL_Running'] == 'No'
265 $_url_params['sr_slave_action'] = 'start';
266 } else {
267 $_url_params['sr_slave_action'] = 'stop';
270 $_url_params['sr_slave_control_parm'] = null;
271 $slave_control_full_link = 'server_replication.php' . PMA_generate_common_url($_url_params);
273 $_url_params['sr_slave_action'] = 'reset';
274 $slave_control_reset_link = 'server_replication.php' . PMA_generate_common_url($_url_params);
276 $_url_params = $GLOBALS['url_params'];
277 $_url_params['sr_slave_skip_error'] = true;
278 $slave_skip_error_link = 'server_replication.php' . PMA_generate_common_url($_url_params);
280 if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') {
281 PMA_Message::error(__('Slave SQL Thread not running!'))->display();
283 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') {
284 PMA_Message::error(__('Slave IO Thread not running!'))->display();
287 $_url_params = $GLOBALS['url_params'];
288 $_url_params['sl_configure'] = true;
289 $_url_params['repl_clear_scr'] = true;
291 $reconfiguremaster_link = 'server_replication.php' . PMA_generate_common_url($_url_params);
293 echo __('Server is configured as slave in a replication process. Would you like to:');
294 echo '<br />';
295 echo '<ul>';
296 echo ' <li><a href="#" id="slave_status_href">' . __('See slave status table') . '</a>';
297 echo PMA_replication_print_status_table('slave', true, false);
298 echo ' </li>';
300 echo ' <li><a href="#" id="slave_control_href">' . __('Control slave:') . '</a>';
301 echo ' <div id="slave_control_gui" style="display: none">';
302 echo ' <ul>';
303 echo ' <li><a href="'. $slave_control_full_link . '">' . (($server_slave_replication[0]['Slave_IO_Running'] == 'No' || $server_slave_replication[0]['Slave_SQL_Running'] == 'No') ? __('Full start') : __('Full stop')) . ' </a></li>';
304 echo ' <li><a href="'. $slave_control_reset_link . '">' . __('Reset slave') . '</a></li>';
305 if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') {
306 echo ' <li><a href="' . $slave_control_sql_link . '">' . __('Start SQL Thread only') . '</a></li>';
307 } else {
308 echo ' <li><a href="' . $slave_control_sql_link . '">' . __('Stop SQL Thread only') . '</a></li>';
310 if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') {
311 echo ' <li><a href="' . $slave_control_io_link . '">' . __('Start IO Thread only') . '</a></li>';
312 } else {
313 echo ' <li><a href="' . $slave_control_io_link . '">' . __('Stop IO Thread only') . '</a></li>';
315 echo ' </ul>';
316 echo ' </div>';
317 echo ' </li>';
318 echo ' <li><a href="#" id="slave_errormanagement_href">' . __('Error management:') . '</a>';
319 echo ' <div id="slave_errormanagement_gui" style="display: none">';
320 PMA_Message::error(__('Skipping errors might lead into unsynchronized master and slave!'))->display();
321 echo ' <ul>';
322 echo ' <li><a href="' . $slave_skip_error_link . '">' . __('Skip current error') . '</a></li>';
323 echo ' <li>' . __('Skip next');
324 echo ' <form method="post" action="server_replication.php">';
325 echo PMA_generate_common_hidden_inputs('', '');
326 echo ' <input type="text" name="sr_skip_errors_count" value="1" style="width: 30px" />' . __('errors.');
327 echo ' <input type="submit" name="sr_slave_skip_error" value="' . __('Go') . '" />';
328 echo ' <input type="hidden" name="sr_take_action" value="1" />';
329 echo ' </form></li>';
330 echo ' </ul>';
331 echo ' </div>';
332 echo ' </li>';
333 echo ' <li><a href="' . $reconfiguremaster_link . '">' . __('Change or reconfigure master server') . '</a></li>';
334 echo '</ul>';
335 echo '</div>';
337 } elseif (! isset($GLOBALS['sl_configure'])) {
338 $_url_params = $GLOBALS['url_params'];
339 $_url_params['sl_configure'] = true;
340 $_url_params['repl_clear_scr'] = true;
342 echo sprintf(__('This server is not configured as slave in a replication process. Would you like to <a href="%s">configure</a> it?'), 'server_replication.php' . PMA_generate_common_url($_url_params));
344 echo '</fieldset>';
346 if (isset($GLOBALS['sl_configure'])) {
347 PMA_replication_gui_changemaster("slave_changemaster");