PerconaXtraBackup --全备增备prepare restore
Xtrabackup
Xtrabackup包含两个主要的工具,即xtrabackup和innobackupex,二者区别如下:
• xtrabackup只能备份innodb和xtradb引擎表,而不能备份MyISAM表
• innobackupex是一个封装了xtrabackup的Perl脚本,支持同时备份innodb和MyISAM,但在对MyISAM备份时需要加一个全局的读锁
创建用户赋予权限
CREATE USER 'backup'@'localhost' IDENTIFIED BY 'backup';GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT,PROCESS ON *.* TO 'backup'@'localhost';
innobackupex调用xtrabackup备份xtradb和innodb,调用perl脚本备份MyISAM表
创建完整备份示例
innobackupex --defaults-file=/data/mysqldata/3306/my.cnf --user=backup --password='backup'/data/mysqldata/backup/
如果使用–defaults-file选项,则必须在第一位
备份完成后会在目录下创建一个以时间命名的目录
[mysql@master backup]$ pwd/data/mysqldata/backup[mysql@master backup]$ ls2016-08-18_18-23-33
–no-timestamp 该选项告诉innobackupex不创建一个时间戳目录存储备份
innobackupex --defaults-file=/data/mysqldata/3306/my.cnf --user=backup --password='backup'--no-timestamp /data/mysqldata/backup/base
上例中备份会存放在base目录下,如果目录不存在会自动创建
创建备份后并不能直接用于恢复.需要先prepare.
prepare的目的是跑一下redo,将未提交的rollback,回滚的回滚,跑出一个一致性的备份
innobackupex --apply-log /data/mysqldata/backup/base/
查看输出的最后一行 completed OK!表示prepare成功
prepare前
backup-my.cnf ibdata1 performance_schema test xtrabackup_checkpoints xtrabackup_logfilefandb mysql sakila xtrabackup_binlog_info xtrabackup_info
prepare后
backup-my.cnf ib_logfile0 ibtmp1 sakila xtrabackup_binlog_pos_innodb xtrabackup_logfilefandb ib_logfile1 mysql test xtrabackup_checkpointsibdata1 ib_logfile2 performance_schema xtrabackup_binlog_info xtrabackup_info
ib_logfile0,1,2由prepare生成
–use-memory 使用此参数可以提升prepare速度,默认100M
innobackupex --apply-log --use-memory=4G/data/mysqldata/backup/base/
restore全备
为了方便,innobackupex有一个–copy-back选项,可以将备份拷贝回datadir下
innobackupex --defaults-file=/data/mysqldata/3306/my.cnf --copy-back /data/mysqldata/backup/base
datadir必须是空的,除非使用了–force-non-empty-directories 参数.MySQL在copy-back时应该是关闭的
如果创建备份时使用的是其他OS用户,那么在copy-back后你应该修改权限
chown -R mysql:mysql
增量备份(增量只针对xtradb和innodb引擎,其他引擎表仍是全备)
增量备份之前必须有一个全备份.
innobackupex --defaults-file=/data/mysqldata/3306/my.cnf --user=backup --password='backup'--no-timestamp /data/mysqldata/backup/base备份成功后,会生成一个文件xtrabackup_checkpoints[mysql@master backup]$ more base/xtrabackup_checkpointsbackup_type = full-backupedfrom_lsn =0to_lsn =143682470last_lsn =143682470compact =0recover_binlog_info =0
使用上面的全备做为基础,做增量备份
innobackupex --defaults-file=/data/mysqldata/3306/my.cnf --user=backup --password='backup'--no-timestamp --incremental /data/mysqldata/backup/incr1 --incremental-basedir=/data/mysqldata/backup/base备份成功后,查看增备的xtrabackup_checkpoints[mysql@master backup]$ more incr1/xtrabackup_checkpointsbackup_type = incrementalfrom_lsn =143682470to_lsn =143683016last_lsn =143683016compact =0recover_binlog_info =0
再次创建一个增量备份,将以刚才的增备作为基础
innobackupex --defaults-file=/data/mysqldata/3306/my.cnf --user=backup --password='backup'--no-timestamp --incremental /data/mysqldata/backup/incr2 --incremental-basedir=/data/mysqldata/backup/incr1[mysql@master backup]$ more incr2/xtrabackup_checkpointsbackup_type = incrementalfrom_lsn =143683016to_lsn =143683562last_lsn =143683562compact =0recover_binlog_info =0增倍时应该是要读取base的xtrabackup_checkpoints文件,从该文件的last_lsn开始备份.于是我手动创建一个目录incr3,并创建一个文件xtrabackup_checkpoints,以此作为base也是可以备份的.将该xtrabackup_checkpoints文件的last_lsn改为0也可以,但仍不是全备手动指定lsn,也可以成功创建增量备份.这种方法适用于当base不可用时innobackupex --defaults-file=/data/mysqldata/3306/my.cnf --user=backup --password='backup'--incremental /data/mysqldata/backup/incr1 --incremental-lsn=143680036
–incremental-lsn=name
This option specifies the log sequence number (LSN) to
use for the incremental backup. The option accepts a
string argument. It is used with the –incremental
option. It is used instead of specifying
–incremental-basedir. For databases created by MySQL and
Percona Server 5.0-series versions, specify the LSN as
two 32-bit integers in high:low format. For databases
created in 5.1 and later, specify the LSN as a single
64-bit integer.
prepare增备
prepare增量备份与prepare全备稍有不同
• First, only the committed transactions must be replayed on each backup. This will merge the base full backup with the incremental ones.
• Then, the uncommitted transaction must be rolled back in order to have a ready-to-use backup.
1.首先,在所有备份重演提交的事务,这会合并增量备份和全备
2.所有未提交事务回滚
恢复基础备份(全备)这里一定要加–redo-only参数,该参数意思是只应用xtrabackup日志中已经提交的事务数据,不回滚还未提交的数据
innobackupex --apply-log --redo-only /data/mysqldata/backup/base/
将增量备份incr应用到基础备份base
innobackupex --apply-log --redo-only /data/mysqldata/backup/base/--incremental-dir=/data/mysqldata/backup/incr1
将增量备份incr2应用到基础备份base,注意恢复最后一个增量备份时需要去掉–redo-only参数,回滚xtrabackup日志中那些还未提交的数据
innobackupex --apply-log /data/mysqldata/backup/base/--incremental-dir=/data/mysqldata/backup/incr2
Note: –redo-only should be used when merging all incrementals except the last one. That’s why the previous
line doesn’t contain the –redo-only option. Even if the –redo-only was used on the last step, backup would still be consistent but in that case server would perform the rollback phase.
–redo-only只在最后一个增备时不使用.如果在最后一个增倍时使用了–redo-only,备份仍是一致的,但在这种情况下,服务器将执行回滚阶段
要注意的是,prepare应该按照备份的时间顺序,即 全备-增备1-增备2-增备3…
如果顺序错误,备份将不可用.如果你不知道正确的熟顺序,可以查看xtrabackup_checkpoints文件
把所有合在一起的基础备份整体进行一次apply操作,回滚未提交的数据
innobackupex --apply-log /data/mysqldata/backup/base/
这一步是可选的,如果你不做,MySQL会去回滚未提交的数据.同时,因为iblog文件不会被备份,这一步也会创建它们,如果不做这一步,MySQL启动时也会创建它们.
copy-back
innobackupex --defaults-file=/data/mysqldata/3306/my.cnf --copy-back --rsync /data/mysqldata/backup/base
–rsync Uses the rsync utility to optimize local file transfers.
When this option is specified, innobackupex uses rsync to
copy all non-InnoDB files instead of spawning a separate
cp for each file, which can be much faster for servers
with a large number of databases or tables. This option
cannot be used together with –stream.
PerconaXtraBackup --全备增备prepare restore的更多相关文章
- Mongodb全备+增备+oplog恢复误删数据
此时测试表中有7条数据,做个全备. 全备: mongodump --host=192.168.43.43 --port=37017 --oplog --out=/opt/mongo/fullbacku ...
- innobackupex 单脚本循环7天一全备6增备脚本更新
#!/bin/bash #日期转为天数 function date2days { echo "$*" | awk '{ z=-$)/); y=$+-z; m=$+*z-; j=*m ...
- Innobackupex MySQL 全备、增备及恢复
简介: 在这之前都是通过 mysqldump 来备份数据库的,由于是逻辑备份,所以采用这种备份方式数据是很安全的,跨平台.版本都很容易. 凡事有利必有弊,逻辑备份在你数据库比较大时,备份.恢复数据所耗 ...
- innobackupex 全备、增备脚本
全备脚本:innobackupex --defaults-file=/etc/my.cnf --user root --password mypasswd /mydata/fullbak/ 增备脚本: ...
- oracle 备份恢复篇(二)---rman 增备恢复--不完全恢复
一,环境准备 全备脚本: export TMP=/tmp export TMPDIR=$TMP export ORACLE_BASE=/u01 export ORACLE_SID=prod expor ...
- 为MySQL选择合适的备份方式
数据库的备份是极其重要的事情.如果没有备份,遇到下列情况就会抓狂: UPDATE or DELETE whitout where… table was DROPPed accidentally… IN ...
- mysql 备份与还原
http://dev.yesky.com/281/35291281.shtml 每一种逻辑错误发生的概率都极低,但是当多种可能性叠加的时候,小概率事件就 放大成很大的安全隐患,这时候备份的必要性就凸显 ...
- 为MySQL选择合适的备份方式[转]
原文链接:http://nettedfish.sinaapp.com/blog/2013/05/31/choose-suitable-backup-strategy-for-mysql/ 数据库的备份 ...
- 青铜到王者,快速提升你 MySQL 数据库的段位!
Reference: https://mp.weixin.qq.com/s?src=11×tamp=1513259125&ver=574&signature=Uxls ...
随机推荐
- android_demo之自动生成动态表格
今天我们学习了如何更好的利用Android 的 layout 布局. 接下来是个简单的栗子去了解这个自动生成的动态的控件(自动生成表格) 这是我们的layout 页面 <?xml version ...
- Windows服务二:测试新建的服务、调试Windows服务
一.测试Windows服务 为了使Windows服务程序能够正常运行,我们需要像创建一般应用程序那样为它创建一个程序的入口点.像其他应用程序一样,Windows服务也是在Program.cs的Main ...
- struts2的国际化文件在jsp中的引用
struts.xml中的配置 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts ...
- matlab图
.6 统计作图 4.6.1 正整数的频率表 命令 正整数的频率表 函数 tabulate 格式 table = tabulate(X) %X为正整数构成的向量,返回3列:第1列中包含X的值第2列为这些 ...
- spring mvc 4.3.2 + mybatis 3.4.1 + mysql 5.7.14 +shiro 幼儿园收费系统 之 动态组合条件查询
实际应用中,系统设计无法预料到用户最终的查询条件是怎样的.通常的做法是给出一些限制死的查询条件让用户查询.业务稍有改动,就要重新设计界面,增加查询字段等,费时费力. 比较好的做法是,除了常用的查询外, ...
- loadrunner 编写socket脚本实例(附服务端实现)
一.socket背景知识 这个咱就不废话了,网上一搜一大堆 二.本实例实现的功能 服务端接收客户端发送的字符串,并返回"5678succ"共8个字符 三.服务端实现(java代码) ...
- Winform GDI+ 相关资料
在Visual Studio 2010中定义GDI+自定义控件——自定义控件介绍 http://www.cnblogs.com/zhangdong/archive/2010/05/20/1740177 ...
- I/O流——字符流
字符流 字节流提供处理任何类型输入/输出操作的足够功能,但不能直接操作Unicode字符,因而需要字符流. 字符流层次结构的顶层是Reader和Writer抽象类. 实际上,字符流的底层就是字节流. ...
- UITableView 使用
关键字 •UITableView •UITableViewDataSource •UITableViewDelegate •UITableViewCell •MVC 运行结果
- Coursera Machine Learning 作业答案脚本 分享在github上
Github地址:https://github.com/edward0130/Coursera-ML