全部产品
E-MapReduce

HBase备份

更新时间:2017-06-07 13:26:11   分享:   

E-MapReduce的HBase集群,可以通过HBase内置的快照(snapshot)功能对HBase的表进行备份,并将备份的数据导出到阿里云存储服务OSS中,示例如下:

1.创建HBase集群

详见集群创建文档

2.创建table

  1. >create 'test','cf'

3.添加数据

  1. > put 'test','a','cf:c1',1
  2. > put 'test','a','cf:c2',2
  3. > put 'test','b','cf:c1',3
  4. > put 'test','b','cf:c2',4
  5. > put 'test','c','cf:c1',5
  6. > put 'test','c','cf:c2',6

4.创建快照

  1. hbase snapshot create -n test_snapshot -t test

查看快照

  1. >list_snapshots
  2. SNAPSHOT TABLE + CREATION TIME
  3. test_snapshot test (Sun Sep 04 20:31:00 +0800 2016)
  4. 1 row(s) in 0.2080 seconds

5. 导出到OSS

  1. hbase org.apache.hadoop.hbase.snapshot.ExportSnapshot -snapshot test_snapshot -copy-to oss://$accessKeyId:$accessKeySecret@$bucket.oss-cn-hangzhou-internal.aliyuncs.com/hbase/snapshot/test

备注: OSS使用内网Endpoint

6.创建另一个HBase集群

7.OSS导出快照

  1. hbase org.apache.hadoop.hbase.snapshot.ExportSnapshot -snapshot test_snapshot -copy-from oss://$accessKeyId:$accessKeySecret@$bucket.oss-cn-hangzhou-internal.aliyuncs.com/hbase/snapshot/test -copy-to /hbase/

8.从快照恢复数据

  1. >restore _snapshot 'test_snapshot'
  1. >scan 'test'
  2. ROW COLUMN+CELL
  3. a column=cf:c1, timestamp=1472992081375, value=1
  4. a column=cf:c2, timestamp=1472992090434, value=2
  5. b column=cf:c1, timestamp=1472992104339, value=3
  6. b column=cf:c2, timestamp=1472992099611, value=4
  7. c column=cf:c1, timestamp=1472992112657, value=5
  8. c column=cf:c2, timestamp=1472992118964, value=6
  9. 3 row(s) in 0.0540 seconds

9.从快照创建新表

  1. >clone_snapshot 'test_snapshot','test_2'
  1. >scan 'test_2'
  2. ROW COLUMN+CELL
  3. a column=cf:c1, timestamp=1472992081375, value=1
  4. a column=cf:c2, timestamp=1472992090434, value=2
  5. b column=cf:c1, timestamp=1472992104339, value=3
  6. b column=cf:c2, timestamp=1472992099611, value=4
  7. c column=cf:c1, timestamp=1472992112657, value=5
  8. c column=cf:c2, timestamp=1472992118964, value=6
  9. 3 row(s) in 0.0540 seconds
本文导读目录
本文导读目录
以上内容是否对您有帮助?