25.28 hbase数据备份和恢复
以下过程针对线上没有启动新旧集群的情况,所以使用hbase export / import的方式进行数据的备份和迁移
25.28.1 Export过程
首先,先进入hbase所在机器,然后执行命令:
hbase shell
hbase(main):001:0> list
TABLE
test_migration
然后执行:
hbase(main):003:0> describe 'test_migration'
Table test_migration is ENABLED
test_migration
COLUMN FAMILIES DESCRIPTION
{
NAME => 'cf1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_EN
DING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536',
EPLICATION_SCOPE => '0'}
1 row(s) in 0.1710 seconds
通过上面发现有一个列族’cf1’
hbase(main):004:0> scan test_migration
NameError: undefined local variable or method `test_migration' for #<Object:0x48268eec>
hbase(main):005:0> scan 'test_migration'
ROW COLUMN+CELL
1 column=cf1:age, timestamp=1553738512684, value=18
1 column=cf1:name, timestamp=1553738512531, value=zhangsan
1 column=cf1:sex, timestamp=1553738512591, value=\xE7\x94\xB7
1 row(s) in 0.0950 seconds
Export数据(以下直接在bash中执行):
hbase org.apache.hadoop.hbase.mapreduce.Export test_migration /tzq/hbaseData
将数据拷贝到本地:
scp -r admin@datacenter1:/home/admin/hbaseDataTest /home/admin/ambari
然后将数据通过xftp拷贝到本地
25.28.2 Import过程
首先创建一个命令空间(这里是带有命名空间的场景),然后创建相关表
hbase>create_namespace 'test'
hbase(main):022:0> create 'test:test_migration','cf1' (其中cf1为列族)
hbase(main):023:0> list
TABLE
test:test_migration
user
3 row(s)
Took 0.0086 second
将本地数据put到hdfs上:
hdfs dfs -put hbaseDat