Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Hotbackup的一个很好的替代品。
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 | MySQL, Percona Server, MariaDB,Percona XtraDB Cluster, MariaDB 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 |
xtrabackup安装方法
可以下载源码编译安装,也可以下载适合的RPM包或者yum进行安装。1、Installing Percona XtraBackup from Percona yum repository
yum install -y http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
测试是否存在软件包
... 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
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
What’s in each RPM package?¶
检查安装结果:
[root@db01 ~]# rpm -qa|grep xtrabackup
percona-xtrabackup-22-2.2.13-1.el6.x86_64
使用xtrabackup实现对MySQL的备份
1.完全备份
[root@db02 3306]# innobackupex --user=root --password=123456 --socket=/data/3306/mysql.sock --defaults-file=/data/3306/my.cnf /tmp/
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona LLC and/or its affiliates 2009-2013. All Rights Reserved.
This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
Get the latest version of Percona XtraBackup, documentation, and help resources:
http://www.percona.com/xb/p
160703 20:00:13 innobackupex: Executing a version check against the server...
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).
160703 20:00:13 innobackupex: Connected to MySQL server
160703 20:00:13 innobackupex: Done.
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).
160703 20:00:13 innobackupex: Connected to MySQL server
160703 20:00:13 innobackupex: Starting the backup operation
IMPORTANT: Please check that the backup run completes successfully.
At the end of a successful backup run innobackupex
prints "completed OK!".
innobackupex: Using server version 5.5.49-log
innobackupex: Created backup directory /tmp/2016-07-03_20-00-13
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'
innobackupex: Waiting for ibbackup (pid=2586) to suspend
innobackupex: Suspend file '/tmp/2016-07-03_20-00-13/xtrabackup_suspended_2'
xtrabackup version 2.2.13 based on MySQL server 5.6.24 Linux (x86_64) (revision id: 70f4be3)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /data/3306/data
xtrabackup: open files limit requested 1024, set to 65535
xtrabackup: using the following InnoDB configuration:
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:128M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 3
xtrabackup: innodb_log_file_size = 4194304
>> log scanned up to (2097320)
xtrabackup: Generating a list of tablespaces
[01] Copying ./ibdata1 to /tmp/2016-07-03_20-00-13/ibdata1
>> log scanned up to (2097320)
>> log scanned up to (2097320)
>> log scanned up to (2097320)
>> log scanned up to (2097320)
>> log scanned up to (2097320)
[01] ...done
>> log scanned up to (2097320)
xtrabackup: Creating suspend file '/tmp/2016-07-03_20-00-13/xtrabackup_suspended_2' with pid '2586'
160703 20:00:20 innobackupex: Continuing after ibbackup has suspended
160703 20:00:20 innobackupex: Executing FLUSH NO_WRITE_TO_BINLOG TABLES...
160703 20:00:20 innobackupex: Executing FLUSH TABLES WITH READ LOCK...
160703 20:00:20 innobackupex: All tables locked and flushed to disk
160703 20:00:20 innobackupex: Starting to backup non-InnoDB tables and files
innobackupex: in subdirectories of '/data/3306/data/'
innobackupex: Backing up file '/data/3306/data//qqqqqqq41233/db.opt'
>> log scanned up to (2097320)
innobackupex: Backing up file '/data/3306/data//dadadadadadad/db.opt'
innobackupex: Backing up file '/data/3306/data//qqqqqqqq3/db.opt'
innobackupex: Backing up file '/data/3306/data//qqqqqqqq/db.opt'
innobackupex: Backing up file '/data/3306/data//qqqqqqq43/db.opt'
innobackupex: Backing up file '/data/3306/data//oldboy_gbk/db.opt'
innobackupex: Backing up file '/data/3306/data//oldboy/student.frm'
innobackupex: Backing up file '/data/3306/data//oldboy/db.opt'
innobackupex: Backing up file '/data/3306/data//ooooooooooooooooo/db.opt'
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)
innobackupex: Backing up file '/data/3306/data//qqqqqqqq1/db.opt'
innobackupex: Backing up file '/data/3306/data//wordpress/db.opt'
innobackupex: Backing up file '/data/3306/data//aaa/db.opt'
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)
innobackupex: Backing up file '/data/3306/data//cyh/db.opt'
innobackupex: Backing up file '/data/3306/data//wuyi/db.opt'
160703 20:00:21 innobackupex: Finished backing up non-InnoDB tables and files
160703 20:00:21 innobackupex: Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
160703 20:00:21 innobackupex: Waiting for log copying to finish
>> log scanned up to (2097320)
xtrabackup: The latest check point (for incremental): '2097320'
xtrabackup: Stopping log copying thread.
.>> log scanned up to (2097320)
xtrabackup: Creating suspend file '/tmp/2016-07-03_20-00-13/xtrabackup_log_copied' with pid '2586'
xtrabackup: Transaction log of lsn (2097320) to (2097320) was copied.
160703 20:00:22 innobackupex: All tables unlocked
innobackupex: Backup created in directory '/tmp/2016-07-03_20-00-13'
innobackupex: MySQL binlog position: filename 'mysql-bin.000029', position 107
160703 20:00:22 innobackupex: Connection to database server closed
160703 20:00:22 innobackupex: completed OK!
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
[root@localhost ~]# cp /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
备份后的文件:
mysql> GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO ‘bkpuser’@’localhost’;
mysql> FLUSH PRIVILEGES;
2. 准备(prepare)一个完整备份
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona LLC and/or its affiliates 2009-2013. All Rights Reserved.
This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
Get the latest version of Percona XtraBackup, documentation, and help resources:
http://www.percona.com/xb/p
160703 21:43:08 innobackupex: Starting the apply-log operation
IMPORTANT: Please check that the apply-log run completes successfully.
At the end of a successful apply-log run innobackupex
prints "completed OK!".
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
xtrabackup version 2.2.13 based on MySQL server 5.6.24 Linux (x86_64) (revision id: 70f4be3)
xtrabackup: cd to /tmp/2016-07-03_21-07-38
xtrabackup: This target seems to be not prepared yet.
xtrabackup: xtrabackup_logfile detected: size=2097152, start_lsn=(2097320)
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:128M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 2097152
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:128M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 2097152
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: Using atomics to ref count buffer pool pages
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Memory barrier is not used
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, size = 100.0M
InnoDB: Completed initialization of buffer pool
InnoDB: Highest supported file format is Barracuda.
InnoDB: The log sequence numbers 2085708 and 2085708 in ibdata files do not match the log sequence number 2097320 in the ib_logfiles!
InnoDB: Database was not shutdown normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages
InnoDB: from the doublewrite buffer...
InnoDB: Last MySQL binlog file position 0 9706, file name /data/3306/mysql-bin.000025
InnoDB: 128 rollback segment(s) are active.
InnoDB: Waiting for purge to start
InnoDB: 5.6.24 started; log sequence number 2097320
[notice (again)]
If you use binary log and don't use any hack of group commit,
the binary log position seems to be:
InnoDB: Last MySQL binlog file position 0 9706, file name /data/3306/mysql-bin.000025
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 2098397
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
for creating ib_logfile*
xtrabackup version 2.2.13 based on MySQL server 5.6.24 Linux (x86_64) (revision id: 70f4be3)
xtrabackup: cd to /tmp/2016-07-03_21-07-38
xtrabackup: This target seems to be already prepared.
xtrabackup: notice: xtrabackup_logfile was already used to '--prepare'.
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:128M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 3
xtrabackup: innodb_log_file_size = 4194304
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:128M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 3
xtrabackup: innodb_log_file_size = 4194304
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: Using atomics to ref count buffer pool pages
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Memory barrier is not used
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, size = 100.0M
InnoDB: Completed initialization of buffer pool
InnoDB: Setting log file ./ib_logfile101 size to 4 MB
InnoDB: Setting log file ./ib_logfile1 size to 4 MB
InnoDB: Setting log file ./ib_logfile2 size to 4 MB
InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
InnoDB: New log files created, LSN=2098397
InnoDB: Highest supported file format is Barracuda.
InnoDB: 128 rollback segment(s) are active.
InnoDB: Waiting for purge to start
InnoDB: 5.6.24 started; log sequence number 2098700
[notice (again)]
If you use binary log and don't use any hack of group commit,
the binary log position seems to be:
InnoDB: Last MySQL binlog file position 0 9706, file name /data/3306/mysql-bin.000025
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 2099425
160703 21:43:13 innobackupex: completed OK!
[root@db02 2016-07-03_21-07-38]# cat xtrabackup_binlog_info
mysql-bin.000029 107
模式数据库修改
create table student(
id int(4) not null,
name char(20) not null,
age tinyint(2) NOT NULL default '0',
dept varchar(16) default NULL
);
insert into student(id,name,age) values(1,'good',15);
insert into student(id,name,age) values(2,'hehe',18);
模拟数据库损坏
[root@db02 data]# rm -rf *
mysql>show databases; 现在已经造成了数据库文件被删除,里面的数据消失
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)
还原完全备份
还原数据库语法
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona LLC and/or its affiliates 2009-2013. All Rights Reserved.
This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
Get the latest version of Percona XtraBackup, documentation, and help resources:
http://www.percona.com/xb/p
160704 00:03:33 innobackupex: Starting the copy-back operation
IMPORTANT: Please check that the copy-back run completes successfully.
At the end of a successful copy-back run innobackupex
prints "completed OK!".
innobackupex: Starting to copy files in '/tmp/2016-07-03_21-07-38'
innobackupex: back to original data directory '/data/3306/data'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/xtrabackup_info' to '/data/3306/data/xtrabackup_info'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/xtrabackup_binlog_pos_innodb' to '/data/3306/data/xtrabackup_binlog_pos_innodb'
innobackupex: Creating directory '/data/3306/data/qqqqqqq41233'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/qqqqqqq41233/db.opt' to '/data/3306/data/qqqqqqq41233/db.opt'
innobackupex: Creating directory '/data/3306/data/dadadadadadad'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/dadadadadadad/db.opt' to '/data/3306/data/dadadadadadad/db.opt'
innobackupex: Creating directory '/data/3306/data/qqqqqqqq3'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/qqqqqqqq3/db.opt' to '/data/3306/data/qqqqqqqq3/db.opt'
innobackupex: Creating directory '/data/3306/data/qqqqqqqq'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/qqqqqqqq/db.opt' to '/data/3306/data/qqqqqqqq/db.opt'
innobackupex: Creating directory '/data/3306/data/qqqqqqq43'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/qqqqqqq43/db.opt' to '/data/3306/data/qqqqqqq43/db.opt'
innobackupex: Creating directory '/data/3306/data/oldboy_gbk'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/oldboy_gbk/db.opt' to '/data/3306/data/oldboy_gbk/db.opt'
innobackupex: Creating directory '/data/3306/data/oldboy'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/oldboy/student.frm' to '/data/3306/data/oldboy/student.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/oldboy/db.opt' to '/data/3306/data/oldboy/db.opt'
innobackupex: Creating directory '/data/3306/data/ooooooooooooooooo'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/ooooooooooooooooo/db.opt' to '/data/3306/data/ooooooooooooooooo/db.opt'
innobackupex: Creating directory '/data/3306/data/performance_schema'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/file_instances.frm' to '/data/3306/data/performance_schema/file_instances.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/setup_instruments.frm' to '/data/3306/data/performance_schema/setup_instruments.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/setup_consumers.frm' to '/data/3306/data/performance_schema/setup_consumers.frm'
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'
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'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/mutex_instances.frm' to '/data/3306/data/performance_schema/mutex_instances.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/db.opt' to '/data/3306/data/performance_schema/db.opt'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/performance_timers.frm' to '/data/3306/data/performance_schema/performance_timers.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/cond_instances.frm' to '/data/3306/data/performance_schema/cond_instances.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/setup_timers.frm' to '/data/3306/data/performance_schema/setup_timers.frm'
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'
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'
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'
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'
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'
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'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/rwlock_instances.frm' to '/data/3306/data/performance_schema/rwlock_instances.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/performance_schema/threads.frm' to '/data/3306/data/performance_schema/threads.frm'
innobackupex: Creating directory '/data/3306/data/qqqqqqqq1'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/qqqqqqqq1/db.opt' to '/data/3306/data/qqqqqqqq1/db.opt'
innobackupex: Creating directory '/data/3306/data/wordpress'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/wordpress/db.opt' to '/data/3306/data/wordpress/db.opt'
innobackupex: Creating directory '/data/3306/data/aaa'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/aaa/db.opt' to '/data/3306/data/aaa/db.opt'
innobackupex: Creating directory '/data/3306/data/mysql'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_keyword.MYD' to '/data/3306/data/mysql/help_keyword.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/general_log.CSV' to '/data/3306/data/mysql/general_log.CSV'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_keyword.MYI' to '/data/3306/data/mysql/help_keyword.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_topic.frm' to '/data/3306/data/mysql/help_topic.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/procs_priv.MYD' to '/data/3306/data/mysql/procs_priv.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/servers.frm' to '/data/3306/data/mysql/servers.frm'
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'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone.frm' to '/data/3306/data/mysql/time_zone.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/event.MYI' to '/data/3306/data/mysql/event.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/db.frm' to '/data/3306/data/mysql/db.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/ndb_binlog_index.MYD' to '/data/3306/data/mysql/ndb_binlog_index.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/proc.MYD' to '/data/3306/data/mysql/proc.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/tables_priv.MYD' to '/data/3306/data/mysql/tables_priv.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/user.MYD' to '/data/3306/data/mysql/user.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_name.MYI' to '/data/3306/data/mysql/time_zone_name.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/general_log.CSM' to '/data/3306/data/mysql/general_log.CSM'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/event.frm' to '/data/3306/data/mysql/event.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_topic.MYD' to '/data/3306/data/mysql/help_topic.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/procs_priv.frm' to '/data/3306/data/mysql/procs_priv.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_name.MYD' to '/data/3306/data/mysql/time_zone_name.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/slow_log.CSM' to '/data/3306/data/mysql/slow_log.CSM'
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'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_topic.MYI' to '/data/3306/data/mysql/help_topic.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/proc.MYI' to '/data/3306/data/mysql/proc.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/columns_priv.MYD' to '/data/3306/data/mysql/columns_priv.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/slow_log.CSV' to '/data/3306/data/mysql/slow_log.CSV'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/func.frm' to '/data/3306/data/mysql/func.frm'
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'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/ndb_binlog_index.frm' to '/data/3306/data/mysql/ndb_binlog_index.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_category.frm' to '/data/3306/data/mysql/help_category.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/db.MYI' to '/data/3306/data/mysql/db.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/func.MYI' to '/data/3306/data/mysql/func.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/columns_priv.frm' to '/data/3306/data/mysql/columns_priv.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/user.MYI' to '/data/3306/data/mysql/user.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/general_log.frm' to '/data/3306/data/mysql/general_log.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_keyword.frm' to '/data/3306/data/mysql/help_keyword.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/event.MYD' to '/data/3306/data/mysql/event.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_transition.frm' to '/data/3306/data/mysql/time_zone_transition.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_relation.frm' to '/data/3306/data/mysql/help_relation.frm'
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'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/host.MYD' to '/data/3306/data/mysql/host.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_relation.MYI' to '/data/3306/data/mysql/help_relation.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/servers.MYD' to '/data/3306/data/mysql/servers.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/host.frm' to '/data/3306/data/mysql/host.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_relation.MYD' to '/data/3306/data/mysql/help_relation.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone.MYI' to '/data/3306/data/mysql/time_zone.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/plugin.MYI' to '/data/3306/data/mysql/plugin.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/servers.MYI' to '/data/3306/data/mysql/servers.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/user.frm' to '/data/3306/data/mysql/user.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/ndb_binlog_index.MYI' to '/data/3306/data/mysql/ndb_binlog_index.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/tables_priv.MYI' to '/data/3306/data/mysql/tables_priv.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/plugin.MYD' to '/data/3306/data/mysql/plugin.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/db.MYD' to '/data/3306/data/mysql/db.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/proxies_priv.frm' to '/data/3306/data/mysql/proxies_priv.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_transition.MYI' to '/data/3306/data/mysql/time_zone_transition.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/plugin.frm' to '/data/3306/data/mysql/plugin.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/host.MYI' to '/data/3306/data/mysql/host.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/columns_priv.MYI' to '/data/3306/data/mysql/columns_priv.MYI'
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'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_category.MYD' to '/data/3306/data/mysql/help_category.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/procs_priv.MYI' to '/data/3306/data/mysql/procs_priv.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_name.frm' to '/data/3306/data/mysql/time_zone_name.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone.MYD' to '/data/3306/data/mysql/time_zone.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/proc.frm' to '/data/3306/data/mysql/proc.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/func.MYD' to '/data/3306/data/mysql/func.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/proxies_priv.MYD' to '/data/3306/data/mysql/proxies_priv.MYD'
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'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/help_category.MYI' to '/data/3306/data/mysql/help_category.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/proxies_priv.MYI' to '/data/3306/data/mysql/proxies_priv.MYI'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/time_zone_transition.MYD' to '/data/3306/data/mysql/time_zone_transition.MYD'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/tables_priv.frm' to '/data/3306/data/mysql/tables_priv.frm'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/mysql/slow_log.frm' to '/data/3306/data/mysql/slow_log.frm'
innobackupex: Creating directory '/data/3306/data/cyh'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/cyh/db.opt' to '/data/3306/data/cyh/db.opt'
innobackupex: Creating directory '/data/3306/data/wuyi'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/wuyi/db.opt' to '/data/3306/data/wuyi/db.opt'
innobackupex: Starting to copy InnoDB system tablespace
innobackupex: in '/tmp/2016-07-03_21-07-38'
innobackupex: back to original InnoDB data directory '/data/3306/data'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/ibdata1' to '/data/3306/data/ibdata1'
innobackupex: Starting to copy InnoDB undo tablespaces
innobackupex: in '/tmp/2016-07-03_21-07-38'
innobackupex: back to '/data/3306/data'
innobackupex: Starting to copy InnoDB log files
innobackupex: in '/tmp/2016-07-03_21-07-38'
innobackupex: back to original InnoDB log directory '/data/3306/data'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/ib_logfile1' to '/data/3306/data/ib_logfile1'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/ib_logfile0' to '/data/3306/data/ib_logfile0'
innobackupex: Copying '/tmp/2016-07-03_21-07-38/ib_logfile2' to '/data/3306/data/ib_logfile2'
innobackupex: Finished copying back files.
160704 00:03:38 innobackupex: completed OK!
增量备份二进制文件:
[root@db02 2016-07-03_21-07-38]# mysqlbinlog --start-position=107 /data/3306/mysql-bin.000029 >/tmp/$(date +%F).sql
注:--start-position=107可以不指定,因为107是一个日志的默认起始位置。
还原增量备份
mysql> set sql_log_bin=0;
Query OK, 0 rows affected (0.00 sec)
mysql> SOURCE /tmp/2016-07-03_21-07-38/2016-07-03.sql
使用innobackupex进行增量备份
增量备份基本语法:
mysql>create table test(
-> id int(4) not null,
-> name char(20) not null,
-> age tinyint(2) NOT NULL default '0',
-> dept varchar(16) default NULL
-> );
Query OK, 0 rows affected (0.03 sec)
mysql>insert into test(id,name,age) values(1,'oldboy',19);
mysql>insert into test(id,name,age) values(2,'oldgro;',20);
2.进行增量备份
[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/
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona LLC and/or its affiliates 2009-2013. All Rights Reserved.
This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
Get the latest version of Percona XtraBackup, documentation, and help resources:
http://www.percona.com/xb/p
160704 00:22:03 innobackupex: Executing a version check against the server...
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).
160704 00:22:03 innobackupex: Connected to MySQL server
160704 00:22:03 innobackupex: Done.
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).
160704 00:22:03 innobackupex: Connected to MySQL server
160704 00:22:03 innobackupex: Starting the backup operation
IMPORTANT: Please check that the backup run completes successfully.
At the end of a successful backup run innobackupex
prints "completed OK!".
innobackupex: Using server version 5.5.49-log
innobackupex: Created backup directory /tmp/2016-07-04_00-22-03
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/'
innobackupex: Waiting for ibbackup (pid=3312) to suspend
innobackupex: Suspend file '/tmp/2016-07-04_00-22-03/xtrabackup_suspended_2'
xtrabackup version 2.2.13 based on MySQL server 5.6.24 Linux (x86_64) (revision id: 70f4be3)
incremental backup from 2099425 is enabled.
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /data/3306/data
xtrabackup: open files limit requested 1024, set to 65535
xtrabackup: using the following InnoDB configuration:
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:128M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 3
xtrabackup: innodb_log_file_size = 4194304
>> log scanned up to (2099425)
xtrabackup: Generating a list of tablespaces
[01] Copying ./ibdata1 to /tmp/2016-07-04_00-22-03/ibdata1.delta
[01] ...done
>> log scanned up to (2099425)
xtrabackup: Creating suspend file '/tmp/2016-07-04_00-22-03/xtrabackup_suspended_2' with pid '3312'
160704 00:22:05 innobackupex: Continuing after ibbackup has suspended
160704 00:22:05 innobackupex: Executing FLUSH NO_WRITE_TO_BINLOG TABLES...
160704 00:22:05 innobackupex: Executing FLUSH TABLES WITH READ LOCK...
160704 00:22:05 innobackupex: All tables locked and flushed to disk
160704 00:22:05 innobackupex: Starting to backup non-InnoDB tables and files
innobackupex: in subdirectories of '/data/3306/data/'
innobackupex: Backing up file '/data/3306/data//qqqqqqq41233/db.opt'
innobackupex: Backing up file '/data/3306/data//dadadadadadad/db.opt'
innobackupex: Backing up file '/data/3306/data//qqqqqqqq3/db.opt'
>> log scanned up to (2099425)
innobackupex: Backing up file '/data/3306/data//qqqqqqqq/db.opt'
innobackupex: Backing up file '/data/3306/data//qqqqqqq43/db.opt'
innobackupex: Backing up file '/data/3306/data//oldboy_gbk/db.opt'
innobackupex: Backing up file '/data/3306/data//oldboy/student.frm'
innobackupex: Backing up file '/data/3306/data//oldboy/db.opt'
innobackupex: Backing up file '/data/3306/data//ooooooooooooooooo/db.opt'
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)
innobackupex: Backing up file '/data/3306/data//qqqqqqqq1/db.opt'
innobackupex: Backing up file '/data/3306/data//wordpress/db.opt'
innobackupex: Backing up file '/data/3306/data//aaa/db.opt'
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)
innobackupex: Backing up file '/data/3306/data//cyh/db.opt'
innobackupex: Backing up file '/data/3306/data//wuyi/db.opt'
160704 00:22:06 innobackupex: Finished backing up non-InnoDB tables and files
160704 00:22:06 innobackupex: Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
160704 00:22:06 innobackupex: Waiting for log copying to finish
xtrabackup: The latest check point (for incremental): '2099425'
xtrabackup: Stopping log copying thread.
.>> log scanned up to (2099425)
xtrabackup: Creating suspend file '/tmp/2016-07-04_00-22-03/xtrabackup_log_copied' with pid '3312'
xtrabackup: Transaction log of lsn (2099425) to (2099425) was copied.
160704 00:22:07 innobackupex: All tables unlocked
innobackupex: Backup created in directory '/tmp/2016-07-04_00-22-03'
innobackupex: MySQL binlog position: filename 'mysql-bin.000029', position 1258
160704 00:22:07 innobackupex: Connection to database server closed
160704 00:22:07 innobackupex: completed OK!
backup_type = incremental
from_lsn = 1768597
to_lsn = 1769413
last_lsn = 1769413
compact = 0
recover_binlog_info = 0
准备
[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/
例子# innobackupex --apply-log --redo-only BASE-DIR --incremental-dir=INCREMENTAL-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/ --incremental-dir=/tmp/2016-07-04_00-34-48/
例子# innobackupex --apply-log --redo-only BASE-DIR --incremental-dir=INCREMENTAL-DIR-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/
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_table和innodb_expand_import选项。
“导出”表
导出表是在备份的prepare阶段进行的,因此,一旦完全备份完成,就可以在prepare过程中通过–export选项将某表导出了:
# innobackupex –apply-log –export /path/to/backup
此命令会为每个innodb表的表空间创建一个以.exp结尾的文件,这些以.exp结尾的文件则可以用于导入至其它服务器。
“导入”表
要在mysql服务器上导入来自于其它服务器的某innodb表,需要先在当前服务器上创建一个跟原表表结构一致的表,而后才能实现将表导入:
mysql> CREATE TABLE mytable (...) ENGINE=InnoDB;
然后将此表的表空间删除:
mysql> ALTER TABLE mydatabase.mytable DISCARD TABLESPACE;
接下来,将来自于“导出”表的服务器的mytable表的mytable.ibd和mytable.exp文件复制到当前服务器的数据目录,然后使用如下命令将其“导入”:
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
此选项的参数需要是一个文件名,此文件中每行包含一个要备份的表的完整名称;如:
# echo -e 'mageedu.tb1\nmageedu.tb2' > /tmp/tables.txt
# 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状态的备份直接至数据目录中实现还原,不要此时要求数据目录处于一致状态。