利用HBase的快照功能来修改表名

hbase的快照功能常常被用来做数据的恢复的,但是由于项目的特殊需求需要改hbase表的表名。在官网上通过快照功能来修改hbase表名的用法:

下面展示用shell命令的和Java api两种方式:

In versions 0.90.x of hbase and earlier, we had a simple script that would rename the hdfs table directory and then do an edit of the hbase:meta table replacing all mentions of the old table name with the new. The script was called ./bin/rename_table.rb. The script was deprecated and removed mostly because it was unmaintained and the operation performed by the script was brutal.

As of hbase 0.94.x, you can use the snapshot facility renaming a table. Here is how you would do it using the hbase shell:

1. hbase shell

hbase shell> disable 'tableName'
hbase shell> snapshot 'tableName', 'tableSnapshot'
hbase shell> clone_snapshot 'tableSnapshot', 'newTableName'
hbase shell> delete_snapshot 'tableSnapshot'
hbase shell> drop 'tableName'

2. Java api

 public static boolean renameHBaseTable(String oldTableName) throws Exception {
    //创建连接 Connection con
= ConnectionFactory.createConnection();
    //通过连接获取表的管理对象 Admin admin
= con.getAdmin(); String snapshotName = oldTableName + "_snap"; String newTableName = oldTableName + "_ueser_delete";     //做快照之前先禁用表 admin.disableTable(TableName.valueOf(oldTableName));
    //把之前的表做个快照 admin.snapshot(snapshotName, TableName.valueOf(oldTableName));
    //然后在从当前快照中克隆出一个新的表 admin.cloneSnapshot(snapshotName, TableName.valueOf(newTableName));     //删除快照 admin.deleteSnapshot(snapshotName);
    //删除之前的表 admin.deleteTable(TableName.valueOf(oldTableName));
return true; }

 

转载于:https://www.cnblogs.com/itboys/p/6764054.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值