diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb index 8b6b44f..4690cd3 100644 --- a/hbase-shell/src/main/ruby/shell.rb +++ b/hbase-shell/src/main/ruby/shell.rb @@ -357,6 +357,8 @@ Shell.load_command_group( rename_snapshot delete_snapshot list_snapshots + snapshot_all + snapshot_restore ] ) diff --git a/hbase-shell/src/main/ruby/shell/commands/snapshot_all.rb b/hbase-shell/src/main/ruby/shell/commands/snapshot_all.rb new file mode 100644 index 0000000..3769c69 --- /dev/null +++ b/hbase-shell/src/main/ruby/shell/commands/snapshot_all.rb @@ -0,0 +1,63 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'time' + +module Shell + module Commands + class SnapshotAll < Command + def help + return <<-EOF +List all tables and take snapshot . +Optional regular expression parameter could be used to filter the output +by table name. + +Examples: + hbase> snapshot_all + hbase> snapshot_all 'abc.*' +EOF + end + + def command(regex = ".*") + now = Time.now.strftime("%Y%m%d") + + list = admin.list(regex) + list.each do |table| + ssName=table.dup + begin + ssName[":"]="_ns_sep_" + rescue + end + + ssName=ssName + "-ru-" + now + begin + admin.delete_snapshot(ssName) + rescue + end + begin + admin.snapshot(table, ssName) + rescue + end + formatter.row([ table ]) + end + + return list + end + end + end +end diff --git a/hbase-shell/src/main/ruby/shell/commands/snapshot_restore.rb b/hbase-shell/src/main/ruby/shell/commands/snapshot_restore.rb new file mode 100644 index 0000000..3d3ada4 --- /dev/null +++ b/hbase-shell/src/main/ruby/shell/commands/snapshot_restore.rb @@ -0,0 +1,67 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'time' + +module Shell + module Commands + class SnapshotRestore < Command + def help + return <<-EOF +Use snapshot to restore tables. +Date parameter (in the form YYYYmmdd) is used to filter the snapshots + +Examples: + hbase> snapshot_restore '20140917' +EOF + end + + def command(date) + now = Time.now.strftime("%Y-%d-%m") + suffix="-ru-" + date + + list = admin.list_snapshot(".*") + list.each do |snapshot| + ssName=snapshot.getName + if ssName.include? suffix + formatter.row([ ssName ]) + table=ssName.dup + begin + table["_ns_sep_"]=":" + rescue + end + begin + table[suffix]="" + rescue + end + + formatter.row([ "Restoring " + table + " from " + ssName ]) + begin + admin.disable(table) + admin.restore_snapshot(ssName) + admin.enable(table) + rescue + end + end + end + + return "Done" + end + end + end +end