删除Hbase中所有表的脚本

发布于 2024-09-28 19:39:17 字数 211 浏览 4 评论 0原文

我可以告诉 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

淑女气质 2024-10-05 19:39:17

disable_alldrop_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.

等风也等你 2024-10-05 19:39:17

我有一个方便的脚本,它使用 Python Happybase 库来完成此操作:

import happybase

c = happybase.Connection()

for table in c.tables():
  c.disable_table(table)
  c.delete_table(table)
  print "Deleted: " + table

您需要安装 Happybase 才能使用此脚本,并且你可以将其安装为:

sudo easy_install happybase

I have a handy script that does exactly this, using the Python Happybase library:

import happybase

c = happybase.Connection()

for table in c.tables():
  c.disable_table(table)
  c.delete_table(table)
  print "Deleted: " + table

You will need Happybase installed to use this script, and you can install it as:

sudo easy_install happybase
你是我的挚爱i 2024-10-05 19:39:17

您可以通过管道将命令发送到 bin/hbase shell 命令。从那里您可以使用一些脚本来获取表名称并将禁用/删除命令通过管道返回到 hbase。

IE

echo "list" | bin/hbase shell | ./filter_table_names.pl > table_names.txt
./turn_table_names_into_disable_delete_commands.pl table_names.txt | bin/hbase shell 

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.

echo "list" | bin/hbase shell | ./filter_table_names.pl > table_names.txt
./turn_table_names_into_disable_delete_commands.pl table_names.txt | bin/hbase shell 
从此见与不见 2024-10-05 19:39:17

有一个黑客。
打开 $HBASE_HOME/lib/ruby/shell/commands/list.rb 文件并在命令方法的底部添加以下行。

return list

之后,list 命令返回所有表的名称数组。
然后就这样做。

list.each {|t| disable t;drop t}

There is a hack.
Open $HBASE_HOME/lib/ruby/shell/commands/list.rb file and add below line at the bottom of command method.

return list

After that, list command returns an array of names of all tables.
And then do just like this.

list.each {|t| disable t;drop t}
北渚 2024-10-05 19:39:17

我不是通过 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

淡看悲欢离合 2024-10-05 19:39:17

如果您正在寻找通过 shell 脚本在“一行”中执行此操作的方法,您可以使用以下方法:

$ echo 'list.each {|t| disable t; drop t}; quit;' | hbase 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:

$ echo 'list.each {|t| disable t; drop t}; quit;' | hbase shell

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 the list command, and then disables & drops each table as it iterates through the array that list returned. Once it's done, it quits.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文