Skip to content

Instantly share code, notes, and snippets.

@vessi
Forked from andriikravets/gist:7585785
Last active December 29, 2015 00:29
Show Gist options
  • Save vessi/7585893 to your computer and use it in GitHub Desktop.
Save vessi/7585893 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
@path = '/opt/tmp_tables_list'
@remove_except_table = 'localPreferences'
@tables = []
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
fix_base
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment