innobackupex Point-In-Time recovery
利用innobackupex结合全备和全备以后的binlog可以把mysql恢复到指定的时间点。
1.innobackupex全备
$innobackupex --defaults-file=/mysqlweb/mysql5.6/my.cnf -user=bkpuser -password=s3cret /home/mysqlweb
2.apply-log
$innobackupex --apply-log /home/mysqlweb/2014-10-27_14-57-31
3.恢复copy-back
恢复前的准备:
a)关闭mysql
b)清空mysql的datadir目录
c)删除ib_logfile*
$innobackupex --defaults-file=/mysqlweb/mysql5.6/my.cnf --copy-back /home/mysqlweb/2014-10-27_14-57-31/
4.重启mysql并登陆查询恢复前的数据
mysql> select * from lw.test;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
+----+------+
3 rows in set (0.00 sec)
5.查看可用的binary log和当前的binarylog
mysql> show binary logs;
+-----------------------+-----------+
| Log_name | File_size |
+-----------------------+-----------+
| binlog_98_3316.000001 | 3003 |
| binlog_98_3316.000002 | 612 |
| binlog_98_3316.000003 | 1098 |
| binlog_98_3316.000004 | 864 |
+-----------------------+-----------+
4 rows in set (0.00 sec)
mysql> show master status;
+-----------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------------+----------+--------------+------------------+-------------------+
| binlog_98_3316.000004 | 864 | | | |
+-----------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
6.确定要恢复的起位置和结束位置
$ mysqlbinlog binlog_98_3316.000001
7. 根据指定的起始位置和结束位置进行恢复
mysql> system mysqlbinlog binlog_98_3316.000001 --start-position=1854 --stop-position=2491|mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
8.检查恢复后的情况,比恢复前多了3条数据,这三条数据正式我们需要的。
mysql> select * from lw.test;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
| 4 | d |
| 5 | e |
| 6 | f |
+----+------+
6 rows in set (0.00 sec)