Hbase, a hadoop NoSQL database-snapshot explained

Hi Readers,

I am happy to post another blog post on how to take HBase snapshot of a table in hortonworks sandbox 2.5.

I have created a table named ‘person’ in HBase.

hbase(main):032:0> list
TABLE
person
1 row(s) in 0.080 seconds.

I use the scan command to show the data inside the person table.

hbase(main):033:0> scan 'person'
ROW COLUMN+CELL
 1 column=location:, timestamp=1490028012845, value=Chennai
 1 column=name:, timestamp=1490027975127, value=Raj
 1 column=pincode:, timestamp=1490028023696, value=12341
 2 column=location:, timestamp=1490028131440, value=London
 2 column=name:, timestamp=1490028040307, value=Ajay
 2 column=pincode:, timestamp=1490028098868, value=9039
 3 column=location:, timestamp=1490028123508, value=Qwerty
 3 column=name:, timestamp=1490028074518, value=Anad
 3 column=pincode:, timestamp=1490028104978, value=329039
3 row(s) in 0.1230 seconds.

Now I will show how to take a snapshot.

In hbase-site.xml, hbase.snapshot.enabled value should be true.

   
 hbase.snapshot.enabled  
 true 

In HBase shell type the following command  : snapshot ‘table_name’, ‘snapshot_name’

hbase(main):034:0> snapshot 'person', 'personSnapshot20032017'

Use the following command to list the snapshots:

hbase(main):034:0> list_snapshots
SNAPSHOT TABLE + CREATION TIME
 MyStreamSnapshot-03202017 MyStream (Mon Mar 20 16:16:52 +0000 2017)
 personSnapshot20032017 person (Mon Mar 20 16:44:21 +0000 2017)
2 row(s) in 0.1680 seconds

=> ["MyStreamSnapshot-03202017", "personSnapshot20032017"]

You can also delete a snapshot using the following command: delete_snapshot ‘snapshot_name’

You can also clone a table from a snapshot: clone_snapshot ‘snapshot_name’, ‘table_name’.

The snapshot details can be found under this hdfs location

/apps/hbase/data/.hbase-snapshot/personSnapshot20032017/data.manifest

/apps/hbase/data/.hbase-snapshot/personSnapshot20032017/.snapshotinfo

Scenario:

You have deleted a table in HBase (say) person table. You have the snapshot file.(type list_snapshots in hbase shell)

Just use the following command: restore_snapshot ‘snapshot_name’.

restore_snapshot 'personSnapshot20032017'. It will automatically restore the table_schema at that time.

What is a Snapshot?

A snapshot is a set of metadata information that allows an admin to get back to a previous state of the table. A snapshot is not a copy of the table; it’s just a list of file names and doesn’t copy the data.

Transfer snapshot from one cluster to another cluster:

The org.apache.hadoop.hbase.snapshot.ExportSnapshot tool copies all the data related to a snapshot (HFiles, logs, and snapshot metadata) to another cluster:

hbase class org.apache.hadoop.hbase.snapshot.ExportSnapshot -snapshot snapshot01082014 -copy-to hdfs://127.0.0.1:9000/hbase -mappers 8 -bandwidth 100

The above command has eight map jobs which will run to export all snapshots to another cluster with a limiting bandwidth of 100 MB/s.

HBase CheatSheet:

Create a table – create ‘table_name’,’column_family’

  • List a table – list
  • View a table – scan table_name
  • Insert data – put ‘table_name’,’row1′,’column_name:’,’column_value’
  • Update data – use the above command but change the column value.
  • Select /Read data – get ‘table_name’,’row1′
  • delete a cell – delete ‘table_name’, ‘row1’, ‘column_name ’, ‘time stamp’
  • disable a table – disable ‘table_name’
  • drop a table – drop ‘table_name’
  • enable a table – enable ‘table_name’
  • describe a table – describe ‘table_name’
  • exists a table – exists ‘table_name’
  • count no.of rows in a table – count ‘table_name’
  • truncate a table – truncate ‘table_name’

Thanks for reading this post. Subscribe my blog for  some awesome posts.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s