Дерево страниц
Перейти к концу метаданных
Переход к началу метаданных

One of the many ways to restore a replication in case of mysql-bin log loss is to use Percona Xtrabackup utility.

The advantage of using this method is that it does not require a MASTER server stop. The only condition is having binary logging enabled.


1) Install Xtrabackup utility

root@vagrant-ubuntu-trusty-64-test1111:~# apt install percona-xtrabackup


2) Prepare data for copying and create a database backup
To do that, create a new directory and copy files to it

root@vagrant-ubuntu-trusty-64-test1111:~/mysql# innobackupex --user=root --password=root /home/vagrant/mysql/


In the directory created, a new one with the current date will appear
3) When a backup is created, data is not yet ready for the restore. The logs to be restored may contain cancelled transactions. It is required to apply a change log to a data file

root@vagrant-ubuntu-trusty-64-test1111:~/mysql# innobackupex --user=root --password=root --apply-log /home/vagrant/mysql/2018-10-03_08-07-34/


When a backup is ready, copy data files to a SLAVE server
4) On the SLAVE server, stop mysql service and copy data to mysql directory.

root@vagrant-ubuntu-trusty-64-test4444:~/mysql# service mysql stop
root@vagrant-ubuntu-trusty-64-test4444:~/mysql# mv /var/lib/mysql /var/lib/mysql.old
root@vagrant-ubuntu-trusty-64-test4444:~/mysql# cp /home/vagrant/mysql/2018-10-03_08-07-34/ /var/lib/mysql
root@vagrant-ubuntu-trusty-64-test4444:~/mysql# chown -R mysql:mysql /var/lib/mysql
root@vagrant-ubuntu-trusty-64-test4444:~/mysql# service mysql start


5) Open mysql console, get the binary log's location and name. After that, configure replication on the SLAVE server.

root@vagrant-ubuntu-trusty-64-test4444:~/mysql# cat /home/vagrant/mysql/2018-10-03_08-07-34/xtrabackup_binlog_info
mysql-bin.002454    9311320


mysql>  STOP SLAVE;
mysql>  CHANGE MASTER TO MASTER_HOST='<ip_server1>', MASTER_USER='replication', MASTER_PASSWORD='password', MASTER_LOG_FILE='mysql-bin.002454', MASTER_LOG_POS=9311320;
mysql>  START SLAVE;


Check if replication is working

mysql> SHOW SLAVE STATUS\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: <ip_server1>
                  Master_User: replication
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.002455
          Read_Master_Log_Pos: 89717415
               Relay_Log_File: mysqld-relay-bin.000004
                Relay_Log_Pos: 89717561
        Relay_Master_Log_File: mysql-bin.002455
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table:
  • Нет меток