From c6544528d5844d04245cb19b0ff9486815f524e2 Mon Sep 17 00:00:00 2001 From: Ashish Singhi Date: Tue, 4 Nov 2014 18:37:23 +0530 Subject: [PATCH] HBASE-8572 Enhance delete_snapshot.rb to call snapshot deletion API with regex --- hbase-shell/src/main/ruby/hbase/admin.rb | 6 +++--- .../src/main/ruby/shell/commands/delete_snapshot.rb | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb b/hbase-shell/src/main/ruby/hbase/admin.rb index 2a5876a..899f179 100644 --- a/hbase-shell/src/main/ruby/hbase/admin.rb +++ b/hbase-shell/src/main/ruby/hbase/admin.rb @@ -763,9 +763,9 @@ module Hbase end #---------------------------------------------------------------------------------------------- - # Delete specified snapshot - def delete_snapshot(snapshot_name) - @admin.deleteSnapshot(snapshot_name.to_java_bytes) + # Deletes the snapshots matching the given regex + def delete_snapshot(regex) + @admin.deleteSnapshots(regex).to_a end #---------------------------------------------------------------------------------------------- diff --git a/hbase-shell/src/main/ruby/shell/commands/delete_snapshot.rb b/hbase-shell/src/main/ruby/shell/commands/delete_snapshot.rb index b8c3791..a3b200c 100644 --- a/hbase-shell/src/main/ruby/shell/commands/delete_snapshot.rb +++ b/hbase-shell/src/main/ruby/shell/commands/delete_snapshot.rb @@ -21,15 +21,27 @@ module Shell class DeleteSnapshot < Command def help return <<-EOF -Delete a specified snapshot. Examples: +Delete all of snapshots matching the given regex. Examples: + + hbase> delete_snapshot 'snapshotName' + hbase> delete_snapshot 's.*' - hbase> delete_snapshot 'snapshotName', EOF end - def command(snapshot_name) + def command(regex) + list = admin.list_snapshot(regex) + count = list.size + list.each do |snapshot| + puts snapshot.name + end + puts "\nDelete the above #{count} snapshots (y/n)?" unless count == 0 + answer = 'n' + answer = gets.chomp unless count == 0 + puts "No snapshots matched the regex #{regex.to_s}" if count == 0 + return unless answer =~ /y.*/i format_simple_command do - admin.delete_snapshot(snapshot_name) + admin.delete_snapshot(regex) end end end -- 1.9.2.msysgit.0