HBase备份恢复练习
一.冷备
1.创建测试表并插入测试数据
[root@weekend05 ~]# hbase shell
hbase(main):005:0> create 'scores','grade','course'
0 row(s) in 0.4940 seconds
=> Hbase::Table – scores
put 'scores','Tom','grade:','5'
hbase(main):006:0> put 'scores','Tom','course:math','97'
0 row(s) in 0.0710 seconds
hbase(main):007:0> put 'scores','Tom','course:art','87'
0 row(s) in 0.0100 seconds
hbase(main):008:0> put 'scores','Tom','course:english','80'
0 row(s) in 0.0100 seconds
hbase(main):009:0> put 'scores','Jim','grade:','4'
0 row(s) in 0.0210 seconds
hbase(main):010:0> put 'scores','Jim','course:chinese','89'
0 row(s) in 0.0410 seconds
hbase(main):011:0> put 'scores','Jim','course:english','80'
0 row(s) in 0.0090 seconds
hbase(main):012:0> scan 'scores'
ROW COLUMN+CELL
Jim column=course:chinese, timestamp=1465031482172, value=89
Jim column=course:english, timestamp=1465031493584, value=80
Jim column=grade:, timestamp=1465031470174, value=4
Tom column=course:art, timestamp=1465031443686, value=87
Tom column=course:english, timestamp=1465031459071, value=80
Tom column=course:math, timestamp=1465031419695, value=97
2 row(s) in 0.0920 seconds
2.停止HBase
[root@master ~]# stop-hbase.sh
stopping hbase................
3.进行备份
[root@weekend05 ~]# hadoop distcp /hbase /hbasebackup
。。。。。
内容太多
File System Counters
FILE: Number of bytes read=315885
FILE: Number of bytes written=456706
FILE: Number of read operations=0
FILE: Number of large read operations=0
FILE: Number of write operations=0
HDFS: Number of bytes read=103581
HDFS: Number of bytes written=103581
HDFS: Number of read operations=943
HDFS: Number of large read operations=0
HDFS: Number of write operations=187
Map-Reduce Framework
Map input records=161
Map output records=22
Input split bytes=151
Spilled Records=0
Failed Shuffles=0
Merged Map outputs=0
GC time elapsed (ms)=7
CPU time spent (ms)=0
Physical memory (bytes) snapshot=0
Virtual memory (bytes) snapshot=0
Total committed heap usage (bytes)=130547712
File Input Format Counters
Bytes Read=37917
File Output Format Counters
Bytes Written=2424
org.apache.hadoop.tools.mapred.CopyMapper$Counter
BYTESCOPIED=103581
BYTESEXPECTED=103581
BYTESSKIPPED=10257
COPY=139
SKIP=22
4.启动HBase
[root@weekend05 ~]# start-hbase.sh
[root@weekend05 ~]#hbase shell
5.删除测试数据
hbase(main):001:0> list
TABLE
hbase_student
my_data
myns1
new_scores
nyist
scores
user
7 row(s) in 0.2270 seconds
=> ["hbase_student", "my_data", "myns1", "new_scores", "nyist", "scores", "user"]
hbase(main):002:0> disable 'scores'
0 row(s) in 1.3210 seconds
hbase(main):003:0> drop 'scores'
0 row(s) in 0.4170 seconds
6.停止HBase
[root@weekend05 ~]# stop-hbase.sh
stopping hbase...............
7.恢复数据
[root@weekend05 ~]# hdfs dfs -mv /hbase /hbase_tmp’
[root@weekend05 ~]# hadoop distcp -overwrite /hbasebackup /
………上面省略
File System Counters
FILE: Number of bytes read=406438
FILE: Number of bytes written=500029
FILE: Number of read operations=0
FILE: Number of large read operations=0
FILE: Number of write operations=0
HDFS: Number of bytes read=167648
HDFS: Number of bytes written=167648
HDFS: Number of read operations=1503
HDFS: Number of large read operations=0
HDFS: Number of write operations=313
Map-Reduce Framework
Map input records=211
Map output records=0
Input split bytes=152
Spilled Records=0
Failed Shuffles=0
Merged Map outputs=0
GC time elapsed (ms)=44
CPU time spent (ms)=0
Physical memory (bytes) snapshot=0
Virtual memory (bytes) snapshot=0
Total committed heap usage (bytes)=159383552
File Input Format Counters
Bytes Read=53305
File Output Format Counters
Bytes Written=8
org.apache.hadoop.tools.mapred.CopyMapper$Counter
BYTESCOPIED=167648
BYTESEXPECTED=167648
COPY=211
8.启动HBase
[root@weekend05 ~]# start-hbase.sh
[root@weekend05 ~]# hbase shell
9.查看测试数据
hbase(main):001:0> scan 'scores'
ROW COLUMN+CELL
Jim column=course:chinese, timestamp=1465031482172, value=89
Jim column=course:english, timestamp=1465031493584, value=80
Jim column=grade:, timestamp=1465031470174, value=4
Tom column=course:art, timestamp=1465031443686, value=87
Tom column=course:english, timestamp=1465031459071, value=80
Tom column=course:math, timestamp=1465031419695, value=97
2 row(s) in 0.2320 seconds
二.热备
(1)使用export和import
1.创建测试表并插入测试数据
hbase(main):006:0> create 'scores','grade','course'
0 row(s) in 0.4480 seconds
=> Hbase::Table - scores
hbase(main):007:0> put 'scores','Tom','grade:','5'
0 row(s) in 0.0910 seconds
hbase(main):008:0> put 'scores','Tom','course:math','97'
0 row(s) in 0.0240 seconds
hbase(main):009:0> put 'scores','Tom','course:art','87'
0 row(s) in 0.0130 seconds
hbase(main):010:0> put 'scores','Tom','course:english','80'
0 row(s) in 0.0100 seconds
hbase(main):011:0> put 'scores','Jim','grade:','4'
0 row(s) in 0.0100 seconds
hbase(main):012:0> put 'scores','Jim','course:chinese','89'
0 row(s) in 0.0130 seconds
hbase(main):013:0> put 'scores','Jim','course:english','80'
0 row(s) in 0.0210 seconds
hbase(main):014:0> scan 'scores'
ROW COLUMN+CELL
Jim column=course:chinese, timestamp=1465032277623, value=89
Jim column=course:english, timestamp=1465032284037, value=80
Jim column=grade:, timestamp=1465032263803, value=4
Tom column=course:art, timestamp=1465032250427, value=87
Tom column=course:english, timestamp=1465032257150, value=80
Tom column=course:math, timestamp=1465032242712, value=97
Tom column=grade:, timestamp=1465032224863, value=5
2 row(s) in 0.0320 seconds
2.导出数据
a.导出至Linux目录下
[root@weekend05 ~]# hbase org.apache.hadoop.hbase.mapreduce.Export scores /tmp/scores
.。。。。
File System Counters
FILE: Number of bytes read=3658123
FILE: Number of bytes written=24070263
FILE: Number of read operations=0
FILE: Number of large read operations=0
FILE: Number of write operations=0
HDFS: Number of bytes read=19940317
HDFS: Number of bytes written=385
HDFS: Number of read operations=138
HDFS: Number of large read operations=0
HDFS: Number of write operations=3
Map-Reduce Framework
Map input records=2
Map output records=2
Input split bytes=64
Spilled Records=0
Failed Shuffles=0
Merged Map outputs=0
GC time elapsed (ms)=8
CPU time spent (ms)=0
Physical memory (bytes) snapshot=0
Virtual memory (bytes) snapshot=0
Total committed heap usage (bytes)=29687808
File Input Format Counters
Bytes Read=0
File Output Format Counters
Bytes Written=385
b.导出至HDFS目录下
[root@weekend05 ~]# hbase org.apache.hadoop.hbase.mapreduce.Export scores hdfs://master:9000/myback_scores
.。。。。。
File System Counters
FILE: Number of bytes read=3658123
FILE: Number of bytes written=24067137
FILE: Number of read operations=0
FILE: Number of large read operations=0
FILE: Number of write operations=0
HDFS: Number of bytes read=19940317
HDFS: Number of bytes written=385
HDFS: Number of read operations=138
HDFS: Number of large read operations=0
HDFS: Number of write operations=3
Map-Reduce Framework
Map input records=2
Map output records=2
Input split bytes=64
Spilled Records=0
Failed Shuffles=0
Merged Map outputs=0
GC time elapsed (ms)=8
CPU time spent (ms)=0
Physical memory (bytes) snapshot=0
Virtual memory (bytes) snapshot=0
Total committed heap usage (bytes)=29687808
File Input Format Counters
Bytes Read=0
File Output Format Counters
Bytes Written=385
3.删除表
hbase(main):015:0> disable 'scores'
0 row(s) in 1.2200 seconds
hbase(main):016:0> drop 'scores'
0 row(s) in 0.1700 seconds4.恢复数据
在HBase中创建表结构
hbase(main):017:0> create 'scores','grade','course'
0 row(s) in 0.4450 seconds
=> Hbase::Table – scores
导入数据(两种方法)
1)[root@weekend05~]#hbase org.apache.hadoop.hbase.mapreduce.Import scores /tmp/scores
2)[root@weekend05~]#hbase org.apache.hadoop.hbase.mapreduce.Import scores hdfs://master:9000/myback_scores
5.测试数据
hbase(main):016:0> scan 'scores'
ROW COLUMN+CELL
Jim column=course:chinese, timestamp=1465032277623, value=89
Jim column=course:english, timestamp=1465032284037, value=80
Jim column=grade:, timestamp=1465032263803, value=4
Tom column=course:art, timestamp=1465032250427, value=87
Tom column=course:english, timestamp=1465032257150, value=80
Tom column=course:math, timestamp=1465032242712, value=97
Tom column=grade:, timestamp=1465032224863, value=5
2 row(s) in 0.0320 seconds
(2)使用CopyTable备份到本数据库内的表内
在HBase中创建表结构
hbase(main):020:0> create 'new_scores','grade','course'
0 row(s) in 1.2730 seconds
使用CopyTable进行备份
[root@weekend05~]#hbase org.apache.hadoop.hbase.mapreduce.CopyTable --new.name=new_scores scores
查看数据
hbase(main):025:0> scan 'new_scores'
ROW COLUMN+CELL
Jim column=course:chinese, timestamp=1464608884979, value=89
Jim column=course:english, timestamp=1464608885088, value=80
Jim column=grade:, timestamp=1464608884637, value=4
Tom column=course:art, timestamp=1464608875482, value=87
Tom column=course:english, timestamp=1464608875733, value=80
Tom column=course:math, timestamp=1464608875256, value=97
Tom column=grade:, timestamp=1464608875010, value=5
2 row(s) in 0.1120 seconds
疑难小结:
HBase是一个基于LSM树(log-structured merge-tree)的分布式数据存储系统,它使用复杂的内部机制确保数据准确性、一致性、多版本等。因此,你如何获取数十个region server在HDFS和内存中的存储的众多HFile文件、WALs(Write-Ahead-Logs)的一致的数据备份?Snapshots(快照)
HBase快照功能丰富,有很多特征,并且创建时不需要关闭集群。关于snapshot在文章《apache hbase snapshot介绍》中有更详细的介绍。
快照能通过在HDFS中创建一个和unix硬链接相同的存储文件,简单捕捉你的hbase表的某一时刻的信息(图1)。这些快照在几秒内就可以完成,几乎对整个集群没有任何性能影响。并且,它只占用一个微不足道的空间。除了在metadata文件中存储的极少目录数据,你的数据不会冗余,快照允许你的系统回滚到(创建快照)那个时刻,当然,你需要恢复快照。通过在HBase shell中运行如下命令来创建一个表的快照:
hbase(main):001:0> snapshot 'myTable', 'MySnapShot'
在执行这条命令之后,你将发现在hdfs中有一些小的数据文件。在 /hbase/.snapshot/myTable (CDH4) 或者hbase/.hbase-snapshots (Apache 0.94.6.1),这些文件中存储着快照信息。想要恢复数据只需要执行在shell中执行如下命令:
hbase(main):002:0> disable 'myTable'
hbase(main):003:0> restore_snapshot 'MySnapShot'
hbase(main):004:0> enable 'myTable'
正如你看到的,恢复快照需要对表进行离线操作。一旦恢复快照,那任何在快照时刻之后做的增加/更新数据都会丢失。如果你的业务需求是这样的:你必须有数据的异地备份,你可以用exportSnapshot命令赋值一个表的数据到你的本地HDFS或者你选择的远程HDFS中。
HBase复制(HBase Relication)
HBase赋值是另外一个负载较轻的备份工具。复制有三种模式:主->从(master->slave),主<->主(master<->master)和循环(cyclic)。这种方法给你灵活的从任意数据中心获取数据并且确保它能获得在其他数据中心的所有副本。在一个数据中心发生灾难性故障的情况下,客户端应用程序可以利用DNS工具,重定向到另外一个备用位置复制是一个强大的,容错的过程。它提供了“最终一致性”,意味着在任何时刻,最近对一个表的编辑可能无法应用到该表的所有副本,但是最终能够确保一致。
注:对于一个存在的表,你需要通过本文描述的其他方法,手工的拷贝源表到目的表。复制仅仅在你启动它之后才对新的写/编辑操作有效
HBase的导出工具是一个内置的实用功能,它使数据很容易从hbase表导入HDFS目录下的SequenceFiles文件。它创造了一个 map reduce任务,通过一系列HBase API来调用集群,获取指定表格的每一行数据,并且将数据写入指定的HDFS目录中。这个工具对集群来讲是性能密集的,因为它使用了mapreduce和 HBase 客户端API。但是它的功能丰富,支持制定版本或日期范围,支持数据的筛选,从而使增量备份可用。
下面是一个导出命令的简单例子:
hbase org.apache.hadoop.hbase.mapreduce.Export <tablename> <outputdir>
一旦你的表导出了,你就可以复制生成的数据文件到你想存储的任何地方(比如异地/离线集群存储)。你可以执行一个远程的HDFS集群/目录作为命令的输出目录参数,这样数据将会直接被导出到远程集群。使用这个方法需要网络,所以你应该确保到远程集群的网络连接是否可靠以及快速。
拷贝表(CopyTable)
拷贝表功能在文章《使用CopyTable在线备份HBase》中有详细描述,但是这里做了基本的总结。和导出功能类似,拷贝表也使用HBase API创建了一个mapreduce任务,以便从源表读取数据。不同的地方是拷贝表的输出是hbase中的另一个表,这个表可以在本地集群,也可以在远程集群。
一个简单的例子如下:
hbase org.apache.hadoop.hbase.mapreduce.CopyTable --new.name=testCopy test
这个命令将会拷贝名为test的表到集群中的另外一个表testCopy。
请注意,这里有一个明显的性能开销,它使用独立的“puts”操作来逐行的写入数据到目的表。如果你的表非常大,拷贝表将会导致目标region server上的memstore被填满,会引起flush操作并最终导致合并操作的产生,会有垃圾收集操作等等。
此外,你必须考虑到在HBase上运行mapreduce任务所带来的性能影响。对于大型的数据集,这种方法的效果可能不太理想。
HBase备份恢复练习的更多相关文章
- 云HBase备份恢复,为云HBase数据安全保驾护航
摘要: 介绍了阿里云HBase自研备份恢复功能的基本背景以及基本原理架构和基本使用方法. 云HBase发布备份恢复功能,为用户数据保驾护航.对大多数公司来说数据的安全性以及可靠性是非常重要的,如何 ...
- HBase备份还原OpenTSDB数据之Snapshot
前言 本文基于伪分布式搭建 hadoop+zookeeper+hbase+opentsdb之后,想了解前因后果的可以看上一篇和上上篇. opentsdb在hbase中生成4个表(tsdb, tsdb- ...
- MySQL 系列(四)主从复制、备份恢复方案生产环境实战
第一篇:MySQL 系列(一) 生产标准线上环境安装配置案例及棘手问题解决 第二篇:MySQL 系列(二) 你不知道的数据库操作 第三篇:MySQL 系列(三)你不知道的 视图.触发器.存储过程.函数 ...
- 基于MySQL MEB的备份恢复
MEB(MySQL Enterprise Backup)是MySQL商业版中提供的备份工具,属于物理备份. 同XtraBackup一样,mysqlbackup的使用过程同样包含如下三个步骤: 备份(- ...
- Xtrabackup原理及使用innobackupex进行MySQL数据库备份恢复
Xtrabackup是由percona提供的mysql数据库备份工具,据官方介绍,这也是世界上惟一一款开源的能够对innodb和xtradb数据库进行热备的工具. Xtrabackup中主要包含两个工 ...
- 在Linux操作系统下备份恢复技术的应用 转自https://yq.aliyun.com/articles/50205?spm=5176.100239.blogcont24250.9.CfBYE9
摘要: 安全防护:在Linux操作系统下备份恢复技术的应用 原文参见:http://linux.chinaunix.net/techdoc/system/2005/12/19/925898.shtm ...
- mongodb 的备份恢复导入与导出
导入导出 use hndb; db.s.save({name:'李四',age:18,score:80,address:'郑州'}); db.s.save({name:'李三',age:8,score ...
- [转]PLSQL Developer备份恢复oracle数据
本文转自:http://www.cnblogs.com/iampkm/archive/2013/06/09/3128273.html 使用PL sql提供的功能可以快速的备份恢复oracle数据. 1 ...
- MongoDB学习(三)数据导入导出及备份恢复
这几天想着公司要用MongoDB,自然就要用到数据导入导出,就自己学习了一下. 在Mongo学习(二)中就讲到了在bin目录下有一些工具,本篇就是使用这些工具进行数据的导入导出及备份恢复. 注意:以下 ...
随机推荐
- gcc 头文件是用户应用程序和函数库之间的桥梁和纽带 功能的真正逻辑实现是以硬件层为基础
gcc GCC, the GNU Compiler Collection - GNU Project - Free Software Foundation (FSF) http://gcc.gnu.o ...
- RubyMine安装、破解
经常安装东西,这是我安装过最快的ide破解版. 下载地址: http://www.jetbrains.com/ruby/download/index.html 破解序列号: name: rubymin ...
- redis12-----redis 与关系型数据库的对比
书和书签系统 create table book ( bookid int, title ) )engine myisam charset utf8; insert into book values ...
- SQL JOIN连接分类[转]
1.内联接(典型的联接运算,使用像 = 或 <> 之类的比较运算符):包括相等联接和自然联接: 内联接使用比较运算符根据每个表共有的列的值匹配两个表中的行: 2.外联接.外联接可以 ...
- java的数字精确计算问题-BigDecimal
java的数字运算,偶尔会出现精度的问题,以下阐述的 java的BigDecimal类的使用. 例如: System.out.println(0.9+0.3); 结果1.2 System.out.pr ...
- 2016-5-23 jsp
1.table的边框:rules这个参数,它有三个值(cols,rows,none),当rules=cols时,表格会隐藏横向的分隔线,也就是我们只能看到表格的列:当rules=rows时,就隐藏了纵 ...
- 汇编环境的搭建(windows 10 + debug)
1. debug.exe 安装 win10 版本过高,不再提供 debug.exe,甚至从别处获取的 debug.exe 的也无法运行. 汇编语言学习所需的各种执行文件(debug.exe.link. ...
- C#:C# 运算符
ylbtech-C#:C# 运算符 1.返回顶部 1. C# 运算符 运算符是一种告诉编译器执行特定的数学或逻辑操作的符号.C# 有丰富的内置运算符,分类如下: 算术运算符 关系运算符 逻辑运算符 位 ...
- DDK编写64位驱动时加入x64汇编的方法
上篇讲了如何在编写x64应用程序时加入x64汇编,这里来说说如何在编写x64驱动时加入x64汇编. 一.在asm文件中单独编写功能函数 比如要实现一个64位的加法函数,原型如下: ULONG64 my ...
- UI:动画
参考 UIView 层级管理.触摸.检测手机是否横屏.调整设备的方向 动画:为了提高用户的体验 View层的动画.UIlayer层的动画.UIView改变视图效果.UIlayer的绘图框架 #prag ...