Table of Contents

hbase

hbase shell

To script stuff through hbase shell, there are two ways. One is to pipe things directly:

echo list | hbase shell

And the other is to write a script:

echo list > test_script
hbase shell test_script

To save history, add this to .irbrc:

require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb_history"
Kernel.at_exit do
    IRB.conf[:AT_EXIT].each do |i|
        i.call
    end
end

Display status:

echo status | hbase shell
5 servers, 0 dead, 2365.2000 average load

List tables:

echo list | hbase shell

Describe the table:

echo "describe 'table'" | hbase shell

hbase backups

Exporting a table

From the docs: “Export is a utility that will dump the contents of table to HDFS in a sequence file.” Source

hbase org.apache.hadoop.hbase.mapreduce.Export <tablename> <outputdir> [<versions> [<starttime> [<endtime>]]]

For example, exporting table table_name:

hbase org.apache.hadoop.hbase.mapreduce.Export table_name /tmp/table_name

Importing a table:

From the docs: “Import is a utility that will load data that has been exported back into HBase.” Source

hbase -Dhbase.import.version=0.94 org.apache.hadoop.hbase.mapreduce.Import <tablename> <inputdir>

TTL

Changing TTL: “ColumnFamilies can set a TTL length in seconds, and HBase will automatically delete rows once the expiration time is reached. This applies to all versions of a row - even the current one. The TTL time encoded in the HBase for the row is specified in UTC.” Source

Change the TTL (time-to-live), and compact the data, which will erase anything older than that, in this case, one week:

alter 'table', { TTL => 604800 }
major_compact 'table'