Support Questions

Find answers, ask questions, and share your expertise
Check out our newest addition to the community, the Cloudera Data Analytics (CDA) group hub.

How to retrieve a particular Rowkey from Hbase table and Store it in HDFS


Hi All,

I'm having the requirement of retrieving a Particular Rowkey from Hbase tables and Store those in HDFS for taking Backup, is there any option to achieve this scenario.I tried with scan 'TABLENAME',{FILTER =>"(PrefixFilter ('ROWKEY'))"} for retrieving, but i don't know how to store those ROWKEY information in HDFS. Is there best way to do this.


Super Guru

Hi @Mathi Murugan,

The simply way to retrieve particular Rowkey from hbase to HDFS is,

Run the scan command using echo with hbase shell and store the results to local then copy the results to HDFS.

Sample Shell script would be

bash# cat
echo "scan 'test_use',{FILTER =>\"(PrefixFilter ('4'))\"}"|hbase shell>hbase.txt
hadoop fs -put -f /<local-path-to>/hbase.txt /<hadoop-path>/
rm <local-path-to>/hbase.txt

In this script we are storing the scan results to hbase.txt file in local

Then copying the file to HDFS

Then deleting the local file.

@Mathi Murugan,

You can use this one line command

echo "scan 'test_1',{FILTER =>\"(PrefixFilter ('r1'))\"}" | hbase shell -n | grep "column=" | hdfs dfs -appendToFile - /tmp/hbaseresults.txt

Here 'test_1' is the table name, 'r1' is the row key and /tmp/hbaseresults.txt is the hdfs file path. You can replace these values with your values.



Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.