Xtrabackup安装以及应用

Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Hotbackup的一个很好的替代品。

xtrabackup官方网址:https://www.percona.com/downloads/XtraBackup/

MySQL Backup Tool Feature Comparison

Features Percona XtraBackup MySQL Enterprise backup
License GPL Proprietary
Price Free Included in subscription at $5000 per Server
Streaming and encryption formats Open source Proprietary
Supported MySQL flavors MySQLPercona ServerMariaDB,Percona XtraDB ClusterMariaDB Galera Cluster MySQL
Supported operating systems Linux Linux, Solaris, Windows, OSX, FreeBSD.
Non-blocking InnoDB backups [1] Yes Yes
Blocking MyISAM backups Yes Yes
Incremental backups Yes Yes
Full compressed backups Yes Yes
Incremental compressed backups Yes  
Fast incremental backups [2] Yes  
Incremental backups with archived logs feature in Percona Server Yes  
Incremental backups with REDO log only   Yes
Backup locks [8] Yes  
Encrypted backups Yes Yes [3]
Streaming backups Yes Yes
Parallel local backups Yes Yes
Parallel compression Yes Yes
Parallel encryption Yes Yes
Parallel apply-log Yes  
Parallel copy-back   Yes
Partial backups Yes Yes
Partial backups of individual partitions Yes  
Throttling [4] Yes Yes
Backup image validation   Yes
Point-in-time recovery support Yes Yes
Safe slave backups Yes  
Compact backups [5] Yes  
Buffer pool state backups Yes  
Individual tables export Yes Yes [6]
Individual partitions export Yes  
Restoring tables to a different server [7] Yes Yes
Data & index file statistics Yes  
InnoDB secondary indexes defragmentation Yes  
rsync support to minimize lock time Yes  
Improved FTWRL handling Yes  
Backup history table Yes Yes
Backup progress table   Yes
Offline backups   Yes
Backup to tape media managers   Yes
Cloud backups support   Amazon S3
External graphical user interfaces to backup/recovery Zmanda Recovery Manager for MySQL MySQL Workbench, MySQL Enterprise Monitor
来源: https://www.percona.com/doc/percona-xtrabackup/2.4/intro.html

xtrabackup安装方法

可以下载源码编译安装,也可以下载适合的RPM包或者yum进行安装。
1、Installing Percona XtraBackup from Percona yum repository
安装Percona XtraBackup Percona yum资源库
yum install -y http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
查看软件包是否存在
[root@db01 ~]# yum list|grep percona
测试是否存在软件包
...
percona-xtrabackup-20.x86_64               2.0.8-587.rhel5             percona-release-x86_64
percona-xtrabackup-20-debuginfo.x86_64     2.0.8-587.rhel5             percona-release-x86_64
percona-xtrabackup-20-test.x86_64          2.0.8-587.rhel5             percona-release-x86_64
percona-xtrabackup-test-22.x86_64          2.2.13-1.el5                percona-release-x86_64
...
安装软件包
yum install percona-xtrabackup-22
2、Installing Percona XtraBackup using downloaded rpm packages
使用rpm包安装
Installing Percona Server using downloaded rpm packages
下载需要的版本:
wget https://www.percona.com/downloads/Percona-Server-5.7/Percona-Server-5.7.10-3/binary/redhat/7/x86_64/Percona-Server-5.7.10-3-r63dafaf-el7-x86_64-bundle.tar
需要解压
tar xvf Percona-Server-5.7.10-3-r63dafaf-el7-x86_64-bundle.tar
ls *.rpm
 
Percona-Server-57-debuginfo-5.7.10-3.1.el7.x86_64.rpm
Percona-Server-client-57-5.7.10-3.1.el7.x86_64.rpm
Percona-Server-devel-57-5.7.10-3.1.el7.x86_64.rpm
Percona-Server-server-57-5.7.10-3.1.el7.x86_64.rpm
Percona-Server-shared-57-5.7.10-3.1.el7.x86_64.rpm
Percona-Server-shared-compat-57-5.7.10-3.1.el7.x86_64.rpm
Percona-Server-test-57-5.7.10-3.1.el7.x86_64.rpm
Percona-Server-tokudb-57-5.7.10-3.1.el7.x86_64.rpm
运行方式
rpm -ivh Percona-Server-server-57-5.7.10-3.1.el7.x86_64.rpm \
Percona-Server-client-57-5.7.10-3.1.el7.x86_64.rpm \
Percona-Server-shared-57-5.7.10-3.1.el7.x86_64.rpm   ...

Uninstalling Percona XtraBackup

卸载软件包
yum remove percona-xtrabackup
官方文档:https://www.percona.com/doc/percona-xtrabackup/2.2/installation/yum_repo.html#uninstalling-percona-xtrabackup

Download Percona Server 5.7

软件包说明
Download All Packages Together
Percona-Server-5.7.12-5-ra2f663a-el6-x86_64-bundle.tar 
Download Packages Separately
Percona-Server-57-debuginfo-5.7.12-5.1.el6.x86_64.rpm  
Percona-Server-client-57-5.7.12-5.1.el6.x86_64.rpm 
Percona-Server-devel-57-5.7.12-5.1.el6.x86_64.rpm
Percona-Server-server-57-5.7.12-5.1.el6.x86_64.rpm
Percona-Server-shared-57-5.7.12-5.1.el6.x86_64.rpm
Percona-Server-test-57-5.7.12-5.1.el6.x86_64.rpm
Percona-Server-tokudb-57-5.7.12-5.1.el6.x86_64.rpm
官方解释每个软件包的作用:

What’s in each RPM package?¶

每个Percona服务器的RPM包有一个特定的目的。
Percona-Server-server-57包包含了服务器本身(mysqld二进制)。
为服务器Percona-Server-57-debuginfo包包含调试符号。
Percona-Server-client-57包包含命令行客户端。
Percona-Server-devel-57包包含所需的头文件编译软件使用客户端库。
Percona-Server-shared-57包包含客户端共享库。
Percona-Server-shared-compat包包含共享库的编译软件旧版本的客户端库。
库包含在这个包:libmysqlclient.so。
12,libmysqlclient.so。
14日,libmysqlclient.so。
15日,libmysqlclient.so。
16、libmysqlclient.so.18。
Percona-Server-test-57包包括Percona服务器的测试套件

检查安装结果:

[root@db01 ~]# rpm -qa|grep xtrabackup
percona-xtrabackup-22-2.2.13-1.el6.x86_64
Xtrabackup中主要包含两个工具:
xtrabackup:是用于热备innodb,xtradb表中数据的工具,不能备份其他类型的表,也不能备份数据表结构;
innobackupex:是将xtrabackup进行封装的perl脚本,提供了备份myisam表的能力。

使用xtrabackup实现对MySQL的备份

1.完全备份

基本语法:
多实例备份:
  1. [root@db02 3306]# innobackupex --user=root --password=123456 --socket=/data/3306/mysql.sock --defaults-file=/data/3306/my.cnf /tmp/
语法解释:–user=数据库用户
      –password=数据库密码
      –socket=指定socket
      –default-file=指定配置文件
      最后面是存放位置
  1. InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
  2. and Percona LLC and/or its affiliates 2009-2013.  All Rights Reserved.
  3. This software is published under
  4. the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
  5. Get the latest version of Percona XtraBackup, documentation, and help resources:
  6. http://www.percona.com/xb/p
  7. 160703 20:00:13  innobackupex: Executing a version check against the server...
  8. 160703 20:00:13  innobackupex: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_file=/data/3306/my.cnf;mysql_read_default_group=xtrabackup;mysql_socket=/data/3306/mysql.sock' as 'root'  (using password: YES).
  9. 160703 20:00:13  innobackupex: Connected to MySQL server
  10. 160703 20:00:13  innobackupex: Done.
  11. 160703 20:00:13  innobackupex: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_file=/data/3306/my.cnf;mysql_read_default_group=xtrabackup;mysql_socket=/data/3306/mysql.sock' as 'root'  (using password: YES).
  12. 160703 20:00:13  innobackupex: Connected to MySQL server
  13. 160703 20:00:13  innobackupex: Starting the backup operation
  14. IMPORTANT: Please check that the backup run completes successfully.
  15.            At the end of a successful backup run innobackupex
  16.            prints "completed OK!".
  17. innobackupex:  Using server version 5.5.49-log
  18. innobackupex: Created backup directory /tmp/2016-07-03_20-00-13
  19. 160703 20:00:13  innobackupex: Starting ibbackup with command: xtrabackup  --defaults-file="/data/3306/my.cnf"  --defaults-group="mysqld" --backup --suspend-at-end --target-dir=/tmp/2016-07-03_20-00-13 --tmpdir=/tmp --extra-lsndir='/tmp'
  20. innobackupex: Waiting for ibbackup (pid=2586) to suspend
  21. innobackupex: Suspend file '/tmp/2016-07-03_20-00-13/xtrabackup_suspended_2'
  22. xtrabackup version 2.2.13 based on MySQL server 5.6.24 Linux (x86_64) (revision id: 70f4be3)
  23. xtrabackup: uses posix_fadvise().
  24. xtrabackup: cd to /data/3306/data
  25. xtrabackup: open files limit requested 1024, set to 65535
  26. xtrabackup: using the following InnoDB configuration:
  27. xtrabackup:   innodb_data_home_dir = ./
  28. xtrabackup:   innodb_data_file_path = ibdata1:128M:autoextend
  29. xtrabackup:   innodb_log_group_home_dir = ./
  30. xtrabackup:   innodb_log_files_in_group = 3
  31. xtrabackup:   innodb_log_file_size = 4194304
  32. >> log scanned up to (2097320)
  33. xtrabackup: Generating a list of tablespaces
  34. [01] Copying ./ibdata1 to /tmp/2016-07-03_20-00-13/ibdata1
  35. >> log scanned up to (2097320)
  36. >> log scanned up to (2097320)
  37. >> log scanned up to (2097320)
  38. >> log scanned up to (2097320)
  39. >> log scanned up to (2097320)
  40. [01]        ...done
  41. >> log scanned up to (2097320)
  42. xtrabackup: Creating suspend file '/tmp/2016-07-03_20-00-13/xtrabackup_suspended_2' with pid '2586'
  43. 160703 20:00:20  innobackupex: Continuing after ibbackup has suspended
  44. 160703 20:00:20  innobackupex: Executing FLUSH NO_WRITE_TO_BINLOG TABLES...
  45. 160703 20:00:20  innobackupex: Executing FLUSH TABLES WITH READ LOCK...
  46. 160703 20:00:20  innobackupex: All tables locked and flushed to disk
  47. 160703 20:00:20  innobackupex: Starting to backup non-InnoDB tables and files
  48. innobackupex: in subdirectories of '/data/3306/data/'
  49. innobackupex: Backing up file '/data/3306/data//qqqqqqq41233/db.opt'
  50. >> log scanned up to (2097320)
  51. innobackupex: Backing up file '/data/3306/data//dadadadadadad/db.opt'
  52. innobackupex: Backing up file '/data/3306/data//qqqqqqqq3/db.opt'
  53. innobackupex: Backing up file '/data/3306/data//qqqqqqqq/db.opt'
  54. innobackupex: Backing up file '/data/3306/data//qqqqqqq43/db.opt'
  55. innobackupex: Backing up file '/data/3306/data//oldboy_gbk/db.opt'
  56. innobackupex: Backing up file '/data/3306/data//oldboy/student.frm'
  57. innobackupex: Backing up file '/data/3306/data//oldboy/db.opt'
  58. innobackupex: Backing up file '/data/3306/data//ooooooooooooooooo/db.opt'
  59. innobackupex: Backing up files '/data/3306/data//performance_schema/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (18 files)
  60. innobackupex: Backing up file '/data/3306/data//qqqqqqqq1/db.opt'
  61. innobackupex: Backing up file '/data/3306/data//wordpress/db.opt'
  62. innobackupex: Backing up file '/data/3306/data//aaa/db.opt'
  63. innobackupex: Backing up files '/data/3306/data//mysql/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (72 files)
  64. innobackupex: Backing up file '/data/3306/data//cyh/db.opt'
  65. innobackupex: Backing up file '/data/3306/data//wuyi/db.opt'
  66. 160703 20:00:21  innobackupex: Finished backing up non-InnoDB tables and files
  67. 160703 20:00:21  innobackupex: Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
  68. 160703 20:00:21  innobackupex: Waiting for log copying to finish
  69. >> log scanned up to (2097320)
  70. xtrabackup: The latest check point (for incremental): '2097320'
  71. xtrabackup: Stopping log copying thread.
  72. .>> log scanned up to (2097320)
  73. xtrabackup: Creating suspend file '/tmp/2016-07-03_20-00-13/xtrabackup_log_copied' with pid '2586'
  74. xtrabackup: Transaction log of lsn (2097320) to (2097320) was copied.
  75. 160703 20:00:22  innobackupex: All tables unlocked
  76. innobackupex: Backup created in directory '/tmp/2016-07-03_20-00-13'
  77. innobackupex: MySQL binlog position: filename 'mysql-bin.000029', position 107
  78. 160703 20:00:22  innobackupex: Connection to database server closed
  79. 160703 20:00:22  innobackupex: completed OK!
错误提示:如果执行该命令出现如下错误:
  1.     Can't load '/usr/local/lib64/perl5/auto/DBD/mysql/mysql.so' for module DBD::mysql: libmysqlclient.so.18: 无法打开共享对象 at /usr/bin/innobackupex line 18
需要拷贝libmysqlclient.so.18至/usr/lib64:
  1. [root@localhost ~]# cp /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/

备份后的文件:

在备份的同时,备份数据会在备份目录下创建一个以当前时间为名字的目录存放备份文件:
各文件说明:
(1)xtrabackup_checkpoints —-备份类型(如完全或增量)、备份状态(如是否已经没prepare状态)和LSN(日志序列号)范围信息
每个InnoDB页(通常大小为16K)都会包含一个日志序列号,即LSN,LSN是整个数据库系统的系统版本号,每个页面相关的LSN能够表名此页面最近是如何发生改变的。
backup_type = full-backuped
from_lsn = 0
to_lsn = 2097320
last_lsn = 2097320
compact = 0
(2)xtrabackup_binlog_info —-mysql服务器当前正在使用的二进制日志及备份这一刻为二进制日志事件的位置
(3)xtrabackup_pos_innodb —-二进制日志及用于InnoDB或XtraDB表的二进制日志的当前posistion。
(4)xtrabackup_binary —-备份中用到的xtrabackup的可执行文件
(5)backup-my.cnf —- 备份命令用到的配置选项信息;
在使用innobackupex命令备份时吗还可以使用–no-timestamp选项来阻止命令自动创建一个以时间命名的目录
innobackupex命令将会创建一个BACKUP-DIR目录来存储备份数据
还需要注意,备份数据库的用户需要具有相对应的权限,如果要使用一个最小权限的用户进行备份可以使用以下参数:
  1. mysql> GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO bkpuser’@’localhost’;       
  2. mysql> FLUSH PRIVILEGES;

2. 准备(prepare)一个完整备份

一般情况下,在备份完成后,数据尚且不能用于恢复操作,因为备份的数据中可能会包含尚未提交的事务或已经提交但尚未同步至数据文件中的事务,因此,此时数据文件仍处理不一致状态。“准备”的主要作用是通过回滚未提交的事务及同步已经提交的事务至数据文件也使得数据文件处于一致性状态。
innobackupex命令的–apply-log选项可用于实现上述功能。
[root@db02 /]# innobackupex –apply-log /tmp/2016-07-03_21-07-38/
如果执行正确,会输出以下内容:不提示错误即可
  1. InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
  2. and Percona LLC and/or its affiliates 2009-2013.  All Rights Reserved.
  3. This software is published under
  4. the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
  5. Get the latest version of Percona XtraBackup, documentation, and help resources:
  6. http://www.percona.com/xb/p
  7. 160703 21:43:08  innobackupex: Starting the apply-log operation
  8. IMPORTANT: Please check that the apply-log run completes successfully.
  9.            At the end of a successful apply-log run innobackupex
  10.            prints "completed OK!".
  11. 160703 21:43:08  innobackupex: Starting ibbackup with command: xtrabackup  --defaults-file="/tmp/2016-07-03_21-07-38/backup-my.cnf"  --defaults-group="mysqld" --prepare --target-dir=/tmp/2016-07-03_21-07-38
  12. xtrabackup version 2.2.13 based on MySQL server 5.6.24 Linux (x86_64) (revision id: 70f4be3)
  13. xtrabackup: cd to /tmp/2016-07-03_21-07-38
  14. xtrabackup: This target seems to be not prepared yet.
  15. xtrabackup: xtrabackup_logfile detected: size=2097152, start_lsn=(2097320)
  16. xtrabackup: using the following InnoDB configuration for recovery:
  17. xtrabackup:   innodb_data_home_dir = ./
  18. xtrabackup:   innodb_data_file_path = ibdata1:128M:autoextend
  19. xtrabackup:   innodb_log_group_home_dir = ./
  20. xtrabackup:   innodb_log_files_in_group = 1
  21. xtrabackup:   innodb_log_file_size = 2097152
  22. xtrabackup: using the following InnoDB configuration for recovery:
  23. xtrabackup:   innodb_data_home_dir = ./
  24. xtrabackup:   innodb_data_file_path = ibdata1:128M:autoextend
  25. xtrabackup:   innodb_log_group_home_dir = ./
  26. xtrabackup:   innodb_log_files_in_group = 1
  27. xtrabackup:   innodb_log_file_size = 2097152
  28. xtrabackup: Starting InnoDB instance for recovery.
  29. xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
  30. InnoDB: Using atomics to ref count buffer pool pages
  31. InnoDB: The InnoDB memory heap is disabled
  32. InnoDB: Mutexes and rw_locks use GCC atomic builtins
  33. InnoDB: Memory barrier is not used
  34. InnoDB: Compressed tables use zlib 1.2.3
  35. InnoDB: Using CPU crc32 instructions
  36. InnoDB: Initializing buffer pool, size = 100.0M
  37. InnoDB: Completed initialization of buffer pool
  38. InnoDB: Highest supported file format is Barracuda.
  39. InnoDB: The log sequence numbers 2085708 and 2085708 in ibdata files do not match the log sequence number 2097320 in the ib_logfiles!
  40. InnoDB: Database was not shutdown normally!
  41. InnoDB: Starting crash recovery.
  42. InnoDB: Reading tablespace information from the .ibd files...
  43. InnoDB: Restoring possible half-written data pages 
  44. InnoDB: from the doublewrite buffer...
  45. InnoDB: Last MySQL binlog file position 0 9706, file name /data/3306/mysql-bin.000025
  46. InnoDB: 128 rollback segment(s) are active.
  47. InnoDB: Waiting for purge to start
  48. InnoDB: 5.6.24 started; log sequence number 2097320
  49. [notice (again)]
  50.   If you use binary log and don't use any hack of group commit,
  51.   the binary log position seems to be:
  52. InnoDB: Last MySQL binlog file position 0 9706, file name /data/3306/mysql-bin.000025
  53. xtrabackup: starting shutdown with innodb_fast_shutdown = 1
  54. InnoDB: FTS optimize thread exiting.
  55. InnoDB: Starting shutdown...
  56. InnoDB: Shutdown completed; log sequence number 2098397
  57. 160703 21:43:11  innobackupex: Restarting xtrabackup with command: xtrabackup  --defaults-file="/tmp/2016-07-03_21-07-38/backup-my.cnf"  --defaults-group="mysqld" --prepare --target-dir=/tmp/2016-07-03_21-07-38
  58. for creating ib_logfile*
  59. xtrabackup version 2.2.13 based on MySQL server 5.6.24 Linux (x86_64) (revision id: 70f4be3)
  60. xtrabackup: cd to /tmp/2016-07-03_21-07-38
  61. xtrabackup: This target seems to be already prepared.
  62. xtrabackup: notice: xtrabackup_logfile was already used to '--prepare'.
  63. xtrabackup: using the following InnoDB configuration for recovery:
  64. xtrabackup:   innodb_data_home_dir = ./
  65. xtrabackup:   innodb_data_file_path = ibdata1:128M:autoextend
  66. xtrabackup:   innodb_log_group_home_dir = ./
  67. xtrabackup:   innodb_log_files_in_group = 3
  68. xtrabackup:   innodb_log_file_size = 4194304
  69. xtrabackup: using the following InnoDB configuration for recovery:
  70. xtrabackup:   innodb_data_home_dir = ./
  71. xtrabackup:   innodb_data_file_path = ibdata1:128M:autoextend
  72. xtrabackup:   innodb_log_group_home_dir = ./
  73. xtrabackup:   innodb_log_files_in_group = 3
  74. xtrabackup:   innodb_log_file_size = 4194304
  75. xtrabackup: Starting InnoDB instance for recovery.
  76. xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
  77. InnoDB: Using atomics to ref count buffer pool pages
  78. InnoDB: The InnoDB memory heap is disabled
  79. InnoDB: Mutexes and rw_locks use GCC atomic builtins
  80. InnoDB: Memory barrier is not used
  81. InnoDB: Compressed tables use zlib 1.2.3
  82. InnoDB: Using CPU crc32 instructions
  83. InnoDB: Initializing buffer pool, size = 100.0M
  84. InnoDB: Completed initialization of buffer pool
  85. InnoDB: Setting log file ./ib_logfile101 size to 4 MB
  86. InnoDB: Setting log file ./ib_logfile1 size to 4 MB
  87. InnoDB: Setting log file ./ib_logfile2 size to 4 MB
  88. InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
  89. InnoDB: New log files created, LSN=2098397
  90. InnoDB: Highest supported file format is Barracuda.
  91. InnoDB: 128 rollback segment(s) are active.
  92. InnoDB: Waiting for purge to start
  93. InnoDB: 5.6.24 started; log sequence number 2098700
  94. [notice (again)]
  95.   If you use binary log and don't use any hack of group commit,
  96.   the binary log position seems to be:
  97. InnoDB: Last MySQL binlog file position 0 9706, file name /data/3306/mysql-bin.000025
  98. xtrabackup: starting shutdown with innodb_fast_shutdown = 1
  99. InnoDB: FTS optimize thread exiting.
  100. InnoDB: Starting shutdown...
  101. InnoDB: Shutdown completed; log sequence number 2099425
  102. 160703 21:43:13  innobackupex: completed OK!
查看完全备份时日志位置;
  1. [root@db02 2016-07-03_21-07-38]# cat xtrabackup_binlog_info 
  2. mysql-bin.000029 107

模式数据库修改

  1. create table student(
  2. id int(4) not null,
  3. name char(20) not null,
  4. age tinyint(2)  NOT NULL default '0',
  5. dept varchar(16)  default NULL
  6. );
  7. insert into student(id,name,age) values(1,'good',15);
  8. insert into student(id,name,age) values(2,'hehe',18);

模拟数据库损坏

进入数据库的data目录删除所有
  1. [root@db02 data]# rm -rf *
  2. mysql>show databases;  现在已经造成了数据库文件被删除,里面的数据消失
  3. +--------------------+
  4. | Database           |
  5. +--------------------+
  6. | information_schema |
  7. +--------------------+
  8. 1 row in set (0.00 sec)

还原完全备份

innobackupex命令的–copy-back选项用于执行恢复操作,其通过复制所有数据相关的文件至mysql服务器DATADIR目录中来执行恢复过程。innobackupex通过backup-my.cnf来获取DATADIR目录的相关信息

还原数据库语法

[root@db02 data]# innobackupex –user=root –password=123456 –socket=/data/3306/mysql.sock –defaults-file=/data/3306/my.cnf –copy-back /tmp/2016-07-03_21-07-38/
只是在恢复的时候加入了–copy-back
如果执行正确,会输出以下内容
  1. InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
  2. and Percona LLC and/or its affiliates 2009-2013.  All Rights Reserved.
  3. This software is published under
  4. the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
  5. Get the latest version of Percona XtraBackup, documentation, and help resources:
  6. http://www.percona.com/xb/p
  7. 160704 00:03:33  innobackupex: Starting the copy-back operation
  8. IMPORTANT: Please check that the copy-back run completes successfully.
  9.            At the end of a successful copy-back run innobackupex
  10.            prints "completed OK!".
  11. innobackupex: Starting to copy files in '/tmp/2016-07-03_21-07-38'
  12. innobackupex: back to original data directory '/data/3306/data'
  13. innobackupex: Copying '/tmp/2016-07-03_21-07-38/xtrabackup_info' to '/data/3306/data/xtrabackup_info'
  14. innobackupex: Copying '/tmp/2016-07-03_21-07-38/xtrabackup_binlog_pos_innodb' to '/data/3306/data/xtrabackup_binlog_pos_innodb'
  15. innobackupex: Creating directory '/data/3306/data/qqqqqqq41233'
  16. innobackupex: Copying '/tmp/2016-07-03_21-07-38/qqqqqqq41233/db.opt' to '/data/3306/data/qqqqqqq41233/db.opt'
  17. innobackupex: Creating directory '/data/3306/data/dadadadadadad'
  18. innobackupex: Copying '/tmp/2016-07-03_21-07-38/dadadadadadad/db.opt' to '/data/3306/data/dadadadadadad/db.opt'
  19. innobackupex: Creating directory '/data/3306/data/qqqqqqqq3'
  20. innobackupex: Copying '/tmp/2016-07-03_21-07-38/qqqqqqqq3/db.opt' to '/data/3306/data/qqqqqqqq3/db.opt'
  21. innobackupex: Creating directory '/data/3306/data/qqqqqqqq'
  22. innobackupex: Copying '/tmp/2016-07-03_21-07-38/qqqqqqqq/db.opt' to '/data/3306/data/qqqqqqqq/db.opt'
  23. innobackupex: Creating directory '/data/3306/data/qqqqqqq43'
  24. innobackupex: Copying '/tmp/2016-07-03_21-07-38/qqqqqqq43/db.opt' to '/data/3306/data/qqqqqqq43/db.opt'
  25. innobackupex: Creating directory '/data/3306/data/oldboy_gbk'
  26. innobackupex: Copying '/tmp/2016-07-03_21-07-38/oldboy_gbk/db.opt' to '/data/3306/data/oldboy_gbk/db.opt'
  27. innobackupex: Creating directory '/data/3306/data/oldboy'
  28. innobackupex: Copying '/tmp/2016-07-03_21-07-38/oldboy/student.frm' to '/data/3306/data/oldboy/student.frm'
  29. innobackupex: Copying '/tmp/2016-07-03_21-07-38/oldboy/db.opt' to '/data/3306/data/oldboy/db.opt'
  30. innobackupex: Creating directory '/data/3306/data/ooooooooooooooooo'
  31. innobackupex: Copying '/tmp/2016-07-03_21-07-38/ooooooooooooooooo/db.opt' to '/data/3306/data/ooooooooooooooooo/db.opt'
  32. innobackupex: Creating directory '/data/3306/data/performance_schema'
  33. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/file_instances.frm' to '/data/3306/data/performance_schema/file_instances.frm'
  34. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/setup_instruments.frm' to '/data/3306/data/performance_schema/setup_instruments.frm'
  35. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/setup_consumers.frm' to '/data/3306/data/performance_schema/setup_consumers.frm'
  36. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/file_summary_by_instance.frm' to '/data/3306/data/performance_schema/file_summary_by_instance.frm'
  37. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/events_waits_summary_by_instance.frm' to '/data/3306/data/performance_schema/events_waits_summary_by_instance.frm'
  38. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/mutex_instances.frm' to '/data/3306/data/performance_schema/mutex_instances.frm'
  39. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/db.opt' to '/data/3306/data/performance_schema/db.opt'
  40. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/performance_timers.frm' to '/data/3306/data/performance_schema/performance_timers.frm'
  41. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/cond_instances.frm' to '/data/3306/data/performance_schema/cond_instances.frm'
  42. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/setup_timers.frm' to '/data/3306/data/performance_schema/setup_timers.frm'
  43. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/events_waits_current.frm' to '/data/3306/data/performance_schema/events_waits_current.frm'
  44. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/file_summary_by_event_name.frm' to '/data/3306/data/performance_schema/file_summary_by_event_name.frm'
  45. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/events_waits_history.frm' to '/data/3306/data/performance_schema/events_waits_history.frm'
  46. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/events_waits_summary_by_thread_by_event_name.frm' to '/data/3306/data/performance_schema/events_waits_summary_by_thread_by_event_name.frm'
  47. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/events_waits_history_long.frm' to '/data/3306/data/performance_schema/events_waits_history_long.frm'
  48. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/events_waits_summary_global_by_event_name.frm' to '/data/3306/data/performance_schema/events_waits_summary_global_by_event_name.frm'
  49. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/rwlock_instances.frm' to '/data/3306/data/performance_schema/rwlock_instances.frm'
  50. innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/threads.frm' to '/data/3306/data/performance_schema/threads.frm'
  51. innobackupex: Creating directory '/data/3306/data/qqqqqqqq1'
  52. innobackupex: Copying '/tmp/2016-07-03_21-07-38/qqqqqqqq1/db.opt' to '/data/3306/data/qqqqqqqq1/db.opt'
  53. innobackupex: Creating directory '/data/3306/data/wordpress'
  54. innobackupex: Copying '/tmp/2016-07-03_21-07-38/wordpress/db.opt' to '/data/3306/data/wordpress/db.opt'
  55. innobackupex: Creating directory '/data/3306/data/aaa'
  56. innobackupex: Copying '/tmp/2016-07-03_21-07-38/aaa/db.opt' to '/data/3306/data/aaa/db.opt'
  57. innobackupex: Creating directory '/data/3306/data/mysql'
  58. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_keyword.MYD' to '/data/3306/data/mysql/help_keyword.MYD'
  59. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/general_log.CSV' to '/data/3306/data/mysql/general_log.CSV'
  60. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_keyword.MYI' to '/data/3306/data/mysql/help_keyword.MYI'
  61. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_topic.frm' to '/data/3306/data/mysql/help_topic.frm'
  62. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/procs_priv.MYD' to '/data/3306/data/mysql/procs_priv.MYD'
  63. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/servers.frm' to '/data/3306/data/mysql/servers.frm'
  64. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_transition_type.MYI' to '/data/3306/data/mysql/time_zone_transition_type.MYI'
  65. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone.frm' to '/data/3306/data/mysql/time_zone.frm'
  66. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/event.MYI' to '/data/3306/data/mysql/event.MYI'
  67. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/db.frm' to '/data/3306/data/mysql/db.frm'
  68. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/ndb_binlog_index.MYD' to '/data/3306/data/mysql/ndb_binlog_index.MYD'
  69. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/proc.MYD' to '/data/3306/data/mysql/proc.MYD'
  70. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/tables_priv.MYD' to '/data/3306/data/mysql/tables_priv.MYD'
  71. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/user.MYD' to '/data/3306/data/mysql/user.MYD'
  72. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_name.MYI' to '/data/3306/data/mysql/time_zone_name.MYI'
  73. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/general_log.CSM' to '/data/3306/data/mysql/general_log.CSM'
  74. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/event.frm' to '/data/3306/data/mysql/event.frm'
  75. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_topic.MYD' to '/data/3306/data/mysql/help_topic.MYD'
  76. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/procs_priv.frm' to '/data/3306/data/mysql/procs_priv.frm'
  77. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_name.MYD' to '/data/3306/data/mysql/time_zone_name.MYD'
  78. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/slow_log.CSM' to '/data/3306/data/mysql/slow_log.CSM'
  79. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_leap_second.MYI' to '/data/3306/data/mysql/time_zone_leap_second.MYI'
  80. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_topic.MYI' to '/data/3306/data/mysql/help_topic.MYI'
  81. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/proc.MYI' to '/data/3306/data/mysql/proc.MYI'
  82. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/columns_priv.MYD' to '/data/3306/data/mysql/columns_priv.MYD'
  83. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/slow_log.CSV' to '/data/3306/data/mysql/slow_log.CSV'
  84. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/func.frm' to '/data/3306/data/mysql/func.frm'
  85. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_leap_second.MYD' to '/data/3306/data/mysql/time_zone_leap_second.MYD'
  86. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/ndb_binlog_index.frm' to '/data/3306/data/mysql/ndb_binlog_index.frm'
  87. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_category.frm' to '/data/3306/data/mysql/help_category.frm'
  88. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/db.MYI' to '/data/3306/data/mysql/db.MYI'
  89. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/func.MYI' to '/data/3306/data/mysql/func.MYI'
  90. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/columns_priv.frm' to '/data/3306/data/mysql/columns_priv.frm'
  91. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/user.MYI' to '/data/3306/data/mysql/user.MYI'
  92. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/general_log.frm' to '/data/3306/data/mysql/general_log.frm'
  93. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_keyword.frm' to '/data/3306/data/mysql/help_keyword.frm'
  94. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/event.MYD' to '/data/3306/data/mysql/event.MYD'
  95. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_transition.frm' to '/data/3306/data/mysql/time_zone_transition.frm'
  96. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_relation.frm' to '/data/3306/data/mysql/help_relation.frm'
  97. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_transition_type.MYD' to '/data/3306/data/mysql/time_zone_transition_type.MYD'
  98. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/host.MYD' to '/data/3306/data/mysql/host.MYD'
  99. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_relation.MYI' to '/data/3306/data/mysql/help_relation.MYI'
  100. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/servers.MYD' to '/data/3306/data/mysql/servers.MYD'
  101. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/host.frm' to '/data/3306/data/mysql/host.frm'
  102. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_relation.MYD' to '/data/3306/data/mysql/help_relation.MYD'
  103. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone.MYI' to '/data/3306/data/mysql/time_zone.MYI'
  104. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/plugin.MYI' to '/data/3306/data/mysql/plugin.MYI'
  105. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/servers.MYI' to '/data/3306/data/mysql/servers.MYI'
  106. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/user.frm' to '/data/3306/data/mysql/user.frm'
  107. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/ndb_binlog_index.MYI' to '/data/3306/data/mysql/ndb_binlog_index.MYI'
  108. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/tables_priv.MYI' to '/data/3306/data/mysql/tables_priv.MYI'
  109. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/plugin.MYD' to '/data/3306/data/mysql/plugin.MYD'
  110. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/db.MYD' to '/data/3306/data/mysql/db.MYD'
  111. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/proxies_priv.frm' to '/data/3306/data/mysql/proxies_priv.frm'
  112. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_transition.MYI' to '/data/3306/data/mysql/time_zone_transition.MYI'
  113. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/plugin.frm' to '/data/3306/data/mysql/plugin.frm'
  114. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/host.MYI' to '/data/3306/data/mysql/host.MYI'
  115. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/columns_priv.MYI' to '/data/3306/data/mysql/columns_priv.MYI'
  116. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_transition_type.frm' to '/data/3306/data/mysql/time_zone_transition_type.frm'
  117. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_category.MYD' to '/data/3306/data/mysql/help_category.MYD'
  118. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/procs_priv.MYI' to '/data/3306/data/mysql/procs_priv.MYI'
  119. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_name.frm' to '/data/3306/data/mysql/time_zone_name.frm'
  120. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone.MYD' to '/data/3306/data/mysql/time_zone.MYD'
  121. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/proc.frm' to '/data/3306/data/mysql/proc.frm'
  122. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/func.MYD' to '/data/3306/data/mysql/func.MYD'
  123. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/proxies_priv.MYD' to '/data/3306/data/mysql/proxies_priv.MYD'
  124. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_leap_second.frm' to '/data/3306/data/mysql/time_zone_leap_second.frm'
  125. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_category.MYI' to '/data/3306/data/mysql/help_category.MYI'
  126. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/proxies_priv.MYI' to '/data/3306/data/mysql/proxies_priv.MYI'
  127. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_transition.MYD' to '/data/3306/data/mysql/time_zone_transition.MYD'
  128. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/tables_priv.frm' to '/data/3306/data/mysql/tables_priv.frm'
  129. innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/slow_log.frm' to '/data/3306/data/mysql/slow_log.frm'
  130. innobackupex: Creating directory '/data/3306/data/cyh'
  131. innobackupex: Copying '/tmp/2016-07-03_21-07-38/cyh/db.opt' to '/data/3306/data/cyh/db.opt'
  132. innobackupex: Creating directory '/data/3306/data/wuyi'
  133. innobackupex: Copying '/tmp/2016-07-03_21-07-38/wuyi/db.opt' to '/data/3306/data/wuyi/db.opt'
  134. innobackupex: Starting to copy InnoDB system tablespace
  135. innobackupex: in '/tmp/2016-07-03_21-07-38'
  136. innobackupex: back to original InnoDB data directory '/data/3306/data'
  137. innobackupex: Copying '/tmp/2016-07-03_21-07-38/ibdata1' to '/data/3306/data/ibdata1'
  138. innobackupex: Starting to copy InnoDB undo tablespaces
  139. innobackupex: in '/tmp/2016-07-03_21-07-38'
  140. innobackupex: back to '/data/3306/data'
  141. innobackupex: Starting to copy InnoDB log files
  142. innobackupex: in '/tmp/2016-07-03_21-07-38'
  143. innobackupex: back to original InnoDB log directory '/data/3306/data'
  144. innobackupex: Copying '/tmp/2016-07-03_21-07-38/ib_logfile1' to '/data/3306/data/ib_logfile1'
  145. innobackupex: Copying '/tmp/2016-07-03_21-07-38/ib_logfile0' to '/data/3306/data/ib_logfile0'
  146. innobackupex: Copying '/tmp/2016-07-03_21-07-38/ib_logfile2' to '/data/3306/data/ib_logfile2'
  147. innobackupex: Finished copying back files.
  148. 160704 00:03:38  innobackupex: completed OK!
我们可以在查看结果:
mysql>select * from student;  #我们添加的数据也都回来了
+—-+——–+—–+——+
| id | name   | age | dept |
+—-+——–+—–+——+
|  0 | 1      |   0 | NULL |
|  2 | oldboy |   0 | NULL |
|  3 | good   |   0 | NULL |
|  3 | good   |  15 | NULL |
+—-+——–+—–+——+
4 rows in set (0.00 sec)

增量备份二进制文件:

  1. [root@db02 2016-07-03_21-07-38]# mysqlbinlog --start-position=107 /data/3306/mysql-bin.000029 >/tmp/$(date +%F).sql
  2. 注:--start-position=107可以不指定,因为107是一个日志的默认起始位置。

还原增量备份

为了防止还原时产生大量的二进制日志,在还原可临时关闭二进制日志后再还原;
  1. mysql> set sql_log_bin=0; 
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql> SOURCE /tmp/2016-07-03_21-07-38/2016-07-03.sql

使用innobackupex进行增量备份

前面我们进行增量备份时,使用的还是老方法:备份二进制日志。其实xtrabackup还支持进行增量备份。
每个InnoDB的页面都会包含一个LSN信息,每当相关的数据发生改变,相关的页面的LSN就会自动增长。这正是InnoDB表可以进行增量备份的基础,即innobackupex通过备份上次完整备份之后发生改变的页面来实现。

增量备份基本语法:

1.模拟插入数据
  1. mysql>create table test(
  2.     -> id int(4) not null,
  3.     -> name char(20) not null,
  4.     -> age tinyint(2)  NOT NULL default '0',
  5.     -> dept varchar(16)  default NULL
  6.     -> );
  7. Query OK, 0 rows affected (0.03 sec)
  8. mysql>insert into test(id,name,age) values(1,'oldboy',19);
  9. mysql>insert into test(id,name,age) values(2,'oldgro;',20);

2.进行增量备份

  1. [root@db02 tmp]# innobackupex --user=root --password=123456 --socket=/data/3306/mysql.sock --defaults-file=/data/3306/my.cnf --incremental /tmp/ --incremental-basedir=/tmp/2016-07-04_00-21-06/
如果没有错误提示就说说明没有问题
  1. InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
  2. and Percona LLC and/or its affiliates 2009-2013.  All Rights Reserved.
  3. This software is published under
  4. the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
  5. Get the latest version of Percona XtraBackup, documentation, and help resources:
  6. http://www.percona.com/xb/p
  7. 160704 00:22:03  innobackupex: Executing a version check against the server...
  8. 160704 00:22:03  innobackupex: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_file=/data/3306/my.cnf;mysql_read_default_group=xtrabackup;mysql_socket=/data/3306/mysql.sock' as 'root'  (using password: YES).
  9. 160704 00:22:03  innobackupex: Connected to MySQL server
  10. 160704 00:22:03  innobackupex: Done.
  11. 160704 00:22:03  innobackupex: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_file=/data/3306/my.cnf;mysql_read_default_group=xtrabackup;mysql_socket=/data/3306/mysql.sock' as 'root'  (using password: YES).
  12. 160704 00:22:03  innobackupex: Connected to MySQL server
  13. 160704 00:22:03  innobackupex: Starting the backup operation
  14. IMPORTANT: Please check that the backup run completes successfully.
  15.            At the end of a successful backup run innobackupex
  16.            prints "completed OK!".
  17. innobackupex:  Using server version 5.5.49-log
  18. innobackupex: Created backup directory /tmp/2016-07-04_00-22-03
  19. 160704 00:22:03  innobackupex: Starting ibbackup with command: xtrabackup  --defaults-file="/data/3306/my.cnf"  --defaults-group="mysqld" --backup --suspend-at-end --target-dir=/tmp/2016-07-04_00-22-03 --tmpdir=/tmp --extra-lsndir='/tmp' --incremental-basedir='/tmp/2016-07-04_00-21-06/'
  20. innobackupex: Waiting for ibbackup (pid=3312) to suspend
  21. innobackupex: Suspend file '/tmp/2016-07-04_00-22-03/xtrabackup_suspended_2'
  22. xtrabackup version 2.2.13 based on MySQL server 5.6.24 Linux (x86_64) (revision id: 70f4be3)
  23. incremental backup from 2099425 is enabled.
  24. xtrabackup: uses posix_fadvise().
  25. xtrabackup: cd to /data/3306/data
  26. xtrabackup: open files limit requested 1024, set to 65535
  27. xtrabackup: using the following InnoDB configuration:
  28. xtrabackup:   innodb_data_home_dir = ./
  29. xtrabackup:   innodb_data_file_path = ibdata1:128M:autoextend
  30. xtrabackup:   innodb_log_group_home_dir = ./
  31. xtrabackup:   innodb_log_files_in_group = 3
  32. xtrabackup:   innodb_log_file_size = 4194304
  33. >> log scanned up to (2099425)
  34. xtrabackup: Generating a list of tablespaces
  35. [01] Copying ./ibdata1 to /tmp/2016-07-04_00-22-03/ibdata1.delta
  36. [01]        ...done
  37. >> log scanned up to (2099425)
  38. xtrabackup: Creating suspend file '/tmp/2016-07-04_00-22-03/xtrabackup_suspended_2' with pid '3312'
  39. 160704 00:22:05  innobackupex: Continuing after ibbackup has suspended
  40. 160704 00:22:05  innobackupex: Executing FLUSH NO_WRITE_TO_BINLOG TABLES...
  41. 160704 00:22:05  innobackupex: Executing FLUSH TABLES WITH READ LOCK...
  42. 160704 00:22:05  innobackupex: All tables locked and flushed to disk
  43. 160704 00:22:05  innobackupex: Starting to backup non-InnoDB tables and files
  44. innobackupex: in subdirectories of '/data/3306/data/'
  45. innobackupex: Backing up file '/data/3306/data//qqqqqqq41233/db.opt'
  46. innobackupex: Backing up file '/data/3306/data//dadadadadadad/db.opt'
  47. innobackupex: Backing up file '/data/3306/data//qqqqqqqq3/db.opt'
  48. >> log scanned up to (2099425)
  49. innobackupex: Backing up file '/data/3306/data//qqqqqqqq/db.opt'
  50. innobackupex: Backing up file '/data/3306/data//qqqqqqq43/db.opt'
  51. innobackupex: Backing up file '/data/3306/data//oldboy_gbk/db.opt'
  52. innobackupex: Backing up file '/data/3306/data//oldboy/student.frm'
  53. innobackupex: Backing up file '/data/3306/data//oldboy/db.opt'
  54. innobackupex: Backing up file '/data/3306/data//ooooooooooooooooo/db.opt'
  55. innobackupex: Backing up files '/data/3306/data//performance_schema/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (18 files)
  56. innobackupex: Backing up file '/data/3306/data//qqqqqqqq1/db.opt'
  57. innobackupex: Backing up file '/data/3306/data//wordpress/db.opt'
  58. innobackupex: Backing up file '/data/3306/data//aaa/db.opt'
  59. innobackupex: Backing up files '/data/3306/data//mysql/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (72 files)
  60. innobackupex: Backing up file '/data/3306/data//cyh/db.opt'
  61. innobackupex: Backing up file '/data/3306/data//wuyi/db.opt'
  62. 160704 00:22:06  innobackupex: Finished backing up non-InnoDB tables and files
  63. 160704 00:22:06  innobackupex: Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
  64. 160704 00:22:06  innobackupex: Waiting for log copying to finish
  65. xtrabackup: The latest check point (for incremental): '2099425'
  66. xtrabackup: Stopping log copying thread.
  67. .>> log scanned up to (2099425)
  68. xtrabackup: Creating suspend file '/tmp/2016-07-04_00-22-03/xtrabackup_log_copied' with pid '3312'
  69. xtrabackup: Transaction log of lsn (2099425) to (2099425) was copied.
  70. 160704 00:22:07  innobackupex: All tables unlocked
  71. innobackupex: Backup created in directory '/tmp/2016-07-04_00-22-03'
  72. innobackupex: MySQL binlog position: filename 'mysql-bin.000029', position 1258
  73. 160704 00:22:07  innobackupex: Connection to database server closed
  74. 160704 00:22:07  innobackupex: completed OK!
查看xtrabackup_checkpoints

  1. backup_type = incremental
  2. from_lsn = 1768597
  3. to_lsn = 1769413
  4. last_lsn = 1769413
  5. compact = 0
  6. recover_binlog_info = 0

准备

准备(prepare)增量备份与整理完全备份有着一些不同,尤其是要注意的是:
(1)需要在每个备份(包括完全和增量备份)上,将已经提交的事务进行“重放”。
“重放”之后,所有的备份数据将合并到完全备份上
(2)基于所有的备份将末提交的事务进行“回滚”。
执行完全备份的redo;
# innobackupex –apply-log –redo-only BASE-DIR
  1. [root@db02 data]# innobackupex --user=root --password=123456 --socket=/data/3306/mysql.sock --defaults-file=/data/3306/my.cnf --apply-log --redo-only /tmp/2016-07-04_00-21-06/
接着执行第一个增量:
  1. 例子# innobackupex --apply-log --redo-only BASE-DIR --incremental-dir=INCREMENTAL-DIR-1
  2. [root@db02 data]# innobackupex --user=root --password=123456 --socket=/data/3306/mysql.sock --defaults-file=/data/3306/my.cnf --apply-log --redo-only /tmp/2016-07-04_00-21-06/ --incremental-dir=/tmp/2016-07-04_00-34-48/
而后是第二个增量:因为我们只执行了一次增量,所以只有一个文件夹
  1. 例子# innobackupex --apply-log --redo-only BASE-DIR --incremental-dir=INCREMENTAL-DIR-2
  2. [root@db02 data]# innobackupex --user=root --password=123456 --socket=/data/3306/mysql.sock --defaults-file=/data/3306/my.cnf --apply-log --redo-only /tmp/2016-07-04_00-21-06/ --incremental-dir=/tmp/2016-07-04_00-34-48/
提示:
其中BASE-DIR指的是完全备份所在的目录,而INCREMENTAL-DIR-1指定的是第一次增量备份的目录,INCREMENTAL-DIR=2指的是第二次增量备份的目录,其他依次类推,即如果有多次增量备份,每一次都要执行如上操作。

Xtrabackup的“流”及“备份压缩”功能

Xtrabackup对备份的数据文件支持“流”功能,即可以将备份的数据通过STDOUT传输给tar程序进行归档,而不是默认的直接保存至某备份目录中。要使用此功能,仅需要使用–stream选项即可。如:

# innobackupex –stream=tar  /backup | gzip > /backup/`date +%F_%H-%M-%S`.tar.gz

甚至也可以使用类似如下命令将数据备份至其它服务器:

# innobackupex –stream=tar  /backup | ssh user@www.magedu.com  “cat –  > /backups/`date +%F_%H-%M-%S`.tar” 

此外,在执行本地备份时,还可以使用–parallel选项对多个文件进行并行复制。此选项用于指定在复制时启动的线程数目。当然,在实际进行备
份时要利用此功能的便利性,也需要启用innodb_file_per_table选项或共享的表空间通过innodb_data_file_path选
项存储在多个ibdata文件中。对某一数据库的多个文件的复制无法利用到此功能。其简单使用方法如下:

# innobackupex –parallel  /path/to/backup

同时,innobackupex备份的数据文件也可以存储至远程主机,这可以使用–remote-host选项来实现:

# innobackupex –remote-host=root@www.magedu.com  /path/IN/REMOTE/HOST/to/backup    

导入或导出单张表

默认情况下,InnoDB表不能通过直接复制表文件的方式在mysql服务器之间进行移植,即便使用了innodb_file_per_table 选项。而使用Xtrabackup工具可以实现此种功能,不过,此时需要导出表的mysql服务器启用了innodb_file_per_table 选项(严格来说,是要导出的表在其创建之前,mysql服务器就启用了innodb_file_per_table选项),并且导入表的服务器同 时启用了innodb_file_per_tableinnodb_expand_import选项。

 “导出

导出表是在备份的prepare阶段进行的,因此,一旦完全备份完成,就可以在prepare过程中通过–export选项将某表导出了:

# innobackupex –apply-log –export /path/to/backup

此命令会为每个innodb表的表空间创建一个以.exp结尾的文件,这些以.exp结尾的文件则可以用于导入至其它服务器。

导入

  1. 要在mysql服务器上导入来自于其它服务器的某innodb表,需要先在当前服务器上创建一个跟原表表结构一致的表,而后才能实现将表导入:
  2. mysql> CREATE TABLE mytable (...)  ENGINE=InnoDB;
  3. 然后将此表的表空间删除:
  4. mysql> ALTER TABLE mydatabase.mytable  DISCARD TABLESPACE;
  5. 接下来,将来自于“导出”表的服务器的mytable表的mytable.ibdmytable.exp文件复制到当前服务器的数据目录,然后使用如下命令将其“导入”:
  6. mysql> ALTER TABLE mydatabase.mytable  IMPORT TABLESPACE;

使用Xtrabackup对数据库进行部分备份

Xtrabackup也可以实现部分备份,即只备份某个或某些指定的数据库或某数据库中的某个或某些表。但要使用此功能,必须启用 innodb_file_per_table选项,即每张表保存为一个独立的文件。同时,其也不支持–stream选项,即不支持将数据通过管道传输给 其它程序进行处理。

此外,还原部分备份跟还原全部数据的备份也有所不同,即你不能通过简单地将prepared的部分备份使用–copy-back选项直接复制回数 据目录,而是要通过导入表的方向来实现还原。当然,有些情况下,部分备份也可以直接通过–copy-back进行还原,但这种方式还原而来的数据多数会 产生数据不一致的问题,因此,无论如何不推荐使用这种方式。

创建部分备份

创建部分备份的方式有三种:正则表达式(–include), 枚举表文件(–tables-file)和列出要备份的数据库(–databases)

使用–include

使用–include时,要求为其指定要备份的表的完整名称,即形如databasename.tablename,如:

# innobackupex –include=’^mageedu[.]tb1′ 
/path/to/backup

使用–tables-file

此选项的参数需要是一个文件名,此文件中每行包含一个要备份的表的完整名称;如:

  1. # echo -e 'mageedu.tb1\nmageedu.tb2' > /tmp/tables.txt
  2. # innobackupex --tables-file=/tmp/tables.txt  /path/to/backup

使用–databases

此选项接受的参数为数据名,如果要指定多个数据库,彼此间需要以空格隔开;同时,在指定某数据库时,也可以只指定其中的某张表。此外,此选项也可以接受一个文件为参数,文件中每一行为一个要备份的对象。如:

# innobackupex –databases=”mageedu testdb” 
/path/to/backup

整理(preparing)部分备份

prepare部分备份的过程类似于导出表的过程,要使用–export选项进行:

# innobackupex –apply-log –export 
/pat/to/partial/backup

此命令执行过程中,innobackupex会调用xtrabackup命令从数据字典中移除缺失的表,因此,会显示出许多关于表不存在类的警告信息。同时,也会显示出为备份文件中存在的表创建.exp文件的相关信息。

还原部分备份

还原部分备份的过程跟导入表的过程相同。当然,也可以通过直接复制prepared状态的备份直接至数据目录中实现还原,不要此时要求数据目录处于一致状态。

本文转载:http://www.toxingwang.com/database/mysql/1539.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/575996.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

MySQL双主配置

双机热备的概念简单说一下,就是要保持两个数据库的状态自动同步。对任何一个数据库的操作都自动应用到另外一个数据库,始终保持两个数据库数据一致。 这样做的好处多。 1. 可以做灾备,其中一个坏了可以切换到另一个。 2. 可以做负载均衡&…

DSPBuilder笔记

一、位宽设置 在DSPBuilder中,数据在内部采用二进制定点数表示方法,数据可以设置成无符号整数、有符号整数和有符号小数等,其中有符号数由符号位、整数位和小数位组成(有符号整数的小数位为0),位宽根据需求…

MySQL主从复制原理、半同步操作步骤及原理

1.1 企业Linux运维场景数据同步方案 1.1.1 文件级别的异机同步方案 1、scp/sftp/nc 命令可以实现远程数据同步。2、搭建ftp/http/svn/nfs 服务器,然后在客户端上也可以把数据同步到服务器。3、搭建samba文件共享服务,然后在客户端上也可以把数据同步到服…

基于.Net 写我自己的Ajax后台框架AjaxFramework

小小目录: 为什么要写自己的Ajax后台框架 框架的简单设计说明 框架如何使用 框架使用效果图 框架的优缺点 框架源码下载1、为什么要写自己的Ajax后台框架 现在Ajax在web应用方面已经用的稀巴烂了,如果你做一个网站没有用到ajax都不好意思拿出手&…

MySQL备份恢复与日志

MySQL 数据库的备份与恢复 1.1 备份数据的意义 第一是保护公司的数据,第二是网站7*24小时提供服务1.2 备份单个数据库参数使用 MySQL数据库自带了一个很好用的备份命令,就是mysqldump,它的基本使用如下;语法:mysqldum…

MySQL入门介绍

数据库介绍 1.1 什么是数据库? 简单的说,数据库(英文Dtabase)就是一个存放数据的仓库,这个仓库是按照一定的数据结果(数据结构是指数据的组织形式或数据之间的联系)来组织、存储的、我们可以通…

zoj 2526(一道很好的最短路应用题)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId1538 题意:最短路问题,但是要求出最短路的条数,同时要求出所有可能的最短路选择中javabean最多的情况。 思路:求到终点的最短路径用Dijkstra&am…

MySQL常用命令大全

登录MySQL方法 单实例MySQL登录的方法 mysql #刚装完系统无密码情况登录方式,不需要密码 mysql -u root #刚装完系统无密码的情况登录 mysql -uroot -p #这里标准的dba命令行登录 mysql -uroot -poldboy #非脚本里一般不这样用,密码明文会泄露密码…

服务器安全之iptables iptables

服务器安全之iptables 感谢老男孩老师为我们讲解iptables 优化之路 iptables防火墙简介 Netfilter/Iptables(以下简称Iptables)是unix/linux自带的一款优秀且开放源代码的安全自由的**基于包过滤的防火墙工具**,它的功能十分强大&#xff0…

MC新手入门(三十)------ 逻辑运算符和表达式

游戏设计中提供了三种逻辑运算符: 1)&& 与运算 2)|| 或运算 3) !非运算 游戏设计中我们常常要用到上面的逻辑运算,例如:当在双人游戏中都要实现两人同时存活才能过关,…

Nagios 配置及监控

Nagios 监控 在互联网日益发展的今天,监控的重要性已经不言而喻。可能打开一个URL要经过6-7层的处理,如果出了问题而没有监控将很难定位到问题所在。那哪些内容需要监控呢? 1.本地资源 (1) 负载:uptime; (2) CPU&…

SSH 配置

SSH 批量管理 SSH介绍 SSH是Secure Shell Protocol的简写,由IETF网络工作小组(Network working Group)指定;在进行数据传输之前,SSH先对联机数据包通过加密技术进行加密处理,加密后在进行数据传输。确保了传…

服务器重启导致无法启动MySQL

今天服务器受到DDOS攻击,笔者脑残重启了一下服务器。结果造成MySQL服务器无法启动mysql日志见下图。160803 17:43:47 mysqld_safe Starting mysqld daemon with databases from /application/mysql/data160803 17:43:47 [Note] /application/mysql/bin/mysqld (mysq…

架构师之DNS实战

架构师 DNS实战 老男孩教育 DNS简介 1. DNS的出现及演化 网络出现的早起是使用IP地址通讯的,那是就几台主机通讯。但是随着接入网络主机的增多,这种数字标识的地址非常不便于记忆,UNIX上就出现了建立一个叫做hosts的文件(Linux和W…

打包jar文件后的spring部署及hibernate自动建表经验总结

楔子 用springhibernate做一个服务器运行程序,在部署到服务器时(打包成jar,在window server2008下运行),出现了以下两个纠结问题: 1. 加载不了Spring容器 2. hibernate.hbm2ddl.auto 到了服务器不能自动建表…

我是一个线程 [转]

我是一个线程,我一出生就被编了个号:0x3704,然后被领到一个昏暗的屋子里,在这里我发现了很多和我一模一样的同伴。 我身边的同伴0x6900 待的时间比较长,他带着沧桑的口气对我说:“我们线程的宿命就是处理包…

自动化运维之–Cobbler

Cobbler 自动化 Cobbler简介 Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows。该工具使用python开发,小巧轻便(才15k行python代码),使用简单的命令即可完成PXE网络安装环境的配置&…

开源jumpserver 堡垒机搭建

一、环境 CentOS 6.x x86_64 mini service iptables stop 关闭SELinux的方法: 修改/etc/selinux/config文件中的SELINUX”” 为 disabled ,然后重启。 如果不想重启系统,使用命令setenforce 0 1.指定yum源 wget -O /etc/yum.repos.d/e…

Shell 变量及函数讲解 [2]

Shell 变量的输入 Shell变量除了可以直接赋值或脚本传参外,还可以使用read命令从标准输入获得,read为bash内置命令,可以通过help read查看帮助【语法格式】read [参数] [变量名]【常用参数】-p prompt:设置提示信息-t timeout&…

java大作业私人管家系统_重庆管家婆软件丨管家婆工贸PRO的E-MES管理详解

其实,ERP和MES在制造操作中扮演着独立而又互补的角色。ERP能将企业所有方面的数据进行实时、可用的全面集成,为管理决策提供高效、准确的业务决策支持;MES则能加强MRP计划的执行,把MRP计划同车间作业现场控制通过执行系统联系起来。这些“现场…