搜索
首页数据库mysql教程基于Innobackupex的不完全恢复

对于MySQL的不完全恢复,我们可以借助于Innobackupex的多重备份加上binlog来将数据库恢复到任意时刻。这里的不完全恢复(也叫时点恢复)是相对于完全恢复。本文主要演示了基于Innobackupex如何做一个不完全恢复,供大家参考。 a、创建演示环境 robin@localhost[

对于MySQL的不完全恢复,我们可以借助于Innobackupex的多重备份加上binlog来将数据库恢复到任意时刻。这里的不完全恢复(也叫时点恢复)是相对于完全恢复。本文主要演示了基于Innobackupex如何做一个不完全恢复,供大家参考。
a、创建演示环境 robin@localhost[(none)]> show variables like 'version'; --当前MySQL版本 +---------------+------------+ | Variable_name | Value | +---------------+------------+ | version | 5.6.12-log | +---------------+------------+ robin@localhost[(none)]> reset master; Query OK, 0 rows affected (0.03 sec) robin@localhost[(none)]> use tempdb; robin@localhost[tempdb]> create table tb(id smallint,val varchar(20)); robin@localhost[tempdb]> insert into tb values(1,'fullbak'); --创建一个全备 SHELL> innobackupex --user=robin -password=xxx --port=3606 --socket=/tmp/mysql3606.sock --defaults-file=/etc/my3606.cnf \ > /hotbak/full --no-timestamp b、创建一个增备 --在创建增备前插入一条记录到tb robin@localhost[tempdb]> insert into tb values(2,'Incbak'); SHELL> innobackupex --user=robin -password=xxx --port=3606 --socket=/tmp/mysql3606.sock --defaults-file=/etc/my3606.cnf \ > --incremental /hotbak/inc --incremental-basedir=/hotbak/full --no-timestamp --再次新增一条记录 robin@localhost[tempdb]> insert into tb values(3,'pointrecover'); Query OK, 1 row affected (0.01 sec) --记下当前的时间点用于后续的不完全恢复 robin@localhost[tempdb]> system date; Thu Dec 25 11:53:54 CST 2014 --模拟误操作 robin@localhost[tempdb]> truncate table tb; Query OK, 0 rows affected (0.01 sec) c、再次全备 SHELL> innobackupex --user=robin -password=xxx --port=3606 --socket=/tmp/mysql3606.sock --defaults-file=/etc/my3606.cnf \ > /hotbak/full2 --no-timestamp --全备后新增一张表 robin@localhost[tempdb]> create table tb_after_truncate(id int,val varchar(20)); Query OK, 0 rows affected (0.02 sec)3、演示恢复过程
--下面理清一下思路: --当前备份情况: 全备+增备+全备 --我们在增备之后truncate了表tb,然后又创建了一个全备,新建了一个表tb_after_truncate。 --此时我们需要将数据库恢复到truncate(误操作)之前 --解决方案:我们需要利用第一次的全备+增备+binglog来恢复到truncate前,当前第二次全备用不上。 a、先做基于全备的apply,注意,此时使用了--redo-only SHELL> i【本文来自鸿网互联 (http://www.68idc.cn)】nnobackupex --apply-log --redo-only --user=robin -password=xxx --port=3606 \ > --defaults-file=/etc/my3606.cnf /hotbak/full b、基于增备的apply, --此时没有--redo-only,如果有多个增备,仅仅最后一个增备无需指定--redo-only SHELL> innobackupex --apply-log --user=robin -password=xxx --port=3606 --defaults-file=/etc/my3606.cnf \ > /hotbak/full --incremental-dir=/hotbak/inc c、进行copy back SHELL> mysqldown -P3606 --copy back前关闭实例 SHELL> netstat -nltp|grep mysql|grep 3606 SHELL> mv /data/inst3606/data3606 /data/inst3606/data3606bk SHELL> mkdir -p /data/inst3606/data3606 SHELL> innobackupex --user=robin -password=xxx --port=3606 --copy-back /hotbak/full --defaults-file=/etc/my3606.cnf SHELL> chown -R mysql:mysql /data/inst3606/data3606 d、启动恢复后的实例 SHELL> mysqld_safe --defaults-file=/etc/my3606.cnf & SHELL> mysql -uroot -pxxx -P3606 -S /tmp/mysql3606.sock \ > -e "select * from tempdb.tb" Warning: Using a password on the command line interface can be insecure. +------+---------+ | id | val | +------+---------+ | 1 | fullbak | | 2 | Incbak | +------+---------+ --获取增量之后的log position SHELL> cd /hotbak/inc/ SHELL> more xtrabackup_binlog_info inst3606bin.000001 774 --这里使用了stop-datetime去将日志追加到truncate之前 SHELL> mysqlbinlog /data/inst3606/log/bin/inst3606bin.000001 --start-position=774 --stop-datetime="2014-12-25 11:53:54" \ > |mysql -urobin -pxxx -P3606 -S /tmp/mysql3606.sock --验证结果如下,可以看到已经恢复到truncate之前了 SHELL> mysql -uroot -pxxx -P3606 -S /tmp/mysql3606.sock \ > -e "select * from tempdb.tb" Warning: Using a password on the command line interface can be insecure. +------+--------------+ | id | val | +------+--------------+ | 1 | fullbak | | 2 | Incbak | | 3 | pointrecover | +------+--------------+ --如果我们需要继续恢复后面的事务,我们可以找出truncate前后位置,然后跳过这个position SHELL> mysqlbinlog /data/inst3606/log/bin/inst3606bin.000001 --start-datetime="2014-12-25 11:53:54"|grep truncate -A5 truncate table tb /*!*/; # at 1180 #141225 11:55:35 server id 3606 end_log_pos 1260 CRC32 0x12f55fc5 Query thread_id=928 exec_time=0 error_code=0 SET TIMESTAMP=1419479735/*!*/; /*!\C latin1 *//*!*/; -- create table tb_after_truncate(id int,val varchar(20)) /*!*/; # at 1392 #141225 13:06:47 server id 3606 end_log_pos 1415 CRC32 0xf956f311 Stop DELIMITER ; # End of log file --我们找出的position为1260,跳过1260之前的继续追加binlog SHELL> mysqlbinlog /data/inst3606/log/bin/inst3606bin.000001 --start-position=1260 \ > |mysql -urobin -pxxx -P3606 -S /tmp/mysql3606.sock --验证追加后的结果,可以看到表tb_after_truncate存在 [mysql@app ~]$ mysql -uroot -pxxx -P3606 -S /tmp/mysql3606.sock \ > -e "desc tempdb.tb_after_truncate" Warning: Using a password on the command line interface can be insecure. +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | val | varchar(20) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+4、小结
f、也可以跳过故障点,继续追加后面的binlog日志至最新,如本文尾部的演示

 

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
在MySQL中使用视图的局限性是什么?在MySQL中使用视图的局限性是什么?May 14, 2025 am 12:10 AM

mysqlviewshavelimitations:1)他们不使用Supportallsqloperations,限制DatamanipulationThroughViewSwithJoinSorsubqueries.2)他们canimpactperformance,尤其是withcomplexcomplexclexeriesorlargedatasets.3)

确保您的MySQL数据库:添加用户并授予特权确保您的MySQL数据库:添加用户并授予特权May 14, 2025 am 12:09 AM

porthusermanagementInmysqliscialforenhancingsEcurityAndsingsmenting效率databaseoperation.1)usecReateusertoAddusers,指定connectionsourcewith@'localhost'or@'%'。

哪些因素会影响我可以在MySQL中使用的触发器数量?哪些因素会影响我可以在MySQL中使用的触发器数量?May 14, 2025 am 12:08 AM

mysqldoes notimposeahardlimitontriggers,butacticalfactorsdeterminetheireffactective:1)serverConfiguration impactactStriggerGermanagement; 2)复杂的TriggerSincreaseSySystemsystem load; 3)largertablesslowtriggerperfermance; 4)highConconcConcrencerCancancancancanceTigrignecentign; 5); 5)

mysql:存储斑点安全吗?mysql:存储斑点安全吗?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

mySQL:通过PHP Web界面添加用户mySQL:通过PHP Web界面添加用户May 14, 2025 am 12:04 AM

通过PHP网页界面添加MySQL用户可以使用MySQLi扩展。步骤如下:1.连接MySQL数据库,使用MySQLi扩展。2.创建用户,使用CREATEUSER语句,并使用PASSWORD()函数加密密码。3.防止SQL注入,使用mysqli_real_escape_string()函数处理用户输入。4.为新用户分配权限,使用GRANT语句。

mysql:blob和其他无-SQL存储,有什么区别?mysql:blob和其他无-SQL存储,有什么区别?May 13, 2025 am 12:14 AM

mysql'sblobissuitableForStoringBinaryDataWithInareLationalDatabase,而alenosqloptionslikemongodb,redis和calablesolutionsoluntionsoluntionsoluntionsolundortionsolunsolunsstructureddata.blobobobsimplobissimplobisslowderperformandperformanceperformancewithlararengelitiate;

mySQL添加用户:语法,选项和安全性最佳实践mySQL添加用户:语法,选项和安全性最佳实践May 13, 2025 am 12:12 AM

toaddauserinmysql,使用:createUser'username'@'host'Indessify'password'; there'showtodoitsecurely:1)choosethehostcarecarefullytocon trolaccess.2)setResourcelimitswithoptionslikemax_queries_per_hour.3)usestrong,iniquepasswords.4)Enforcessl/tlsconnectionswith

MySQL:如何避免字符串数据类型常见错误?MySQL:如何避免字符串数据类型常见错误?May 13, 2025 am 12:09 AM

toAvoidCommonMistakeswithStringDatatatPesInMysQl,CloseStringTypenuances,chosethirtightType,andManageEngencodingAndCollat​​ionsEttingsefectery.1)usecharforfixed lengengters lengengtings,varchar forbariaible lengength,varchariable length,andtext/blobforlabforlargerdata.2 seterters seterters seterters seterters

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

Dreamweaver Mac版

Dreamweaver Mac版

视觉化网页开发工具

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能