xtrabackup 备份从库,建立新的从库 xtrabackup_slave_info 建立主库查看xtrabackup_binlog_info的pos位置重要

(1)参数理解
由M-S 搭建M-2S

--slave-info,会打印binary log的位置和master server名,并且以change master的方式写到xtrabackup_slave_info中。

--safe-slave-backup,为了保证复制状态的一致性,这个选项会关闭slave sql线程,等待直到SHOW STATUS 中的Slave_open_temp_tabls为了才启动备份。如果等待时间超过—safe-slave-backup-timeout就会报
错默认300秒。备份成功后 slave sql thread会自动启动。

(2)主-从,在从库上备份数据库,新建主库的一个从库
10.10.6.87   dg2 主
10.10.6.86   dg   从
10.10.6.90   dgt 从

主库的10.10.6.87 master的信息

mysql> show master status G;
*************************** 1. row ***************************
             File: mysql-bin.000025
         Position: 1046
     Binlog_Do_DB: 
 Binlog_Ignore_DB: mysql,information_schema
Executed_Gtid_Set: 
1 row in set (0.00 sec)


10.10.6.86 从库的master信息:
mysql> show master status G;
*************************** 1. row ***************************
             File: mysql-bin.000019
         Position: 680
     Binlog_Do_DB: 
 Binlog_Ignore_DB: mysql,information_schema
Executed_Gtid_Set: 
1 row in set (0.00 sec)


10.10.6.86 从库的信息:
mysql> show slave status G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.10.6.87
                  Master_User: rep
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000025
          Read_Master_Log_Pos: 1046
               Relay_Log_File: mysql-bin.000021
                Relay_Log_Pos: 1436
        Relay_Master_Log_File: mysql-bin.000025
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: mysql
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1522
              Relay_Log_Space: 1637
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 2
                  Master_UUID: 8f9e146f-0a18-11e7-810a-0050568833c8
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)
 

备库上备份整个库
[root@dg backup]# innobackupex  --defaults-file=/etc/my.cnf --user=backup --password='bc.123456'  --socket=/var/lib/mysql/mysql.sock    --slave-info  --safe-slave-backup   --no-timestamp  /backup/full

注意:
备份源库上恢复日志也可以不在备份源上   必要时加上reset slave all 或者加上reset master all
备份完成后,还不能用于恢复,一些未提交的事物需要恢复,需要恢复redo logo的数据,确保数据一致
[root@dg backup]# innobackupex --apply-log /backup/full


传输数据到新的备库
[root@dg backup]# scp  -r full/  dgt:/backup/


(3)在新建的S 恢复机清理目录
service  mysqld stop
mv  /var/lib/mysql /var/lib/mysql6


(4)拷贝数据文件到目录:
innobackupex --defaults-file=/etc/my.cnf --copy-back --rsync /backup/full


[root@dgt mysql]# chown  -R mysql.mysql  /var/lib/mysql
[root@dgt lib]# service mysqld start
[root@dgt lib]# cd   /backup/full

重点的重点,切记不要去查看show master status的pos位置,这是用xrabackup备份的,查看下面的位置
[root@dgt full]# cat  xtrabackup_slave_info
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000025', MASTER_LOG_POS=1046


(5) 修改从库的检查点位置
 CHANGE MASTER TO master_host='10.10.6.87', master_port=3306, master_user='rep',master_password='bc.123456', master_log_file='mysql-bin.000025', master_log_pos=1046; 


start  slave;

主库上的用户
  GRANT REPLICATION SLAVE ON *.* TO 'rep'@'10.10.6.%' IDENTIFIED BY 'bc.123456';

(6)查看状态


mysql> show slave status G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.10.6.87
                  Master_User: rep
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000025
          Read_Master_Log_Pos: 1046
               Relay_Log_File: mysql-bin.000003
                Relay_Log_Pos: 320
        Relay_Master_Log_File: mysql-bin.000025
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: mysql,information_schema
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1046
              Relay_Log_Space: 521
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 2
                  Master_UUID: 8f9e146f-0a18-11e7-810a-0050568833c8
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)
————————————————
版权声明:本文为CSDN博主「wluckdog」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wll_1017/article/details/70213115

原文地址:https://www.cnblogs.com/cheyunhua/p/14662311.html