mysqlbackup 还原特定的表
mysqlbackup使用TTS恢复指定表. *************************************************************
4.恢复特定表
************************************************************* --4.1新建測试环境 CREATE DATABASE `wind` DEFAULT CHARACTER SET gbk ; use wind; create table t1
(
sid int not null ,
sname varchar(100) 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 DO
INSERT INTO t1 values(i,'mysql測试');
set i=i+1;
END WHILE;
commit;
set autocommit=1;
END
//
DELIMITER ; call proc1; create table t2
as
select * from t1; --4.2.全备 # rm -rf /backup && mkdir /backup #mysqlbackup --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 增量备份 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, 10 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 --第一次增量备份 #mysqlbackup --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 --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 --第二次增量备份 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, 5000 rows affected (0.24 sec)
Rows matched: 5000 Changed: 5000 Warnings: 0 mysql> commit;
Query OK, 0 rows affected (0.00 sec) mysql> select count(*) from wind.t2 where sname='ocpyang mysql test!';
+----------+
| count(*) |
+----------+
| 5000 |
+----------+
1 row in set (0.86 sec) #mysqlbackup --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 --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 end
end_lsn=139571560 --4.4 合并增量备份到全备 ls /backupinc/
2015-04-02_12-44-02 2015-04-02_12-46-48 ls /backup 2015-04-02_12-41-45 mysqlbackup --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 模拟删除指定表 #cat /usr/local/mysql/my.cnf |grep datadir
datadir=/usr/local/mysql/data mysql> select count(*) from t2;
+----------+
| count(*) |
+----------+
| 999990 |
+----------+
1 row in set (0.80 sec) mysql> select count(*) from wind.t2 where sname='ocpyang mysql test!';
+----------+
| count(*) |
+----------+
| 5000 |
+----------+
1 row in set (0.86 sec) mysql> drop table t2; --4.6 还原指定表(使用mysql用户) chown -R mysql /backup
chgrp -R mysql /backup chown -R mysql /usr/local/mysql
chgrp -R mysql /usr/local/mysql [mysql@mysql ~]$ whoami #避免权限问题
mysql /***********************NOTE:权限问题出现的错误 150402 13:29:26 mysqlbackup: INFO: Importing table: wind.t2.
mysqlbackup: ERROR: mysql query: 'ALTER TABLE wind.t2 IMPORT TABLESPACE':
Internal error: Cannot reset LSNs in table '"wind"."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 [mysql@mysql ~]$ 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
MySQL Enterprise Backup version 3.12.0 Linux-2.6.18-194.el5-x86_64 [2015/03/10]
Copyright (c) 2003, 2015, Oracle and/or 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_log/mysql-bin.index
--backup-dir=/backup/2015-04-02_12-41-45/ --include-tables=wind\.t2$
copy-back mysqlbackup: 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 Options:
--------------------------------------------------------------------
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 = 128 --------------------------------------------------------------------
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 14 buffers each of size 16777216.
150402 13:38:25 mysqlbackup: INFO: Copy-back operation starts with following threads
1 read-threads 1 write-threads
mysqlbackup: INFO: Could not find binlog index file. binlogs will not be copied for this backup.
Point-In-Time-Recovery will not be possible.
If this is online backup then server may not have started with --log-bin.
You may specify its 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:27 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 61 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验证表恢复情况 mysql> use wind;
Database changed
mysql> 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(*) |
+----------+
| 5000 |
+----------+
1 row in set (0.78 sec)
版权声明:本文博主原创文章,博客,未经同意不得转载。
mysqlbackup 还原特定的表的更多相关文章
- 捕获mssqlservice 修改表后的数据,统一存储到特定的表中,之后通过代码同步两个库的数据
根据之前的一些想法,如果有A,B 两个数据库, 如果把A 用户通过界面产生的更新或者插入修改,操作的数据同步更新到B 库中,如果允许延时2分钟以内 想法一: 通过创建触发器 把变更的数据和对应的表名称 ...
- PowerDesigner里怎样查找特定的表
转自:https://blog.csdn.net/u013178480/article/details/78261650 crtl+f查找,在code处输入你要查找的表名,然后点击“find now& ...
- postgreSQL 备份+还原多张表
-U表示用户 -h表示主机 -p表示端口号 -t表示表名 -f表示备份后的sql文件的名字 -d表示要恢复数据库名 一.打开cmd 进入postgresql安装路径下的bin文件夹,以我的为例: cd ...
- MongoDB数据库备份与还原、单表的导入导出
-------------------MongoDB备份与恢复------------------- 1.MongoDB数据库备份 1.语法: mongodump -h dbh ...
- RMAN笔记
Rman常用命令 Preview选项 1) 显示用于还原system表空间数据文件的备份文件 RMAN> restore datafile 2 preview; 2) 显示用于还原特 ...
- 9、mysql的备份与恢复
mysql中 /*! ....*/ 不是注释,mysql为了保持兼容,它把一些特有的仅在mysql上用的语句放在/*!....*/中, 这样这些语句如果在其他数据库中是不会被执行,但在mysql中它会 ...
- 数据库备份还原——mysqlbackup与mysqldump对比测试
1 环境描述 1.1 硬件环境 服务器类型:华为RH5885 IP: 10.148.128.100 内存: 64G 物理CPU个数:4 CPU核数:8 逻辑CPU个数:64 Int ...
- mysql 针对单张表的备份与还原
A.MySQL 备份工具xtrabackup 的安装 . percona 官方xtrabackup 的二进制版本:二进制版本解压就能用了. . 解压xtrabackup & 创建连接 -Lin ...
- Oracle表数据或结构误删还原
数据误删 表结构没有发生改变 --开启表字段转移,不开启无法还原 alter table 表名 enable row movement; --数据闪回 flashback table 表名 to ti ...
随机推荐
- redhat linux使用Centos yum源
redhat Linux如果是没有购买红帽许可的话是不能使用redhat的yum源的,但是可以通过修改使之能使用Centos的yum源. 步骤一:删除redhat的yum [root@localhos ...
- CF 518D(概率dp)
传送门:Ilya and Escalator 题意:有n个人排队进车厢,每秒只能进一个人,而且第1个人进了后面的人才能进,第一个人每秒进入车厢的概率为p,不进的概率为1-p,求t秒后进入车厢总人数的数 ...
- jQuery Mobile 是创建移动 web 应用程序的框架。
jQuery Mobile jQuery Mobile 是创建移动 web 应用程序的框架. jQuery Mobile 适用于所有流行的智能手机和平板电脑. jQuery Mobile 使用 HTM ...
- 【剑指offer】面试题24:二叉搜索树的兴许前序遍历序列
分析: 前序: 根 左 右 后序: 左 由 根 二叉搜索树: 左 < 根 < 右 那么这就非常明显了. def ifpost(postArray, start, end): #one or ...
- Android5.0L下因sensorservice crash导致systemserver重新启动的第二种场景分析
一.出问题的场景 1.Sensorservice线程正在处理compass sensor事件的过程中.检查了一次buffer的指针的有效性,并在稍后会传递到AKM获取数据的函数接口中使用 2.Sens ...
- URAL 1297 后缀数组:求最长回文子串
思路:这题下午搞了然后一直WA,后面就看了Discuss,里面有个数组:ABCDEFDCBA,这个我输出ABCD,所以错了. 然后才知道自己写的后缀数组对这个回文子串有bug,然后就不知道怎么改了. ...
- windows之实现3D立体效果的三种方法
第一种:快捷键:win+tab 另外一种:cmd输入rundll32.exe dwmapi #105 第三种:使用软件bumptop
- Leetcode 细节实现 Set Matrix Zeroes
Set Matrix Zeroes Total Accepted: 18139 Total Submissions: 58671My Submissions Given a m x n matrix, ...
- WPF界面设计技巧(9)—使用UI自动化布局
原文:WPF界面设计技巧(9)-使用UI自动化布局 最近一直没时间更新这系列文章,因为我一直在埋头编写我的第一个WPF应用程序:MailMail 今天开始编写附属的加密/解密工具,对UI自动化布局有些 ...
- UVA 10404 Bachet's Game(dp + 博弈?)
Problem B: Bachet's Game Bachet's game is probably known to all but probably not by this name. Initi ...