实验机器一共两台:
虚拟机A
虚拟机B
现象:#
虚拟机A用XBK全备后,将全备文件拷贝到虚拟机B,在虚拟机B启动mysql,执行命令show master status
,发现GTID号没有自动生成。
当时使用的备份语句:
innobackupex --uesr=root --password=12345 -S /tmp/mysql.sock --no-timestamp /bak/full_`date +%F`
解决方法:#
- 第一种:在虚拟机B执行以下命令
reset master
set global gtid_purged='虚拟机A的GTID'
# 虚拟机A的GTID信息可以在备份文件中查到:xtrabackup_info
- 第二种:备份时添加
--slave-info
参数
这个参数的主要用途不是用于自动更新GTID信息,有兴趣的兄弟可以自行百度。
innobackupex --uesr=root --password=12345 --slave-info -S /tmp/mysql.sock --no-timestamp /bak/full_`date +%F`
# 备份之后,拷贝到虚拟机B的数据目录,启动数据库,自动会更新GTID信息
innobackupex --uesr=root --password=12345 -S /tmp/mysql.sock --no-timestamp /bak/full_`date +%F`
下面就是一个我经常用来备份全库时的语句:
innobackupex --defaults-file=/etc/my.cnf --user=root --password='123' --host=localhost --rsync --compress --compress-threads=5 --compress-chunk-size=64K --slave-info /root
下面我们就看帮助,看一下其中这个--slave-info的含义:
[root@zabbixsrvbjdb04 ~]# innobackupex --help |grep -C 5 slave
--slave-info
This option is useful when backing up a replication slave server. It
prints the binary log position and name of the master server. It
also writes this information to the "xtrabackup_slave_info" file as
a "CHANGE MASTER" command. A new slave for this master can be set up
by starting a slave server on this backup and issuing a "CHANGE
MASTER" command with the binary log position saved in the
"xtrabackup_slave_info" file.
以下就是我的理解:
在备份从库时,可以使用该参数, 加上--slave-info备份目录下会多生成一个xtrabackup_slave_info 文件, 这里会保存主日志文件以及偏移, 文件内容类似于:CHANGE MASTER TO MASTER_LOG_FILE='', MASTER_LOG_POS=0。
这个参数适用的场景:假设现在有主库A和从库B,目前想再添加一台备库C,并让备库C以主库A为master;因为主库A是生产库,压力一般比较大,所以我们就在备库B上备份一个数据库,然后把这个备份拿到C服务器上 并导入到C库,接下来再在C服务器上执行change master的命令:其中 master_host是A的ip,而master_log_file和master_log_pos就是这个xtrabackup_slave_info里面的值。不知道说明白了吗
--slave-info:该参数表示对slave进行备份的时候使用,打印出master的名字和binlog pos,同样将这些信息以change master的命令写入xtrabackup_slave_info文件。
注意事项:
假如从库开了多线程复制(slave_parallel_workers),但是没开启GTID,运行时会报错:
The --slave-info option requires GTID enabled for a multi-threaded slave.
XtraBackup的要求是要两者必须都开启,因此可以在备份开始前先设置成单线程复制,等备份结束之后再开启slave_parallel_workers参数,也可以直接开启GTID。