大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
小编给大家分享一下MySQL中xtrabackup原理、备份日志分析、备份信息获取的示例分析,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
成都创新互联公司-专业网站定制、快速模板网站建设、高性价比南充网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式南充网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖南充地区。费用合理售后完善,10余年实体公司更值得信赖。
一、 xtrabackup备份恢复工作原理:
InnoDB引擎很大程度上与Oracle类似,使用redo,undo机制,XtraBackup在备份的时候,以read-write模式打开innodb的数据文件,然后对其进行复制。与此同时,XtraBackup还有另外一个线程监视着transactions log,一旦log发生变化,就把变化过的log pages复制走,直到全部innoDB数据文件复制完成之后,停止监控log buffer及日志复制。如果log buffer没有及时写出将被日志的循环写特性覆盖。xtrabackup在启动时会记住log sequence number(LSN),然后一页一页地复制InnoDB的数据。
xtrabackup在恢复期间对提交的事务前滚,未提交或失败的事务进行回滚,从而保证数据的一致性。因此对于InnoDB表在备份期间不会锁表。由于XtraBackup其内置的InnoDB库打开文件的时候是rw的,所以运行XtraBackup的用户,必须对InnoDB的数据文件具有读写权限。
补充:
1.
在备份innodb page的过程中,XtraBackup每次读写1MB的数据,1MB/16KB=64个page。这个不可配置。读1MB数据之 后,XtraBackup一页一页地遍历这1MB数据,使用innodb的buf_page_is_corrupted()函数检查此页的数据是否正常, 如果数据不正常,就重新读取这一页,最多重新读取10次,如果还是失败,备份就失败了,退出。在复制transactions log的时候,每次读写512KB的数据。同样不可以配置。
2. 如果要使用一个最小权限的用户进行备份,则可基于如下命令创建此类用户:
mysql> CREATE USER 'bkuser'@'localhost' IDENTIFIED BY 'secret';
mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'bkuser';
mysql> GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'bkuser'@'localhost';
mysql> FLUSH PRIVILEGES;
二、 完全备份演示及日志分析:
[root@mysql01 full]# innobackupex --user=root --password=oracle /xtrabackup/full/
170602 20:24:02 innobackupex: Starting the backup operation
IMPORTANT: Please check that the backup run completes successfully.
At the end of a successful backup run innobackupex
prints "completed OK!".
170602 20:24:02 Connecting to MySQL server host: localhost, user: root, password: set, port: 3306, socket: not set
Using server version 5.6.25-log
innobackupex version 2.4.7 based on MySQL server 5.7.13 Linux (x86_64) (revision id: 6f7a799)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /var/lib/mysql/
xtrabackup: open files limit requested 0, set to 1024
## 从配置文件获取有关innodb的配置信息
xtrabackup: using the following InnoDB configuration:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:12M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 50331648
InnoDB: Number of pools: 1
## 扫描innodb日志lsn并复制inndodb系统表空间
170602 20:24:02 >> log scanned up to (1626057)
xtrabackup: Generating a list of tablespaces
InnoDB: Allocated tablespace ID 1 for mysql/innodb_table_stats, old maximum was 0
170602 20:24:02 [01] Copying ./ibdata1 to /xtrabackup/full/2017-06-02_20-24-02/ibdata1
170602 20:24:02 [01] ...done
170602 20:24:03 [01] Copying ./mysql/innodb_table_stats.ibd to /xtrabackup/full/2017-06-02_20-24-02/mysql/innodb_table_stats.ibd
。。。。
170602 20:24:03 [01] ...done
170602 20:24:03 [01] Copying ./mysql/slave_master_info.ibd to /xtrabackup/full/2017-06-02_20-24-02/mysql/slave_master_info.ibd
170602 20:24:03 [01] ...done
170602 20:24:03 >> log scanned up to (1626057)
## 缓冲写出到数据文件并锁表
170602 20:24:03 Executing FLUSH NO_WRITE_TO_BINLOG TABLES...
170602 20:24:03 Executing FLUSH TABLES WITH READ LOCK...
## 开始复制非innodb表及相关文件
170602 20:24:03 Starting to backup non-InnoDB tables and files
170602 20:24:03 [01] Copying ./mysql/help_category.MYI to /xtrabackup/full/2017-06-02_20-24-02/mysql/help_category.MYI
170602 20:24:03 [01] ...done
170602 20:24:03 [01] Copying ./mysql/plugin.frm to /xtrabackup/full/2017-06-02_20-24-02/mysql/plugin.frm
170602 20:24:03 [01] ...done
170602 20:24:03 [01] Copying ./mysql/plugin.MYD to /xtrabackup/full/2017-06-02_20-24-02/mysql/plugin.MYD
。。。。
170602 20:24:05 [01] Copying ./performance_schema/events_stages_history_long.frm to /xtrabackup/full/2017-06-02_20-24-02/performance_schema/events_stages_history_long.frm
170602 20:24:05 [01] ...done
## 结束复制非innodb表及相关文件
170602 20:24:05 Finished backing up non-InnoDB tables and files
170602 20:24:05 [00] Writing xtrabackup_binlog_info
170602 20:24:05 [00] ...done
## 强制将commit log刷新到redo,保证事务是完整的
170602 20:24:05 Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
## 获取最新的lsn
xtrabackup: The latest check point (for incremental): '1626057'
xtrabackup: Stopping log copying thread.
.170602 20:24:05 >> log scanned up to (1626057)
## 释放锁
170602 20:24:05 Executing UNLOCK TABLES
170602 20:24:05 All tables unlocked
## 列出备份位置
170602 20:24:05 Backup created in directory '/xtrabackup/full/2017-06-02_20-24-02/'
## 列出binlog的位置
MySQL binlog position: filename 'binlog.000001', position '120'
170602 20:24:05 [00] Writing backup-my.cnf
170602 20:24:05 [00] ...done
170602 20:24:05 [00] Writing xtrabackup_info
170602 20:24:05 [00] ...done
xtrabackup: Transaction log of lsn (1626057) to (1626057) was copied.
170602 20:24:05 completed OK!
三、获取备份的相关信息
1. 查看备份期间生成的文件
[root@mysql01 full]# ls /xtrabackup/full/2017-06-02_20-24-02/
backup-my.cnf performance_schema xtrabackup_checkpoints
ibdata1 test xtrabackup_info
mysql xtrabackup_binlog_info xtrabackup_logfile
说明:
2. 查看备份有关的总体信息
[root@mysql01 full]# more /xtrabackup/full/2017-06-02_20-24-02/xtrabackup_info
uuid = 5e8841af-478e-11e7-a0d7-000c2944297a
name =
tool_name = innobackupex
tool_command = --user=root --password=... /xtrabackup/full/
tool_version = 2.4.7
ibbackup_version = 2.4.7
server_version = 5.6.25-log
start_time = 2017-06-02 20:24:02
end_time = 2017-06-02 20:24:05
lock_time = 0
binlog_pos = filename 'binlog.000001', position '120'
innodb_from_lsn = 0
innodb_to_lsn = 1626057
partial = N
说明>xtrabackup_info 记录: 整个备份信息的概要
3. 查看备份检查点的相关信息
[root@mysql01 full]# more /xtrabackup/full/2017-06-02_20-24-02/xtrabackup_checkpoints
backup_type = full-backuped
from_lsn = 0
to_lsn = 1626057
last_lsn = 1626057
compact = 0
recover_binlog_info = 0
说明>xtrabackup_checkpoints 记录:备份类型(如完全或增量)、备份状态(如是否已经为prepared状态)和LSN(日志序列号)范围信息;
4. 查看备份binlog有关的信息
[root@mysql01 full]# more /xtrabackup/full/2017-06-02_20-24-02/xtrabackup_binlog_info
binlog.000001 120
说明>xtrabackup_binlog_info记录: mysql服务器当前正在使用的二进制日志文件及至备份这一刻为止二进制日志事件的位置。
5. 查看备份命令的配置选项信息
[root@mysql01 full]# more /xtrabackup/full/2017-06-02_20-24-02/backup-my.cnf
# This MySQL options file was generated by innobackupex.
# The MySQL server
[mysqld]
innodb_checksum_algorithm=innodb
innodb_log_checksum_algorithm=innodb
innodb_data_file_path=ibdata1:12M:autoextend
innodb_log_files_in_group=2
innodb_log_file_size=50331648
innodb_fast_checksum=false
innodb_page_size=16384
innodb_log_block_size=512
innodb_undo_directory=.
innodb_undo_tablespaces=0
以上是“mysql中xtrabackup原理、备份日志分析、备份信息获取的示例分析”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!