Skip to content

Instantly share code, notes, and snippets.

@andriikravets
Last active December 29, 2015 00:29
Show Gist options
  • Save andriikravets/7585785 to your computer and use it in GitHub Desktop.
Save andriikravets/7585785 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
@@path = '/opt/tmp_tables_list'
@@remove_except_table = 'localPreferences'
class Remover
def initialize
@tables = Array.new
end
def fix_base
`echo "list" | hbase shell | grep -v #{@@remove_except_table} > #{@@path}`
sanitize_file @@path
`cat #{@@path} | awk '{print "disable \\"" $1 "\\""}' | hbase shell`
`cat #{@@path} | awk '{print "drop \\"" $1 "\\""}' | hbase shell`
end
def sanitize_file(path)
File.open(path).each do |line|
tables_found = line.include? 'TABLE'
if tables_found and !line.include? ' seconds' and !line.include? 'TABLE'
@tables << line
end
end
write_tables
end
def write_tables
File.open(@@path, 'w') do |file|
@tables.each do |string|
file.write(string)
end
end
end
end
Remover.new.fix_base
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment