XTRABACKUP
xtrabackup是percona公司开发的第三方备份软件,只备份innodb引擎表的ibd文件(frm不备份),不备份myisam引擎表。备份性能很高,备份期间没有任和锁,ddl、dml、select都不受影响

xtrabackup全备:
step1:这步只是在系统层做了个拷贝,数据库目录只拷贝ibd文件,frm表结构需要恢复时手动拷贝,log文件不备份
  1. [root@likun data]# xtrabackup --backup --datadir=/mysql/data/--target-dir=/root/bak              
[root@likun bak]# ls
db1  ibdata1  xtrabackup_checkpoints  xtrabackup_logfile
 
step2:这步会根据第一步的lsn结果扫描日志文件,将备份期间的新log、undo,补充到备份文件中,使他们合并成为完整的有一致性的
  1. [root@likun bak]# xtrabackup --prepare --use-memory=50M--datadir=/mysql/data/--target-dir=/root/bak      
[root@likun bak]# ls
db1  ibdata1  xtrabackup_binlog_pos_innodb  xtrabackup_checkpoints  xtrabackup_logfile
 

xtrabackup   增量备:  
周一:首先做一个全备,但不要做prepare
insert into test3 values(1);commit;
xtrabackup --backup --datadir=/mysql/data/ --target-dir=/root/bak/1/
周二:基于周一做增量备,--incremental-basedir设置为周一全备的目录,表示基于哪天做增量

insert into test3 values(2);commit;
xtrabackup --backup --datadir=/mysql/data/ --target-dir=/root/bak/2/ --incremental-basedir=/root/bak/1/
周三:基于周二做增量备

insert into test3 values(3);commit;   
xtrabackup --backup --datadir=/mysql/data/ --target-dir=/root/bak/3/ --incremental-basedir=/root/bak/2/
 
恢复:
--apply-log-only   只应用日志,把增量合在一起,而不产生日志
xtrabackup --prepare  --apply-log-only --redo-only --target-dir=/root/bak/1/
xtrabackup --prepare  --apply-log-only --redo-only --target-dir=/root/bak/1/ --incremental-basedir=/root/bak/2/

xtrabackup --prepare  --apply-log-only --redo-only --target-dir=/root/bak/1/ --incremental-basedir=/root/bak/3/
这时目录1,数据才是完整的了   
 
xtrabackup --prepare   --target-dir=/root/bak/1

最终生成完整备份,可以看到目录1下面生成了ib_logfile日志文件
 
 



INNOBACKUPEX
使用innobackupex做完整备份:
先保证my.cnf配置文件中配置了 basedir 和 datadir,如果配置文件在其他位置,指定‘--defaults-file=/etc/my.cnf’
step1:生成完整备份,同时copy innodb和myisam以及frm文件,会锁myisam表
[root@likun bak]# innobackupex --user=root /root/bak
  1. InnoDBBackupUtility v1.5.1-xtrabackup;Copyright2003,2009InnobaseOy
  2. and Percona LLC and/or its affiliates 2009-2013.  AllRightsReserved.
  3. This software is published under
  4. the GNU GENERAL PUBLIC LICENSE Version2,June1991.
  5. Get the latest version of PerconaXtraBackup, documentation, and help resources:
  6. http://www.percona.com/xb/p
  7. 14081014:09:34  innobackupex:Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup' as 'root'  (using password: NO).
  8. 14081014:09:34  innobackupex:Connected to MySQL server
  9. 14081014:09:34  innobackupex:Executing a version check against the server...
  10. 14081014:09:34  innobackupex:Done.
  11. IMPORTANT:Please check that the backup run completes successfully.
  12.            At the end of a successful backup run innobackupex
  13.            prints "completed OK!".
  14. innobackupex:Using mysql server version 5.5.30-log
  15. innobackupex:Created backup directory /root/bak/2014-08-10_14-09-34
  16. 14081014:09:34  innobackupex:Starting ibbackup with command: xtrabackup  --defaults-group="mysqld"--backup --suspend-at-end --target-dir=/root/bak/2014-08-10_14-09-34--tmpdir=/tmp --extra-lsndir='/tmp'
  17. innobackupex:Waitingfor ibbackup (pid=15364) to suspend
  18. innobackupex:Suspend file '/root/bak/2014-08-10_14-09-34/xtrabackup_suspended_2'
  19. xtrabackup version 2.2.3 based on MySQL server 5.6.17Linux(x86_64)(revision id:)
  20. xtrabackup: uses posix_fadvise().
  21. xtrabackup: cd to /mysql/data
  22. xtrabackup: open files limit requested 0,set to 40960
  23. xtrabackup:using the following InnoDB configuration:
  24. xtrabackup:   innodb_data_home_dir =./
  25. xtrabackup:   innodb_data_file_path = ibdata1:10M:autoextend
  26. xtrabackup:   innodb_log_group_home_dir =./
  27. xtrabackup:   innodb_log_files_in_group =2
  28. xtrabackup:   innodb_log_file_size =5242880
  29. >> log scanned up to (1670110)
  30. [01]Copying./ibdata1 to /root/bak/2014-08-10_14-09-34/ibdata1
  31. >> log scanned up to (1670110)
  32. [01]        ...done
  33. >> log scanned up to (1670110)
  34. [01]Copying./db1/test3.ibd to /root/bak/2014-08-10_14-09-34/db1/test3.ibd
  35. [01]        ...done
  36. [01]Copying./db1/test1.ibd to /root/bak/2014-08-10_14-09-34/db1/test1.ibd
  37. [01]        ...done
  38. [01]Copying./db1/test4.ibd to /root/bak/2014-08-10_14-09-34/db1/test4.ibd
  39. [01]        ...done
  40. [01]Copying./mysql/abc.ibd to /root/bak/2014-08-10_14-09-34/mysql/abc.ibd
  41. [01]        ...done
  42. [01]Copying./db2/test.ibd to /root/bak/2014-08-10_14-09-34/db2/test.ibd
  43. [01]        ...done
  44. >> log scanned up to (1670110)
  45. xtrabackup:Creating suspend file '/root/bak/2014-08-10_14-09-34/xtrabackup_suspended_2' with pid '15364'
  46. 14081014:09:38  innobackupex:Continuing after ibbackup has suspended
  47. 14081014:09:38  innobackupex:Executing FLUSH TABLES WITH READ LOCK...
  48. 14081014:09:38  innobackupex:All tables locked and flushed to disk
  49. 14081014:09:38  innobackupex:Starting to backup non-InnoDB tables and files
  50. innobackupex: in subdirectories of '/mysql/data'
  51. innobackupex:Backing up file '/mysql/data/db1/test4.frm'
  52. innobackupex:Backing up file '/mysql/data/db1/test3.frm'
  53. >> log scanned up to (1670110)
  54. innobackupex:Backing up file '/mysql/data/db1/db.opt'
  55. innobackupex:Backing up file '/mysql/data/db1/test1.frm'
  56. innobackupex:Backing up files '/mysql/data/mysql/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}'(73 files)
  57. innobackupex:Backing up files '/mysql/data/performance_schema/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}'(18 files)
  58. innobackupex:Backing up file '/mysql/data/db2/db.opt'
  59. innobackupex:Backing up file '/mysql/data/db2/test.frm'
  60. 14081014:09:38  innobackupex:Finished backing up non-InnoDB tables and files
  61. 14081014:09:38  innobackupex:Executing FLUSH ENGINE LOGS...
  62. 14081014:09:38  innobackupex:Waitingfor log copying to finish
  63. xtrabackup:The latest check point (for incremental):'1670110'
  64. xtrabackup:Stopping log copying thread.
  65. .>> log scanned up to (1670110)
  66. xtrabackup:Creating suspend file '/root/bak/2014-08-10_14-09-34/xtrabackup_log_copied' with pid '15364'
  67. xtrabackup:Transaction log of lsn (1670110) to (1670110) was copied.
  68. 14081014:09:39  innobackupex:All tables unlocked
  69. innobackupex:Backup created in directory '/root/bak/2014-08-10_14-09-34'
  70. innobackupex:MySQL binlog position: filename 'mysql-bin.000011', position 107
  71. 14081014:09:39  innobackupex:Connection to database server closed
  72. 14081014:09:39  innobackupex: completed OK!
step2:同步日志文件
[root@likun bak]# innobackupex   --use-memory=50M --apply-log /root/bak/2014-08-10_14-09-34/
 
 
恢复完整备份:
service mysql stop
清空data目录
innobackupex会根据配置文件中datadir进行恢复
[root@likun data]# innobackupex --copy-back /root/bak/2014-08-10_14-09-34/
chown mysql. * -R
service mysql start

 
使用innodbbackupex做增量备份
mkdir {1,2,3}
周一:
 insert into test3 values(1);commit;
[root@likun bak]# innobackupex --user=root /root/bak/1/
周二:
 insert into test3 values(2);commit;   
[root@likun bak]# innobackupex --user=root --incremental /root/bak/2/ --incremental-basedir=/root/bak/1/2014-08-10_14-37-26/
周三:
 insert into test3 values(3);commit;      
[root@likun 2]# innobackupex --user=root --incremental /root/bak/3/ --incremental-basedir=/root/bak/2/2014-08-10_14-42-01/
 
恢复增量备份:
准备原始备份:--redo-only同xtrabackup的apply-log-only

[root@likun 2]# innobackupex --apply-log --redo-only /root/bak/1/2014-08-10_14-37-26/ --use-memory=50M --user=root
叠加周二增量:
[root@likun 2]# innobackupex --apply-log --redo-only /root/bak/1/2014-08-10_14-37-26/ --incremental-dir=/root/bak/2/2014-08-10_14-42-01/ --use-memory=50m --user=root
叠加周三增量:   
[root@likun 2]# innobackupex --apply-log --redo-only /root/bak/1/2014-08-10_14-37-26/ --incremental-dir=/root/bak/3/2014-08-10_14-43-40/ --use-memory=50m --user=root
这样最终在目录1生成完整备份文件。最后执行:
[root@likun 2]# innobackupex --apply-log /root/bak/1/2014-08-10_14-37-26/ --use-memory=50m --user=root
 
将完整的增量备份恢复到数据库:

service mysql stop
清空data目录

[root@likun mysql]#  innobackupex --copy-back /root/bak/1/2014-08-10_14-37-26/

chown mysql. * -R
service mysql start

 
OK~~

16、Xtrabackup备份与恢复的更多相关文章

  1. xtrabackup备份与恢复实践

    说明   xtrabackup  --percona 特点: 开源,在线备份innodb表 支持限速备份,避免对业务造成影响 支持流备 支持增量备份 支持备份文件压缩与加密 支持并行备份与恢复,速度快 ...

  2. MySQL入门篇(七)之Xtrabackup备份与恢复

    一.Xtrabackup介绍 MySQL冷备.mysqldump.MySQL热拷贝都无法实现对数据库进行增量备份.在实际生产环境中增量备份是非常实用的,如果数据大于50G或100G,存储空间足够的情况 ...

  3. Xtrabackup备份与恢复MySQL

    1.innobackupex备份原理 .innobackupex启动并fork一个进程启动xtrabackup,然后等待xtrabackup备份InnoDB文件; .xtrabackup备份时存在两个 ...

  4. Xtrabackup备份与恢复

    一.Xtrabackup介绍 MySQL冷备.mysqldump.MySQL热拷贝都无法实现对数据库进行增量备份.在实际生产环境中增量备份是非常实用的,如果数据大于50G或100G,存储空间足够的情况 ...

  5. Linux基础学习(16)--备份与恢复

    第十六章——备份与恢复 一.备份概述 1.Linux系统需要备份的数据: 2.备份策略: 二.dump和restore命令 1.dump命令: 2.restore命令:

  6. XtraBackup 备份与恢复实例讲解

    前一篇文章我们讲到了PXB的原理以及安装方法,接下来将详细介绍 XtraBackup 备份和恢复的具体过程. xtrabackup 选项 xtrabackup 工具有许多参数,具体可去官网查询(xtr ...

  7. xtrabackup 备份与恢复

    书上摘抄 ---深入浅出mysql 448页  grant reload on *.* to 'backup'@'localhost' identified by '123456'; grant re ...

  8. mysql 开发进阶篇系列 46 物理备份与恢复( xtrabackup的 选项说明,增加备份用户,完全备份案例)

    一. xtrabackup 选项说明 在操作xtrabackup备份与恢复之前,先看下该工具的选项,下面记录了xtrabackup二进制文件的部分命令行选项,后期把常用的选项在补上.点击查看xtrab ...

  9. Mysql—数据备份与恢复

    数据备份 # 备份单个数据库 [root@localhost ~]# mysqldump -h主机名 -u用户名 -p密码 数据库名字 > 备份的数据库名字.sql [root@localhos ...

随机推荐

  1. JDBC原生数据库连接

    我们在开发JavaWeb项目时,常会需要连接数据库.我们以MySQL数据库为例,IDE工具为eclipse,讲述数据库连接与基本操作. 第一步,我们在Web项目的WebContent中建一个简单的前端 ...

  2. Leetcode 之Longest Palindromic Substring(30)

    很经典的一道题,最长回文子串,有多种方法. 首先介绍的一种方法是从中间向两边展开.注意区分aba和abba型的回文串:如果当前最长的子串已经当于两边中最长的子串了,则无需再去判断. //从中间向两边展 ...

  3. hdu 1428(很好的一道题,最短路+记忆化搜索)

    漫步校园 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  4. QQ分享 QQ空间分享 API链接:

    QZone: "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url={{URL}}&title={{TITL ...

  5. Linux下服务器搭建

    一.安装前准备工作 yum -y install gcc   yum -y install gcc-c++   yum -y install make yum -y install ncurses-d ...

  6. AC日记——餐巾计划问题 洛谷 P1084

    餐巾计划问题 思路: 氧气优化水过: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 4005 #define ...

  7. 使用css中的flex布局弹性手风琴效果

    不多说,直接上代码. <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  8. 4.Spark Streaming事务处理

    首先,我们必须知道什么是事务及其一致性? 事务应该具有4个属性:原子性.一致性.隔离性.持久性.这四个属性通常称为ACID特性. 原子性(atomicity).一个事务是一个不可分割的工作单位,事务中 ...

  9. iwebshop 自动给css js链接加版本信息

    lib/core/tag_class.php case 'theme:': $path = $matches[4]; $exts = strtolower(substr($matches[4], st ...

  10. shadowssock启动服务

    启动服务:ssserver -c /var/ss/server.json