Mysqlbackup uses TTS to recover the specified table. 4. Restore a specific table ****************************************** --4.1 New test environment Create DATABASE ' Wind ' DEFAULT CHARACTER SET GBK, use wind;create table t1 (SID int NOT NULL , sname varchar (+) NOT null) Engine=innodb CHARSET=GBK; DELIMITER//create PROCEDURE proc1 () BEGIN DECLARE i int DEFAULT 0; Set i=1; set autocommit=0; While i<=1000000 Doinsert to T1 values (i, ' MySQL test '); set i=i+1; END while; Commit;set autocommit=1; END//delimiter; Call proc1;create table T2asselect * from t1;--4.2. Fully prepared # Rm-rf/backup && mkdir/backup#mysqlback Up--defaults-file=/usr/local/mysql/my.cnf--host=127.0.0.1--port=3306--protocol=tcp--user=root--password=123- -use-tts--include-tables= ' wind.t2 '--with-timestamp--backup-dir=/backup--log-bin-index=/usr/local/mysql/mysql_ Logs/binary_log/mysql-bin.index Backup-and-apply-log # CAT/BACKUP/2015-04-02_12-41-45/META/BACKUP_VARIABLES.TXT | grep ' End ' end_lsn=138866623--4.3 incremental backup mysql> Select COUNT (*) from t1;+----------+| COUNT (*) |+----------+| 1000000 |+----------+1 row in Set (0.75 sec) mysql> Select COUNT (*) from t2;+----------+| COUNT (*) |+----------+| 1000000 |+----------+1 row in Set (0.68 sec) mysql> Delete from T2 limit 10; Query OK, Rows Affected (0.00 sec) Mysql> commit; Query OK, 0 rows Affected (0.00 sec) mysql> Select COUNT (*) from t2;+----------+| COUNT (*) |+----------+| 999990 |+----------+1 row in Set (0.80 sec) # Rm-rf/backupinc && mkdir/backupinc--First incremental backup #mysqlbackup--defaults -FILE=/USR/LOCAL/MYSQL/MY.CNF--host=127.0.0.1--port=3306--protocol=tcp--user=root--password=123--use-tts--in clude-tables= ' wind.t2 '--with-timestamp--log-bin-index=/usr/local/mysql/mysql_logs/binary_log/mysql-bin.index-- Incremental--start-lsn=138866623--incremental-backup-dir=/backupinc Backup # cat/backupinc/2015-04-02_12-44-02/ Meta/backup_variables.txt | grep ' End ' end_lsn=138868639--Second Incremental backup mysql> select COUNT (*) from wind.t2;+----------+| COUNT (*) |+----------+| 999990 |+----------+1 row in Set (0.83 sec) mysql> desc T2, +-------+--------------+------+-----+---------+---- ---+| Field | Type | Null | Key | Default | Extra |+-------+--------------+------+-----+---------+-------+| Sid | Int (11) | NO | | NULL | || sname | varchar (100) | NO | | NULL | |+-------+--------------+------+-----+---------+-------+2 rows in Set (0.00 sec) mysql> Update t2 set sname= ' Ocpyang MySQL test! ' limit 5000; Query OK, affected (0.24 sec) rows matched:5000 changed:5000 warnings:0mysql> commit; Query OK, 0 rows Affected (0.00 sec) mysql> Select COUNT (*) from wind.t2 where sname= ' Ocpyang MySQL test! '; +----------+| COUNT (*) |+----------+| |+----------+1 Row in Set (0.86 sec) #mysqlbackup--defaults-file=/usr/local/mysql/my.cnf--host=127.0.0.1--port=3 306--protocol=tcp--user=root--password=123--use-tts--include-tables= "Wind.t2"--with-timestamp--log-bin-index=/usr/local/mysql/mysql_logs/binary_ Log/mysql-bin.index--incremental--start-lsn=138868639--incremental-backup-dir=/backupinc Backup # cat/backupinc/ 2015-04-02_12-46-48/meta/backup_variables.txt | grep endend_lsn=139571560--4.4 Merge Incremental backup to fully prepared ls/backupinc/2015-04-02_12-44-02 2015-04-02_12-46-48ls/backup2015-04-02_ 12-41-45mysqlbackup--backup-dir=/backup/2015-04-02_12-41-45/--incremental-backup-dir=/backupinc/2015-04-02_ 12-44-02--log-bin-index=/usr/local/mysql/mysql_logs/binary_log/mysql-bin.index Apply-incremental-backup Mysqlbackup--backup-dir=/backup/2015-04-02_12-41-45--incremental-backup-dir=/backupinc/2015-04-02_12-46-48-- Log-bin-index=/usr/local/mysql/mysql_logs/binary_log/mysql-bin.index apply-incremental-backup--4.5 Simulation deletes the specified table #cat/ USR/LOCAL/MYSQL/MY.CNF |grep datadirdatadir=/usr/local/mysql/datamysql> Select COUNT (*) from t2;+----------+| COUNT (*) |+----------+| 999990 |+----------+1 rowIn Set (0.80 sec) mysql> Select COUNT (*) from wind.t2 where sname= ' Ocpyang MySQL test! '; +----------+| COUNT (*) |+----------+| |+----------+1 Row in Set (0.86 sec) mysql> drop table t2;--4.6 Restore specified table (using MySQL user) Chown-r mysql/backupchgrp-r mysq L/backupchown-r mysql/usr/local/mysqlchgrp-r mysql/usr/local/mysql[[email protected] ~]$ whoami #避免权限问题mysql/* Note: Error 150402 13:29:26 mysqlbackup:INFO:Importing table:wind.t2 for permissions issues. Mysqlbackup:ERROR:mysql query: ' ALTER TABLE wind.t2 IMPORT tablespace ': Internal error:cannot reset LSNs in TABLE ' "Win D "." T2 "': tablespace not found mysqlbackup:ERROR:Failed to import tablespace wind.t2.mysqlbackup Failed with errors!******* /mysqlbackup--host=127.0.0.1--port=3306--protocol=tcp--user=root-- password=123--datadir=/usr/local/mysql/data/--log-bin-index=/usr/local/mysql/mysql_logs/binary_log/ Mysql-bin.index--backup-dir=/backup/2015-04-02_12-41-45/--include-tables= ' wind\.t2$ ' copy-back[[email protected] ~]$ mysqlbackup--host=127.0.0.1--port=3306-- Protocol=tcp >--user=root--password=123 >--datadir=/usr/local/mysql/data/>--log-bin-index=/usr/local/my Sql/mysql_logs/binary_log/mysql-bin.index >--backup-dir=/backup/2015-04-02_12-41-45/>--include-tables= ' wind\.t2$ ' > Copy-backmysql Enterprise Backup version 3.12.0 linux-2.6.18-194.el5-x86_64 [2015/03/10] Copyright (c) 20 and/or, Oracle, its affiliates. All rights Reserved. mysqlbackup:INFO:Starting with following command line ... mysqlbackup--host=127.0.0.1--port=3306--protocol=tcp--user =root--password=xxx--datadir=/usr/local/mysql/data/--log-bin-index=/usr/local/mysql/mysql_logs/binary_l Og/mysql-bin.index--backup-dir=/backup/2015-04-02_12-41-45/--include-tables=wind\.t2$ Copy-back Mysqlba Ckup:INFO:IMPORTANT:Please Check that Mysqlbackup run completes successfully. At the end of A successful ' copy-back ' run mysqlbackup prints "Mysqlbackup completed ok!". 150402 13:38:25 Mysqlbackup:INFO:MEB logfile created at/backup/2015-04-02_12-41-45/meta/meb_2015-04-02.13-38-25_ Copy_back.log Mysqlbackup:INFO:MySQL Server version is ' 5.6.23-enterprise-commercial-advanced-log '. Mysqlbackup:INFO:Got Some server configuration information from running Server.--------------------------------------------------------------------Server Repository Option S:--------------------------------------------------------------------datadir =/usr/local/mysql/data/innodb_ Data_home_dir =/usr/local/mysql/innodb_data Innodb_data_file_path = ibdata1:800m;ibdata2:800m:autoextend Innodb_log _group_home_dir =/usr/local/mysql/mysql_logs/innodb_log/innodb_log_files_in_group = 3 Innodb_log_file_size = 2147483648 innodb_page_size = 16384 Innodb_checksum_algorithm = InnoDB innodb_undo_directory =. innodb_undo_tablespaces = 0 Innodb_undo_logs =--------------------------------------------------------------------Backup Config Options:------------- -------------------------------------------------------DataDir =/backup/2015-04-02_12-41-45/datadir Innodb_data_ Home_dir =/backup/2015-04-02_12-41-45/datadir Innodb_data_file_path = ibdata1:800m;ibdata2:800m:autoextend innodb_ Log_group_home_dir =/backup/2015-04-02_12-41-45/datadir Innodb_log_files_in_group = 3 Innodb_log_file_size = 2147483648 innodb_page_size = 16384 Innodb_checksum_algorithm = InnoDB mysqlbackup:INFO:Creating + buffers each of SI Ze 16777216.150402 13:38:25 mysqlbackup:info:copy-back operation starts with following THREADS1 Read-threads 1 write- Threads mysqlbackup:INFO:Could not find Binlog index file. Binlogs is not being copied for this backup. Point-in-time-recovery is not being possible. If This was online backup then server may not be started with--log-bin. Specify it location with--log-bin-index option.150402 13:38:25 mysqlbackup:INFO:Creating table:wind.t2.150402 13:38:25 mysqlbackup:info:copying/backup/2015-04-02_ 12-41-45/datadir/wind/t2.ibd.150402 13:38:26 mysqlbackup:INFO:Completing The copy of all Non-innodb files.150402 13:38: Mysqlbackup:INFO:Importing table:wind.t2.150402 13:38:28 mysqlbackup:INFO:Analyzing table:wind.t2.150402 13:38:29 Mysqlbackup:info:copy-back operation completed successfully.150402 13:38:29 mysqlbackup:INFO:Finished copying backup Files to '/usr/local/mysql/data ' Mysqlbackup completed ok!# ls-ll/usr/local/mysql/data/wind/total 57360-rw-rw----. 1 MySQL MySQL Apr 2 13:26 db.opt-rw-rw----. 1 mysql mysql 8590 Apr 2 13:38 t2.frm-rw-rw-r--. 1 mysql mysql 58720256 Apr 2 13:38 t2.ibd/*******alter TABLE T2 discard tablespace; ALTER table T2 IMPORT tablespace;*********/--4.7 Verify table recovery mysql> use wind;database changedmysql> show tables;+------ ----------+| Tables_in_wind |+----------------+| T2 |+----------------+1 row in SET (0.00 sec) mysql> Select COUNT (*) from t2;+----------+| COUNT (*) |+----------+| 999990 |+----------+1 row in Set (1.34 sec) mysql> Select COUNT (*) from wind.t2 where sname= ' Ocpyang MySQL test! '; +----------+| COUNT (*) |+----------+| |+----------+1 Row in Set (0.78 sec)
Mysqlbackup Recovering a specific table