HBase数据备份

使用4种方式进行HBase数据备份

一、使用快照

1.开启快照许可:

将 hbase-site.xml 中的 hbase.snapshot.enabled 设置为true

2.在hbase sehll中创建快照:

snapshot 'tableName','snapshotName'

3.退出hbase sehll,迁移快照:

hbase org.apache.hadoop.hbase.snapshot.ExportSnapshot -snapshot snapshotName-copy-from hdfs:/nameservice1/hbase  -copy-to  hdfs://nameservice1_backup/hbase  -mappers 20 -bandwidth 1024

4.在hbase shell中恢复快照:

restore_snapshot 'snapshotName'

5.使用快照生成新表:

clone_snapshot 'snapshotName','newTableName'

二、导出数据文件

在源hbase集群导出数据文件到hdfs:

hbase org.apache.hadoop.hbase.mapreduce.Export <tablename> <outputdir>

将源hdfs中的hbase数据文件导入目标hbase的hdfs中后,执行导入数据文件:

hbase org.apache.hadoop.hbase.mapreduce.Import <tablename> <imputdir>

三、下载hdfs中的hbase hfile,上传到另一个集群再执行修复元数据

1.下载源hdfs下的hbase hfile;

2.将hbase hfile上传至目标hdfs对应hbase目录下,例如: /apps/hbase/data/mytest;

3.检查新上传的文件权限:

 su hbase
 hadoop fs -chown -R hbase:hdfs /apps/hbase/data/mytest
 hadoop fs -chmod -R 777 /apps/hbase/data/mytest

4.执行hbase元数据修复:

hbase hbck -fixMeta
hbase hbck -fixAssignments

四、使用 hbase CopyTable 工具

peer.adr参数:hbase zookeeper地址;

new.name参数:备份表名;

hbase org.apache.hadoop.hbase.mapreduce.CopyTable --peer.adr=master:2181:/hbase --new.name=mytest_backup mytest

原创不易,转载请注明出处

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容