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 ...
随机推荐
- python学习文章
推荐大家看看,这几个涉及到解决问题了 用机器学习算法解决问题(图文+程序) http://www.bida.org.cn/index.php?qa=7 数据的价值是提升业务而不仅仅是用户画像 http ...
- spring整合struts2
1. Spring 如何在 WEB 应用中使用 ? 1). 需要额外加入的 jar 包: spring-web-4.0.0.RELEASE.jarspring-webmvc-4.0.0.RELEASE ...
- 图解 classpath
先引用几句网上流传的话: 首先 classpath是指 WEB-INF文件夹下的classes目录 classpath 和 classpath* 区别: classpath:只会到你指定的class路 ...
- Ubuntu 查询 so 归属的 package
. . . . . 今天 LZ 在运行一个程序的时候,出现找不到 so 库的情况: >$ ./core ./core: error : cannot open shared object fil ...
- errorlevel
------siwuxie095 errorlevel 程序返回码 用法:echo %errorlevel% 查看当前程序返回码(即返回值),以知道程序或命令行是否执行成功. DOS在执行完后都有返回 ...
- poj 2761 Feed the dogs (treap树)
/************************************************************* 题目: Feed the dogs(poj 2761) 链接: http: ...
- WCF权限控制
前面写了 WCF账户密码认证, 实现了帐号密码认证, 接下来看看如何对方法的细粒度控制, 本文很大程度参考了 WCF安全之基于自定义声明授权策略, 这篇文章对原理讲得比较清楚, 而我这篇文章呢, ...
- 如何将数据库中的表导入到PowerDesigner中
1. 打开PowerDesigner12,在菜单中按照如下方式进行操作file->Reverse Engineer->DataBase 点击后,弹出 New Physical ...
- Python.Module.site
site " This module is automatically imported during initialization. The automatic import can be ...
- Nginx密码验证 ngx_http_auth_basic_module模块
有时候我们需要限制某些目录只允许指定的用户才可以访问,我们可以给指定的目录添加一个用户限制. nginx给我们提供了ngx_http_auth_basic_module模块来实现这个功能. 模块ngx ...