共计 5813 个字符,预计需要花费 15 分钟才能阅读完成。
行业资讯
数据库
MySQL 数据库
mysql 中 xtrabackup 原理、备份日志分析、备份信息获取的示例分析
丸趣 TV 小编给大家分享一下 mysql 中 xtrabackup 原理、备份日志分析、备份信息获取的示例分析,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
一、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 原理、备份日志分析、备份信息获取的示例分析”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道!