xtrabackup原理,整库,单表,部分备份恢复

增加原理部分
 
创建部分备份(Creating Partial Backups)
部分备份共有三种方式,分别是:
1. 用正则表达式表示要备份的库名及表名(参数为--include)
2. 将要备份的表名或库名都写在一个文本文件中(参数为--tables-file)
3. 将要备份表名或库名完整的写在命令行中(参数为:--databases)。
(译者注:不管你备份哪个库或是哪张表,强烈推荐把mysql库也一起备份,恢复的时候要用。)

方式一:使用--include参数
使用正则模式匹配备份部分库表,需要使用参数--include
innobackupex --include='test.test*' /backup --user=root --password=msds007
 
方式二:使用表列表备份部分表,需要使用参数--tables-file,语句类似如下:
cat /tmp/tables.txt
test.t
test.testflashback2
innobackupex --tables-file=/tmp/tables.txt /backup --user=root --password=msds007
 
方式三:使用--databases参数
innobackupex --databases=test,mysql /backup --user=root --password=msds007
 
准备部分备份(Preparing Partial Backups)
执行preparing partial backups,与恢复独立的表(Restoring Individual Tables)很类似:使用--apply-log和--export参数,并包含上一步生成的时间戳文件夹
innobackupex --apply-log --export /backup/2018-05-10_19-38-44
 
恢复部分备份(Restoring Partial Backups)
1)查看备份集中的文件
[root@mydb1 test]# pwd
/backup/2018-05-10_19-38-44/test
[root@mydb1 test]# ll
total 256
-rw-r--r--. 1 root root   390 May 10 19:58 t.cfg
-rw-r--r--. 1 root root  1087 May 10 19:58 testflashback2.cfg
-rw-r--r--. 1 root root 16384 May 10 19:58 testflashback2.exp
-rw-r-----. 1 root root  9030 May 10 19:38 testflashback2.frm
-rw-r-----. 1 root root 98304 May 10 19:38 testflashback2.ibd
-rw-r--r--. 1 root root 16384 May 10 19:58 t.exp
-rw-r-----. 1 root root  8586 May 10 19:38 t.frm
-rw-r-----. 1 root root 98304 May 10 19:38 t.ibd
 
2)建表,可以从frm文件中解析出建表语句
# mysqlfrm --diagnostic t.frm
# WARNING: Cannot generate character set or collation names without the --server option.
# CAUTION: The diagnostic mode is a best-effort parse of the .frm file. As such, it may not identify all of the components of the table correctly. This is especially true for damaged files. It will also not read the default values for the columns and the resulting statement may not be syntactically correct.
# Reading .frm file for t.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement:
[root@mydb1 ~]# mysqlfrm --server=dba_user:msds007@192.168.1.101 /app/mysqldata/3306/data/test/tt.frm --user=root --port=2323
--server=dba_user:msds007@192.168.1.101     远端服务器,要读取的数据字典
/app/mysqldata/3306/data/test/tt.frm                  frm源文件放置的本地位置
--user=root --port=2323                                     Starting the spawned server on port 2323
CREATE TABLE `t` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) DEFAULT NULL,
PRIMARY KEY `PRIMARY` (`id`)
) ENGINE=InnoDB;
#...done.
 
3)导入数据
ALTER TABLE test.t DISCARD TABLESPACE;
After this, copy t.ibd and t.exp ( or t.cfg if importing to MySQL 5.6) files to database’s home, and import its tablespace:
chown mysql:mysql t.ibd t.exp t.cfg
ALTER TABLE test.t IMPORT TABLESPACE;

转载于:https://www.cnblogs.com/allenhu320/p/11311056.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值