HBASE-6353: Snapshots shell (Matteo Bertozzi)
git-svn-id: https://svn.apache.org/repos/asf/hbase/branches/hbase-7290@1445771 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5f1bc6e52e
commit
60e69c2410
|
@ -657,5 +657,40 @@ module Hbase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------
|
||||||
|
# Take a snapshot of specified table
|
||||||
|
def snapshot(table, snapshot_name)
|
||||||
|
@admin.snapshot(snapshot_name.to_java_bytes, table.to_java_bytes)
|
||||||
|
end
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------
|
||||||
|
# Restore specified snapshot
|
||||||
|
def restore_snapshot(snapshot_name)
|
||||||
|
@admin.restoreSnapshot(snapshot_name.to_java_bytes)
|
||||||
|
end
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------
|
||||||
|
# Create a new table by cloning the snapshot content
|
||||||
|
def clone_snapshot(snapshot_name, table)
|
||||||
|
@admin.cloneSnapshot(snapshot_name.to_java_bytes, table.to_java_bytes)
|
||||||
|
end
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------
|
||||||
|
# Rename specified snapshot
|
||||||
|
def rename_snapshot(old_snapshot_name, new_snapshot_name)
|
||||||
|
@admin.renameSnapshot(old_snapshot_name.to_java_bytes, new_snapshot_name.to_java_bytes)
|
||||||
|
end
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------
|
||||||
|
# Delete specified snapshot
|
||||||
|
def delete_snapshot(snapshot_name)
|
||||||
|
@admin.deleteSnapshot(snapshot_name.to_java_bytes)
|
||||||
|
end
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------
|
||||||
|
# Returns a list of snapshots
|
||||||
|
def list_snapshot
|
||||||
|
@admin.listSnapshots
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -408,14 +408,14 @@ EOF
|
||||||
# Generally used for admin functions which just have one name and take the table name
|
# Generally used for admin functions which just have one name and take the table name
|
||||||
def self.add_admin_utils(*args)
|
def self.add_admin_utils(*args)
|
||||||
args.each do |method|
|
args.each do |method|
|
||||||
define_method method do
|
define_method method do |*method_args|
|
||||||
@shell.command(method, @name)
|
@shell.command(method, @name, *method_args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#Add the following admin utilities to the table
|
#Add the following admin utilities to the table
|
||||||
add_admin_utils :enable, :disable, :flush, :drop, :describe
|
add_admin_utils :enable, :disable, :flush, :drop, :describe, :snapshot
|
||||||
|
|
||||||
#----------------------------
|
#----------------------------
|
||||||
#give the general help for the table
|
#give the general help for the table
|
||||||
|
|
|
@ -307,6 +307,19 @@ Shell.load_command_group(
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Shell.load_command_group(
|
||||||
|
'snapshot',
|
||||||
|
:full_name => 'CLUSTER SNAPSHOT TOOLS',
|
||||||
|
:commands => %w[
|
||||||
|
snapshot
|
||||||
|
clone_snapshot
|
||||||
|
restore_snapshot
|
||||||
|
rename_snapshot
|
||||||
|
delete_snapshot
|
||||||
|
list_snapshots
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
Shell.load_command_group(
|
Shell.load_command_group(
|
||||||
'security',
|
'security',
|
||||||
:full_name => 'SECURITY TOOLS',
|
:full_name => 'SECURITY TOOLS',
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
module Shell
|
||||||
|
module Commands
|
||||||
|
class CloneSnapshot < Command
|
||||||
|
def help
|
||||||
|
return <<-EOF
|
||||||
|
Create a new table by cloning the snapshot content. Examples:
|
||||||
|
There're no copies of data involved.
|
||||||
|
And writing on the newly created table will not influence the snapshot data.
|
||||||
|
|
||||||
|
hbase> clone_snapshot 'snapshotName', 'tableName'
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
def command(snapshot_name, table)
|
||||||
|
format_simple_command do
|
||||||
|
admin.clone_snapshot(snapshot_name, table)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,37 @@
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
module Shell
|
||||||
|
module Commands
|
||||||
|
class DeleteSnapshot < Command
|
||||||
|
def help
|
||||||
|
return <<-EOF
|
||||||
|
Delete a specified snapshot. Examples:
|
||||||
|
|
||||||
|
hbase> delete_snapshot 'snapshotName',
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
def command(snapshot_name)
|
||||||
|
format_simple_command do
|
||||||
|
admin.delete_snapshot(snapshot_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,51 @@
|
||||||
|
#
|
||||||
|
# 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 ListSnapshots < Command
|
||||||
|
def help
|
||||||
|
return <<-EOF
|
||||||
|
List all snapshots taken (by printing the names and relative information).
|
||||||
|
Optional regular expression parameter could be used to filter the output
|
||||||
|
by snapshot name.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
hbase> list_snapshots
|
||||||
|
hbase> list_snapshots 'abc.*'
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
def command(regex = ".*")
|
||||||
|
now = Time.now
|
||||||
|
formatter.header([ "SNAPSHOT", "TABLE + CREATION TIME"])
|
||||||
|
|
||||||
|
regex = /#{regex}/ unless regex.is_a?(Regexp)
|
||||||
|
list = admin.list_snapshot.select {|s| regex.match(s.getName)}
|
||||||
|
list.each do |snapshot|
|
||||||
|
creation_time = Time.at(snapshot.getCreationTime() / 1000).to_s
|
||||||
|
formatter.row([ snapshot.getName, snapshot.getTable + " (" + creation_time + ")" ])
|
||||||
|
end
|
||||||
|
|
||||||
|
formatter.footer(now, list.size)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,37 @@
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
module Shell
|
||||||
|
module Commands
|
||||||
|
class RenameSnapshot < Command
|
||||||
|
def help
|
||||||
|
return <<-EOF
|
||||||
|
Rename a specified snapshot. Examples:
|
||||||
|
|
||||||
|
hbase> rename_snapshot 'oldSnapshotName' 'newSnapshotName'
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
def command(old_snapshot_name, new_snapshot_name)
|
||||||
|
format_simple_command do
|
||||||
|
admin.rename_snapshot(old_snapshot_name, new_snapshot_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,41 @@
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
module Shell
|
||||||
|
module Commands
|
||||||
|
class RestoreSnapshot < Command
|
||||||
|
def help
|
||||||
|
return <<-EOF
|
||||||
|
Restore a specified snapshot.
|
||||||
|
The restore will replace the content of the original table,
|
||||||
|
bringing back the content to the snapshot state.
|
||||||
|
The table must be disabled.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
hbase> restore_snapshot 'snapshotName'
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
def command(snapshot_name)
|
||||||
|
format_simple_command do
|
||||||
|
admin.restore_snapshot(snapshot_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,37 @@
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
module Shell
|
||||||
|
module Commands
|
||||||
|
class Snapshot < Command
|
||||||
|
def help
|
||||||
|
return <<-EOF
|
||||||
|
Take a snapshot of specified table. Examples:
|
||||||
|
|
||||||
|
hbase> snapshot 'sourceTable', 'snapshotName'
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
|
||||||
|
def command(table, snapshot_name)
|
||||||
|
format_simple_command do
|
||||||
|
admin.snapshot(table, snapshot_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue