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. P1474 货币系统 Money Systems(完全背包求填充方案数)

    题目链接:https://www.luogu.org/problemnew/show/1474 题目大意:有V种货币,求用V种货币凑出面值N有多少种方案. 解题思路:就是完全背包问题,只是将求最大价值 ...

  2. HDU-1671

    Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. [PAT] 1140 Look-and-say Sequence(20 分)

    1140 Look-and-say Sequence(20 分)Look-and-say sequence is a sequence of integers as the following: D, ...

  4. window,getComputedStyle,letter-spacing

       js 拿到element的css样式    window.getComputedStyle(ele,[pseuso)    比如想拿到一个element的背景色 window.getComput ...

  5. poj 3264(RMQ或者线段树)

    Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 42929   Accepted: 20184 ...

  6. ofbiz 之minilang解析

    编写一个simple method 首先我们需要对输入参数进行验证 ,判断参数是否完整. 1. 验证 1.1. Login-required :这是一个simple-method的属性,对是否需要登陆 ...

  7. 运行ceph时,了解一下主要的进程。

    最简单ceph.conf配置如下: [global] fsid = 798ed076--429e-9e27-0ffccd60b56e mon_initial_members = ceph-node1 ...

  8. Partial Views

    @Html.Partial("MyPartial")   @Html.Partial("MyStronglyTypedPartial", new [] {&qu ...

  9. loadrunner中文件的操作

    loadrunner中文件的操作 我们可以使用fopen().fscanf().fprintf().fclose()函数进行文件操作,但是因为LoadRunner不支持FILE数据类型,所以我们需要做 ...

  10. LoadRunner 执行单句SQL语句

    LoadRunner 执行单句SQL语句 Action() { int NumRows=0; int i=1; //建立数据库连接 lr_db_connect("StepName=Datab ...