Xtrabackup是一個對InnoDB做數據備份的工具,支持在線熱備份(備份時不影響數據讀寫),是商業(yè)備份工具InnoDB Hotbackup的一個很好的替代品。
xtrabackup官方網址:https://www.percona.com/downloads/XtraBackup/
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
來源:?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.完全備份
基本語法:
多實例備份:
[ 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=指定配置文件 ?? ?? ? 最后面是存放位置 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 ! 錯誤提示:如果執(zhí)行該命令出現如下錯誤:
? ? 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: [ root@localhost ~]# cp / usr / local / mysql / lib / libmysqlclient . so . 18 / usr / lib64 / 備份后的文件: 在備份的同時,備份數據會在備份目錄下創(chuàng)建一個以當前時間為名字的目錄存放備份文件: 各文件說明: (1)xtrabackup_checkpoints —-備份類型(如完全或增量)、備份狀態(tài)(如是否已經沒prepare狀態(tài))和LSN(日志序列號)范圍信息 每個InnoDB頁(通常大小為16K)都會包含一個日志序列號,即LSN,LSN是整個數據庫系統(tǒng)的系統(tǒng)版本號,每個頁面相關的LSN能夠表名此頁面最近是如何發(fā)生改變的。 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的可執(zhí)行文件 (5)backup-my.cnf —- 備份命令用到的配置選項信息; 在使用innobackupex命令備份時嗎還可以使用–no-timestamp選項來阻止命令自動創(chuàng)建一個以時間命名的目錄 innobackupex命令將會創(chuàng)建一個BACKUP-DIR目錄來存儲備份數據
還需要注意,備份數據庫的用戶需要具有相對應的權限,如果要使用一個最小權限的用戶進行備份可以使用以下參數: mysql > GRANT RELOAD , LOCK TABLES , REPLICATION CLIENT ON *.* TO ‘ bkpuser ’@’ localhost ’; ? ? ?? mysql > FLUSH PRIVILEGES ; 2. 準備(prepare)一個完整備份 一般情況下,在備份完成后,數據尚且不能用于恢復操作,因為備份的數據中可能會包含尚未提交的事務或已經提交但尚未同步至數據文件中的事務,因此,此時數據文件仍處理不一致狀態(tài)?!皽蕚洹钡闹饕饔檬峭ㄟ^回滾未提交的事務及同步已經提交的事務至數據文件也使得數據文件處于一致性狀態(tài)。 innobackupex命令的–apply-log選項可用于實現上述功能。 [root@db02 /]# innobackupex –apply-log /tmp/2016-07-03_21-07-38/ 如果執(zhí)行正確,會輸出以下內容:不提示錯誤即可
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 ); 模擬數據庫損壞 進入數據庫的data目錄刪除所有
[ root@db02 data ]# rm - rf * mysql > show databases ; ? 現在已經造成了數據庫文件被刪除,里面的數據消失 +--------------------+ | Database ? ? ? ? ? | +--------------------+ | information_schema | +--------------------+ 1 row in set ( 0.00 sec ) 還原完全備份 innobackupex命令的–copy-back選項用于執(zhí)行恢復操作,其通過復制所有數據相關的文件至mysql服務器DATADIR目錄中來執(zhí)行恢復過程。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 如果執(zhí)行正確,會輸出以下內容
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 ! 我們可以在查看結果: 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)
增量備份二進制文件: [ 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進行增量備份 前面我們進行增量備份時,使用的還是老方法:備份二進制日志。其實xtrabackup還支持進行增量備份。 每個InnoDB的頁面都會包含一個LSN信息,每當相關的數據發(fā)生改變,相關的頁面的LSN就會自動增長。這正是InnoDB表可以進行增量備份的基礎,即innobackupex通過備份上次完整備份之后發(fā)生改變的頁面來實現。 增量備份基本語法: 1.模擬插入數據
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 ! 查看xtrabackup_checkpoints
backup_type = incremental from_lsn = 1768597 to_lsn = 1769413 last_lsn = 1769413 compact = 0 recover_binlog_info = 0
準備 準備(prepare)增量備份與整理完全備份有著一些不同,尤其是要注意的是: (1)需要在每個備份(包括完全和增量備份)上,將已經提交的事務進行“重放”。 “重放”之后,所有的備份數據將合并到完全備份上 (2)基于所有的備份將末提交的事務進行“回滾”。 執(zhí)行完全備份的redo; # innobackupex –apply-log –redo-only BASE-DIR
[ 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 / 接著執(zhí)行第一個增量:
例子# 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 / 而后是第二個增量:因為我們只執(zhí)行了一次增量,所以只有一個文件夾
例子# 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 / 提示: 其中BASE-DIR指的是完全備份所在的目錄,而INCREMENTAL-DIR-1指定的是第一次增量備份的目錄,INCREMENTAL-DIR=2指的是第二次增量備份的目錄,其他依次類推,即如果有多次增量備份,每一次都要執(zhí)行如上操作。
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”?
此外,在執(zhí)行本地備份時,還可以使用–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? 選項(嚴格來說,是要“ 導出” 的表在其創(chuàng)建之前,mysql 服務器就啟用了innodb_file_per_table 選項),并且“ 導入” 表的服務器同 時啟用了innodb_file_per_table 和innodb_expand_import 選項。
?“ 導出 ” 表 導出表是在備份的prepare 階段進行的,因此,一旦完全備份完成,就可以在prepare 過程中通過–export 選項將某表導出了:
# innobackupex –apply-log –export /path/to/backup
此命令會為每個innodb 表的表空間創(chuàng)建一個以.exp 結尾的文件,這些以.exp 結尾的文件則可以用于導入至其它服務器。
“ 導入 ” 表
要在 mysql 服務器上導入來自于其它服務器的某 innodb 表,需要先在當前服務器上創(chuàng)建一個跟原表表結構一致的表,而后才能實現將表導入: 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 進行還原,但這種方式還原而來的數據多數會 產生數據不一致的問題,因此,無論如何不推薦使用這種方式。
創(chuàng)建部分備份 創(chuàng)建部分備份的方式有三種:正則表達式(–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
此命令執(zhí)行過程中,innobackupex 會調用xtrabackup 命令從數據字典中移除缺失的表,因此,會顯示出許多關于“ 表不存在” 類的警告信息。同時,也會顯示出為備份文件中存在的表創(chuàng)建.exp 文件的相關信息。
還原部分備份 還原部分備份的過程跟導入表的過程相同。當然,也可以通過直接復制prepared 狀態(tài)的備份直接至數據目錄中實現還原,不要此時要求數據目錄處于一致狀態(tài)。
本文轉載:http://www.toxingwang.com/database/mysql/1539.html
總結
以上是生活随笔 為你收集整理的Xtrabackup安装以及应用 的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。