Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

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

avatar
Contributor

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.

2 REPLIES 2

avatar
Master 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 hbase_scan.sh
echo "scan 'test_use',{FILTER =>\"(PrefixFilter ('4'))\"}"|hbase shell>hbase.txt
hadoop fs -put -f /<local-path-to>/hbase.txt /<hadoop-path>/
wait
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.

avatar
Super Guru

@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.

Thanks,

Aditya