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;
}

最新文章

  1. 客户端连接RMS服务,报:服务暂时不可用,请确保已连接到此服务器…….
  2. sleep thread process
  3. 黑马程序员_Java基础:IO流总结
  4. CentOS/Redhat VNC 服务
  5. 面向对象(POP)和面向过程(OOP)
  6. 修改Delphi工具控件的默认字体
  7. 提高你30%的设计效率的PPT快捷键
  8. 爱加密Android APk 原理解析
  9. 使用Win32::OLE操作Excel——Excel对象模型
  10. android动画-动画分类及代码演示样例
  11. HDU 4349 Xiao Ming's Hope
  12. Bzoj3756
  13. Linux实践篇--crontab定时任务
  14. windows,分割路径.得出目录
  15. win10 右下角显示秒
  16. SQL Server 数据库部分常用语句小结(二)
  17. NGUI使用图集的精灵换图片
  18. BZOJ4764弹飞大爷——LCT
  19. python3 items() 与 python2 中iteritems()的区别
  20. How to Pronounce the 50 States

热门文章

  1. _T("D:\\122.txt")【字符集问题】或【类型转换问题】
  2. wamp下修改mysql root用户的登录密码方法
  3. linux下mysql 启动命令
  4. 在懂得BREW接口的原理之后, 那么该知道BREW接口是如何声明和实现了
  5. List 和 ObservableCollection的区别
  6. Gson、FastJson、json-lib对比与实例
  7. js array.filter实例(数组去重)
  8. MITE
  9. 使用synchronized(非this对象)同步代码块解决脏读问题
  10. synchronized同步方法