删除Hbase中所有表的脚本
我可以告诉 hbase 使用以下方法禁用和删除特定表:
disable 'tablename'
drop 'tablename'
但我想删除数据库中的所有表,而不对任何表的名称进行硬编码。有办法做到这一点吗?我想通过命令行实用程序 ./hbase shell
来完成此操作,而不是通过 Java 或 Thrift。
I can tell hbase to disable and delete particular tables using:
disable 'tablename'
drop 'tablename'
But I want to delete all the tables in the database without hardcoding the names of any of the tables. Is there a way to do this? I want to do this through the command-line utility ./hbase shell
, not through Java or Thrift.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
disable_all 和 drop_all 已作为命令添加到HBase 红宝石外壳。这些命令已添加到 jira HBASE-3506 这些命令采用表的正则表达式来禁用/删除。他们会在继续之前要求确认。这将使删除大量表变得非常容易,并且不需要外部库或脚本。
disable_all and drop_all have been added as commands in the HBase ruby shell. These commands were added in jira HBASE-3506 These commands take a regex of tables to disable/drop. And they will ask for confirmation before continuing. That should make droping lots of tables pretty easy and not require outside libraries or scripting.
我有一个方便的脚本,它使用 Python Happybase 库来完成此操作:
您需要安装 Happybase 才能使用此脚本,并且你可以将其安装为:
I have a handy script that does exactly this, using the Python Happybase library:
You will need Happybase installed to use this script, and you can install it as:
您可以通过管道将命令发送到
bin/hbase shell
命令。从那里您可以使用一些脚本来获取表名称并将禁用/删除命令通过管道返回到 hbase。IE
You can pipe commands to the
bin/hbase shell
command. From there you can use some scripting to grab the table names and pipe the disable/delete commands back to hbase.i.e.
有一个黑客。
打开 $HBASE_HOME/lib/ruby/shell/commands/list.rb 文件并在命令方法的底部添加以下行。
之后,list 命令返回所有表的名称数组。
然后就这样做。
There is a hack.
Open $HBASE_HOME/lib/ruby/shell/commands/list.rb file and add below line at the bottom of command method.
After that, list command returns an array of names of all tables.
And then do just like this.
我不是通过 hbase shell 删除表,而是通过命令行删除它们,
-删除我的hadoop分布式文件系统目录,然后,
- 创建一个新的干净的 hadoop 分布式文件系统目录,然后,
- 使用“hadoop namenode -format”格式化我的 hadoop 分布式文件系统,然后,
- start-all.sh 和 start-hbase.sh
参考:
http://hadoop.apache。 org/common/docs/r0.20.1/api/overview-summary.html#overview_description
I'm not deleting tables through the hbase shell but I deleting them from the command line by,
- deleting my hadoop distributed filesystem directory, then,
- creating a new clean hadoop distributed filesystem directory, then,
- formatting my hadoop distributed filesystem with 'hadoop namenode -format', then,
- start-all.sh and start-hbase.sh
Reference:
http://hadoop.apache.org/common/docs/r0.20.1/api/overview-summary.html#overview_description
如果您正在寻找通过 shell 脚本在“一行”中执行此操作的方法,您可以使用以下方法:
注意: 以上是从 Bash shell 提示符运行的。它将命令回显到 hbase shell 中,并循环遍历从 list 命令返回的所有表,然后禁用 & 。在迭代
list
返回的数组时删除每个表。一旦完成,它就退出。If you're looking for something that will do this in a 'one-liner' via a shell script you can use this method:
NOTE: The above was run from Bash shell prompt. It echoes the commands into
hbase shell
and does a loop through all the tables that are returned from thelist
command, and then disables & drops each table as it iterates through the array thatlist
returned. Once it's done, it quits.