加入收藏 | 设为首页 | 会员中心 | 我要投稿 瑞安网 (https://www.ruian888.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

mysql中innobackupex备份和binlog日志完全恢复的示例解析

发布时间:2021-12-28 11:57:43 所属栏目:MySql教程 来源:互联网
导读:小编给大家分享一下mysql中innobackupex备份和binlog日志完全恢复的示例分析,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧! 前言: MySQL的完全恢复,我们可以借助于完整的
小编给大家分享一下mysql中innobackupex备份和binlog日志完全恢复的示例分析,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
 
前言:
MySQL的完全恢复,我们可以借助于完整的 备份+binlog 来将数据库恢复到故障点。
备份可以是热备与逻辑备份(mysqldump),只要备份与binlog是完整的,都可以实现完全恢复。
 
1. 准备实验环境
mysql> select version();
+------------+
| version() |
+------------+
| 5.6.25-log |
+------------+
1 row in set (0.00 sec)
mysql> create database com_rec;
Query OK, 1 row affected (0.00 sec)
mysql> use inc_rec;
Database changed
mysql> create table andy (id int);
Query OK, 0 rows affected (0.08 sec)
mysql> insert into andy values(1),(2);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
2. 全备
[root@mysql02 full]# innobackupex --defaults-file=/etc/my.cnf --user=root --password=oracle --port=3606 /xtrabackup/full/
xtrabackup: Transaction log of lsn (1662519) to (1662519) was copied.
170609 17:34:34 completed OK!
3. 查看全备生成文件
[root@mysql02 full]# ll /xtrabackup/full/
total 4
drwxr-x---. 6 root root 4096 Jun 9 17:34 2017-06-09_17-34-30
4. 模拟业务新数据
mysql> insert into andy values(3),(4);
Query OK, 2 rows affected (0.14 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
5. 增量备份
-- 创建存放增量备份目录并赋权
[root@mysql02 full]# mkdir -p /xtrabackup/incr/
[root@mysql02 full]# chown -R mysql:mysql /xtrabackup/incr/
[root@mysql02 full]# ll /xtrabackup/
total 8
drwxr-xr-x. 3 mysql mysql 4096 Jun 9 03:53 full
drwxr-xr-x. 2 mysql mysql 4096 Jun 9 04:00 incre
-- 正式开始增量备份
[root@mysql02 full]# innobackupex --defaults-file=/etc/my.cnf --user=root --password=oracle --incremental
--incremental-basedir=/xtrabackup/full/2017-06-09_17-34-30/ /xtrabackup/incr/
########################################下面是增量备份输出
。。。省略
xtrabackup: Transaction log of lsn (1665808) to (1665808) was copied.
170609 17:36:46 completed OK!
6. 再模拟新业务,该记录在保存在binlog,而不会存在于任何备份,这条记录用于验证完全恢复
mysql> insert into andy values(5);
Query OK, 1 row affected (0.00 sec)
7. 记下操作后的 position 点
mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000005 | 1104 | | | |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
8. 切换binlog日志
mysql> flush logs;
Query OK, 0 rows affected (0.00 sec)
9. 使用binlog events命令来查看我们最后insert的一条记录
mysql> show binlog events in 'binlog.000005';
+---------------+------+-------------+-----------+-------------+-----------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+---------------+------+-------------+-----------+-------------+-----------------------------------------------+
| binlog.000005 | 4 | Format_desc | 1 | 120 | Server ver: 5.6.25-log, Binlog ver: 4 |
| binlog.000005 | 120 | Query | 1 | 221 | drop database inc_rec |
| binlog.000005 | 221 | Query | 1 | 324 | create database com_rec |
| binlog.000005 | 324 | Query | 1 | 430 | use `com_rec`; create table andy (id int) |
| binlog.000005 | 430 | Query | 1 | 515 | BEGIN |
| binlog.000005 | 515 | Query | 1 | 625 | use `com_rec`; insert into andy values(1),(2) |
| binlog.000005 | 625 | Xid | 1 | 656 | COMMIT /* xid=67 */ |
| binlog.000005 | 656 | Query | 1 | 741 | BEGIN |
| binlog.000005 | 741 | Query | 1 | 851 | use `com_rec`; insert into andy values(3),(4) |
| binlog.000005 | 851 | Xid | 1 | 882 | COMMIT /* xid=81 */ |
| binlog.000005 | 882 | Query | 1 | 967 | BEGIN |
| binlog.000005 | 967 | Query | 1 | 1073 | use `com_rec`; insert into andy values(5) |
| binlog.000005 | 1073 | Xid | 1 | 1104 | COMMIT /* xid=96 */ |
| binlog.000005 | 1104 | Rotate | 1 | 1148 | binlog.000006;pos=4 |
+---------------+------+-------------+-----------+-------------+-----------------------------------------------+
14 rows in set (0.00 sec)
  
以上是“mysql中innobackupex备份和binlog日志完全恢复的示例分析”这篇文章的所有内容,感谢各位的阅读!

(编辑:瑞安网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读