日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

如何从一个XtraBackup完整备份中恢复一个InnoDB表

發布時間:2024/3/13 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何从一个XtraBackup完整备份中恢复一个InnoDB表 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

有時候我們從一個完整的數據庫備份中不需要整庫恢復,只需要恢復其中的一個或者幾個表,如果使用Percona的XtraBackup備份在恢復的時候如何只恢復部分數據呢?

轉載請尊重原創、保留相關鏈接本文來自多寶平臺http://www.mbodb.com


下面用例子來演示

首先為了能恢復表需要做以下操作:
1、InnoDB_FAST_SHUTDOWN = 0 ? ? --此參數MySQL在關閉的時候,需要完成所有的full purge和merge insert buffer操作.
2、InnoDB_File_Per_Table = ON ? --此參數修改InnoDB為獨立表空間模式,每個數據庫的每個表都會生成一個數據空間.

開始使用XtraBackup備份,這里用到--export參數.
[mysql@localhost mysql]$ innobackupex-1.5.1 --defaults-file=/etc/my.cnf --export /mysql/backup/

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

140312 16:06:45 ?innobackupex-1.5.1: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_file=/etc/my.cnf;mysql_read_default_group=xtrabackup' (using password: NO).
140312 16:06:45 ?innobackupex-1.5.1: Connected to MySQL server
140312 16:06:45 ?innobackupex-1.5.1: Executing a version check against the server...
140312 16:06:51 ?innobackupex-1.5.1: Done.
IMPORTANT: Please check that the backup run completes successfully.
......
......
......

備份完成之后應用日志使備份多寶保持一致性
[mysql@localhost backup]$ innobackupex-1.5.1 --defaults-file=/etc/my.cnf --apply-log --export /mysql/backup/2014-03-12_16-06-52/

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

140312 16:11:47 ?innobackupex-1.5.1: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_file=/etc/my.cnf;mysql_read_default_group=xtrabackup' (using password: NO).
140312 16:11:47 ?innobackupex-1.5.1: Connected to MySQL server
Connected successfully
140312 16:11:47 ?innobackupex-1.5.1: Connection to database server closed
IMPORTANT: Please check that the apply-log run completes successfully.
? ? ? ? ? ?At the end of a successful apply-log run innobackupex-1.5.1
? ? ? ? ? ?prints "completed OK!".
......
......
......

現在我們登錄MySQL刪除一些t表的數據
mysql> select * from t;
+----+
| id |
+----+
| ?1 |
| ?2 |
| ?3 |
| ?4 |
| ?5 |
| ?6 |
| ?7 |
| ?8 |
| ?9 |
| 10 |
| 11 |
+----+
11 rows in set (0.06 sec)

mysql> delete from t where id between 7 and 10;
Query OK, 4 rows affected (0.18 sec)

mysql> select * from t;
+----+
| id |
+----+
| ?1 |
| ?2 |
| ?3 |
| ?4 |
| ?5 |
| ?6 |
| 11 |
+----+
7 rows in set (0.00 sec)

這時我們Discard表
mysql> ALTER TABLE t DISCARD TABLESPACE;
Query OK, 0 rows affected (0.12 sec)

從備份目錄復制文件到數據庫目錄
[mysql@localhost test]$ cp -p -r t.cfg t.ibd ../../../data/test/

我們進入到MySQL之后Import表
mysql> ALTER TABLE t import TABLESPACE;
Query OK, 0 rows affected (0.07 sec)

查看表t
mysql> select * from t;
+----+
| id |
+----+
| ?1 |
| ?2 |
| ?3 |
| ?4 |
| ?5 |
| ?6 |
| ?7 |
| ?8 |
| ?9 |
| 10 |
| 11 |
+----+
11 rows in set (0.00 sec)

注意:
在復制備份文件的時候一定要復制后綴cfg文件,否則在Import的時候就會報Warning.例如如下的信息:
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1810 | InnoDB: IO Read error: (2, No such file or directory) Error opening './test/t.cfg', will attempt to import without schema verification ? ?|
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------+
cfg文件的用處主要是在MySQL5.6執行"Flush Table xxx Export;"之后使.ibd文件保持一致性,同時這個文件會生成一個.cfg文件,在做Import的時候會對導入過程進行校驗,但是在MySQL5.6.8版本之后也不是必須要有.cfg文件.如果真沒有,在導入的時候有可能就會報出上面的錯誤,所以為了安全還是復制它.

如果表有外鍵在Discard的時候執行如下命令:
set FOREIGN_KEY_CHECKS=0;

在Import表之后執行以下命令恢復外鍵檢查
set FOREIGN_KEY_CHECKS=1;

參數--export的英文解釋如下:

? ? ? ? This option is passed directly to xtrabackup's --export option. It
? ? ? ? enables exporting individual tables for import into another server.

總結

以上是生活随笔為你收集整理的如何从一个XtraBackup完整备份中恢复一个InnoDB表的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。