Simple HBase Schema Backup and Restore
Posted March 30th, 2010 by adminA simple PHP script that writes and reads HBase schemas formatted in JSON using the HBase shell.
There is optional support for you to manually modify the output file and add in rows to be imported on restore. Here is a sample schema:
{'TABLES' : [
{'NAME' : 'sites', 'FAMILIES' : [{'NAME' : 'meta_data', 'COMPRESSION' : 'NONE', 'VERSIONS' : '3', 'TTL' : '2147483647','BLOCKSIZE' : '65536', 'IN_MEMORY' : 'false', 'BLOCKCACHE' : 'true'}, {'NAME' : 'services', 'COMPRESSION' : 'NONE', 'VERSIONS' : '3', 'TTL' : '2147483647', 'BLOCKSIZE' : '65536', 'IN_MEMORY' : 'false', 'BLOCKCACHE' : 'true'}]},
{’NAME’ : ‘users’, ‘FAMILIES’ : [{'NAME' : 'meta_data', 'COMPRESSION' : 'NONE', 'VERSIONS' : '3', 'TTL' : '2147483647', 'BLOCKSIZE' : '65536', 'IN_MEMORY' : 'false', 'BLOCKCACHE' : 'true'}, {'NAME' : 'sessions', 'COMPRESSION' : 'NONE', 'VERSIONS' : '3', 'TTL' : '2147483647', 'BLOCKSIZE' : '65536', 'IN_MEMORY' : 'false', 'BLOCKCACHE' : 'true'}]}
],
‘ROWS’ : [
{'TABLE':'sites','KEY':'atest','FAMILY':'meta_data','COLUMN':'name','VALUE':'Test Site'},
{'TABLE':'sites','KEY':'anothertest','FAMILY':'meta_data','COLUMN':'name','VALUE':'A site name'}
]}
The script is not complete or robust by any means - but it works! Feel free to download, use, and modify however you’d like (GPL). Note: It currently doesn’t handle enabled/disabled
Setup: Set an HBASE_HOME environment variable to the base directory of your HBase installation.
Usage: php hbase-schema-manager.php backup mybackup.json