25

I have a Hbase table X and I want to create an exact copy of it and name it Y. Could someone let me know how it is possible?

Thanks

user1586205
  • 283
  • 1
  • 3
  • 7

7 Answers7

36

Assuming you want to copy the table on the same cluster you can use HBase snapshots in the hbase shell you can

snapshot 'sourceTable', 'sourceTable-snapshot'
clone_snapshot 'sourceTable-snapshot', 'newTable'
hyness
  • 4,785
  • 1
  • 22
  • 24
Arnon Rotem-Gal-Oz
  • 25,469
  • 3
  • 45
  • 68
  • Prior to version 0.94.6, the only way to backup or to clone a table is to use CopyTable/ExportTable – honzajde Jan 22 '15 at 14:56
  • How can we clone a table in 0.94.1? As I learnt, snapshot is available in the newer versions – Sami Oct 07 '16 at 08:13
  • Beware this bug requiring superuser permissions to clone tables if using server <1.4.0: https://issues.apache.org/jira/browse/HBASE-16724 – jordanpg Mar 06 '17 at 14:20
7

CopyTable command is very handy to replicate HBase Tables. Use it in the following way:

hbase org.apache.hadoop.hbase.mapreduce.CopyTable --new.name=Y X;
Pratik Patil
  • 3,662
  • 3
  • 31
  • 31
  • I tried this one but I want it to cross replicate on a different cluster's table – Murtaza Kanchwala Aug 03 '16 at 10:38
  • 1
    it says "undefined local variable or method `new'". What is it so? – Sami Oct 07 '16 at 08:20
  • does this method takes the exact copy? my table has readonly='false' in its description. I am creating a new table with the same fields as my table. But copying does not make its description as same – Sami Oct 12 '16 at 12:37
3

use hbase shell
1. make sure you enbale snapshot in hbase-site.xml

  <property>
     <name>hbase.snapshot.enabled</name>
     <value>true</value>
    </property>

2. hbase> snapshot 'x' ,'snapshot_x'
3. hbase> clone_snapshot 'snapshot_x' ,'another_x'

toby941
  • 378
  • 2
  • 4
1

In hbase shell check version;

hbase(main):001:0> version
0.90.4, r1150278, Sun Jul 24 15:53:29 PDT 2011

if older version of 0.94.6 then you should use mapredeuce jobs. snapshots are available since 0.94.6 if it is above, you may use toby941 answer or you can use one of these

A)

./hbase org.apache.hadoop.hbase.mapreduce.CopyTable
Usage: CopyTable [--rs.class=CLASS] [--rs.impl=IMPL] [--starttime=X] [--endtime=Y] [--new.name=NEW] [--peer.adr=ADR] <tablename>

B-1)

./hbase org.apache.hadoop.hbase.mapreduce.Export
Usage: Export [-D <property=value>]* <tablename> <outputdir> [<versions> [<starttime> [<endtime>]]]

B-2) then import with whatever name you want

./hbase org.apache.hadoop.hbase.mapreduce.Import
Usage: Import <tablename> <inputdir>
Community
  • 1
  • 1
Joker
  • 96
  • 6
0

According to the HBase documentations here (1, 2) are the options.

Praveen Sripati
  • 32,799
  • 16
  • 80
  • 117
0

this will work..

hbase org.apache.hadoop.hbase.mapreduce.Export tableA /hbase_export/tableA

hbase org.apache.hadoop.hbase.mapreduce.Import /hbase_export/tableA tableAcopy
Tivie
  • 18,864
  • 5
  • 58
  • 77
Kamal D
  • 11
0

Snapshot methodology may not work if you are on older version of hbase https://issues.apache.org/jira/browse/HBASE-8742 . In that case you may have to manually copy hbase schema and then apply snapshot or better to upgrade to fixed version.

AkD
  • 427
  • 10
  • 19