Skip to content

Commit ccd88f3

Browse files
author
Matteo Bertozzi
committedAug 12, 2012
hbase snapshot draft
1 parent 6dad178 commit ccd88f3

File tree

3 files changed

+8143
-0
lines changed

3 files changed

+8143
-0
lines changed
 

‎patches/hbase-snapshot/snapshot-protobuf-v0.patch

+6,060
Large diffs are not rendered by default.

‎patches/hbase-snapshot/snapshot-restore-v0.patch

+1,775
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
diff --git a/hbase-server/src/main/ruby/hbase/admin.rb b/hbase-server/src/main/ruby/hbase/admin.rb
2+
index 6239d52..1e9ad10 100644
3+
--- a/hbase-server/src/main/ruby/hbase/admin.rb
4+
+++ b/hbase-server/src/main/ruby/hbase/admin.rb
5+
@@ -643,5 +643,43 @@ module Hbase
6+
put.add(org.apache.hadoop.hbase.HConstants::CATALOG_FAMILY, org.apache.hadoop.hbase.HConstants::REGIONINFO_QUALIFIER, org.apache.hadoop.hbase.util.Writables.getBytes(hri))
7+
meta.put(put)
8+
end
9+
+
10+
+ #----------------------------------------------------------------------------------------------
11+
+ # Take a snapshot of specified table
12+
+ def snapshot(table, snapshot_name, snapshot_type=nil)
13+
+ if snapshot_type == 'global':
14+
+ @admin.globalSnapshot(snapshot_name.to_java_bytes, table.to_java_bytes)
15+
+ else
16+
+ @admin.snapshot(snapshot_name.to_java_bytes, table.to_java_bytes)
17+
+ end
18+
+ end
19+
+
20+
+ #----------------------------------------------------------------------------------------------
21+
+ # Restore specified snapshot
22+
+ def restore_snapshot(snapshot_name, table=nil)
23+
+ if table != nil
24+
+ @admin.restoreSnapshot(snapshot_name.to_java_bytes, table.to_java_bytes)
25+
+ else
26+
+ @admin.restoreSnapshot(snapshot_name.to_java_bytes)
27+
+ end
28+
+ end
29+
+
30+
+ #----------------------------------------------------------------------------------------------
31+
+ # Delete specified snapshot
32+
+ def rename_snapshot(old_snapshot_name, new_snapshot_name)
33+
+ @admin.renameSnapshot(old_snapshot_name.to_java_bytes, new_snapshot_name.to_java_bytes)
34+
+ end
35+
+
36+
+ #----------------------------------------------------------------------------------------------
37+
+ # Delete specified snapshot
38+
+ def delete_snapshot(snapshot_name)
39+
+ @admin.deleteSnapshot(snapshot_name.to_java_bytes)
40+
+ end
41+
+
42+
+ #----------------------------------------------------------------------------------------------
43+
+ # Returns a list of snapshots
44+
+ def list_snapshot
45+
+ @admin.listSnapshots.map { |s| s.getSnapshotNameAsString }
46+
+ end
47+
end
48+
end
49+
diff --git a/hbase-server/src/main/ruby/shell.rb b/hbase-server/src/main/ruby/shell.rb
50+
index d020969..820344b 100644
51+
--- a/hbase-server/src/main/ruby/shell.rb
52+
+++ b/hbase-server/src/main/ruby/shell.rb
53+
@@ -309,6 +309,18 @@ Shell.load_command_group(
54+
)
55+
56+
Shell.load_command_group(
57+
+ 'snapshot',
58+
+ :full_name => 'CLUSTER SNAPSHOT TOOLS',
59+
+ :commands => %w[
60+
+ snapshot
61+
+ restore_snapshot
62+
+ rename_snapshot
63+
+ delete_snapshot
64+
+ list_snapshots
65+
+ ]
66+
+)
67+
+
68+
+Shell.load_command_group(
69+
'security',
70+
:full_name => 'SECURITY TOOLS',
71+
:comment => "NOTE: Above commands are only applicable if running with the AccessController coprocessor",
72+
diff --git a/hbase-server/src/main/ruby/shell/commands/delete_snapshot.rb b/hbase-server/src/main/ruby/shell/commands/delete_snapshot.rb
73+
new file mode 100644
74+
index 0000000..acb7977
75+
--- /dev/null
76+
+++ b/hbase-server/src/main/ruby/shell/commands/delete_snapshot.rb
77+
@@ -0,0 +1,39 @@
78+
+#
79+
+# Copyright 2010 The Apache Software Foundation
80+
+#
81+
+# Licensed to the Apache Software Foundation (ASF) under one
82+
+# or more contributor license agreements. See the NOTICE file
83+
+# distributed with this work for additional information
84+
+# regarding copyright ownership. The ASF licenses this file
85+
+# to you under the Apache License, Version 2.0 (the
86+
+# "License"); you may not use this file except in compliance
87+
+# with the License. You may obtain a copy of the License at
88+
+#
89+
+# http://www.apache.org/licenses/LICENSE-2.0
90+
+#
91+
+# Unless required by applicable law or agreed to in writing, software
92+
+# distributed under the License is distributed on an "AS IS" BASIS,
93+
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
94+
+# See the License for the specific language governing permissions and
95+
+# limitations under the License.
96+
+#
97+
+
98+
+module Shell
99+
+ module Commands
100+
+ class DeleteSnapshot < Command
101+
+ def help
102+
+ return <<-EOF
103+
+Delete a specified snapshot. Examples:
104+
+
105+
+ hbase> delete_snapshot 'name',
106+
+EOF
107+
+ end
108+
+
109+
+ def command(snapshot_name)
110+
+ format_simple_command do
111+
+ admin.delete_snapshot(snapshot_name)
112+
+ end
113+
+ end
114+
+ end
115+
+ end
116+
+end
117+
diff --git a/hbase-server/src/main/ruby/shell/commands/list_snapshots.rb b/hbase-server/src/main/ruby/shell/commands/list_snapshots.rb
118+
new file mode 100644
119+
index 0000000..9ab57f1
120+
--- /dev/null
121+
+++ b/hbase-server/src/main/ruby/shell/commands/list_snapshots.rb
122+
@@ -0,0 +1,48 @@
123+
+#
124+
+# Copyright 2010 The Apache Software Foundation
125+
+#
126+
+# Licensed to the Apache Software Foundation (ASF) under one
127+
+# or more contributor license agreements. See the NOTICE file
128+
+# distributed with this work for additional information
129+
+# regarding copyright ownership. The ASF licenses this file
130+
+# to you under the Apache License, Version 2.0 (the
131+
+# "License"); you may not use this file except in compliance
132+
+# with the License. You may obtain a copy of the License at
133+
+#
134+
+# http://www.apache.org/licenses/LICENSE-2.0
135+
+#
136+
+# Unless required by applicable law or agreed to in writing, software
137+
+# distributed under the License is distributed on an "AS IS" BASIS,
138+
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139+
+# See the License for the specific language governing permissions and
140+
+# limitations under the License.
141+
+#
142+
+
143+
+module Shell
144+
+ module Commands
145+
+ class ListSnapshots < Command
146+
+ def help
147+
+ return <<-EOF
148+
+List all snapshots taken. Optional regular expression parameter could
149+
+be used to filter the output. Examples:
150+
+
151+
+ hbase> list_snapshots
152+
+ hbase> list_snapshots 'abc.*'
153+
+EOF
154+
+ end
155+
+
156+
+ def command(regex = ".*")
157+
+ now = Time.now
158+
+ formatter.header([ "SNAPSHOT" ])
159+
+
160+
+ regex = /#{regex}/ unless regex.is_a?(Regexp)
161+
+ list = admin.list_snapshot.grep(regex)
162+
+ list.each do |snapshot|
163+
+ formatter.row([ snapshot ])
164+
+ end
165+
+
166+
+ formatter.footer(now, list.size)
167+
+ end
168+
+ end
169+
+ end
170+
+end
171+
diff --git a/hbase-server/src/main/ruby/shell/commands/rename_snapshot.rb b/hbase-server/src/main/ruby/shell/commands/rename_snapshot.rb
172+
new file mode 100644
173+
index 0000000..a84d5f0
174+
--- /dev/null
175+
+++ b/hbase-server/src/main/ruby/shell/commands/rename_snapshot.rb
176+
@@ -0,0 +1,39 @@
177+
+#
178+
+# Copyright 2010 The Apache Software Foundation
179+
+#
180+
+# Licensed to the Apache Software Foundation (ASF) under one
181+
+# or more contributor license agreements. See the NOTICE file
182+
+# distributed with this work for additional information
183+
+# regarding copyright ownership. The ASF licenses this file
184+
+# to you under the Apache License, Version 2.0 (the
185+
+# "License"); you may not use this file except in compliance
186+
+# with the License. You may obtain a copy of the License at
187+
+#
188+
+# http://www.apache.org/licenses/LICENSE-2.0
189+
+#
190+
+# Unless required by applicable law or agreed to in writing, software
191+
+# distributed under the License is distributed on an "AS IS" BASIS,
192+
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
193+
+# See the License for the specific language governing permissions and
194+
+# limitations under the License.
195+
+#
196+
+
197+
+module Shell
198+
+ module Commands
199+
+ class RenameSnapshot < Command
200+
+ def help
201+
+ return <<-EOF
202+
+Rename a specified snapshot. Examples:
203+
+
204+
+ hbase> rename_snapshot 'old_snapshot_name' 'new_snapshot_name'
205+
+EOF
206+
+ end
207+
+
208+
+ def command(old_snapshot_name, new_snapshot_name)
209+
+ format_simple_command do
210+
+ admin.rename_snapshot(old_snapshot_name, new_snapshot_name)
211+
+ end
212+
+ end
213+
+ end
214+
+ end
215+
+end
216+
diff --git a/hbase-server/src/main/ruby/shell/commands/restore_snapshot.rb b/hbase-server/src/main/ruby/shell/commands/restore_snapshot.rb
217+
new file mode 100644
218+
index 0000000..554e761
219+
--- /dev/null
220+
+++ b/hbase-server/src/main/ruby/shell/commands/restore_snapshot.rb
221+
@@ -0,0 +1,40 @@
222+
+#
223+
+# Copyright 2010 The Apache Software Foundation
224+
+#
225+
+# Licensed to the Apache Software Foundation (ASF) under one
226+
+# or more contributor license agreements. See the NOTICE file
227+
+# distributed with this work for additional information
228+
+# regarding copyright ownership. The ASF licenses this file
229+
+# to you under the Apache License, Version 2.0 (the
230+
+# "License"); you may not use this file except in compliance
231+
+# with the License. You may obtain a copy of the License at
232+
+#
233+
+# http://www.apache.org/licenses/LICENSE-2.0
234+
+#
235+
+# Unless required by applicable law or agreed to in writing, software
236+
+# distributed under the License is distributed on an "AS IS" BASIS,
237+
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
238+
+# See the License for the specific language governing permissions and
239+
+# limitations under the License.
240+
+#
241+
+
242+
+module Shell
243+
+ module Commands
244+
+ class RestoreSnapshot < Command
245+
+ def help
246+
+ return <<-EOF
247+
+Restore a specified snapshot. Examples:
248+
+
249+
+ hbase> restore_snapshot 'name'
250+
+ hbase> restore_snapshot 'name', 'tableName'
251+
+EOF
252+
+ end
253+
+
254+
+ def command(snapshot_name, table=nil)
255+
+ format_simple_command do
256+
+ admin.restore_snapshot(snapshot_name, table)
257+
+ end
258+
+ end
259+
+ end
260+
+ end
261+
+end
262+
diff --git a/hbase-server/src/main/ruby/shell/commands/snapshot.rb b/hbase-server/src/main/ruby/shell/commands/snapshot.rb
263+
new file mode 100644
264+
index 0000000..30a1504
265+
--- /dev/null
266+
+++ b/hbase-server/src/main/ruby/shell/commands/snapshot.rb
267+
@@ -0,0 +1,41 @@
268+
+#
269+
+# Copyright 2010 The Apache Software Foundation
270+
+#
271+
+# Licensed to the Apache Software Foundation (ASF) under one
272+
+# or more contributor license agreements. See the NOTICE file
273+
+# distributed with this work for additional information
274+
+# regarding copyright ownership. The ASF licenses this file
275+
+# to you under the Apache License, Version 2.0 (the
276+
+# "License"); you may not use this file except in compliance
277+
+# with the License. You may obtain a copy of the License at
278+
+#
279+
+# http://www.apache.org/licenses/LICENSE-2.0
280+
+#
281+
+# Unless required by applicable law or agreed to in writing, software
282+
+# distributed under the License is distributed on an "AS IS" BASIS,
283+
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
284+
+# See the License for the specific language governing permissions and
285+
+# limitations under the License.
286+
+#
287+
+
288+
+module Shell
289+
+ module Commands
290+
+ class Snapshot < Command
291+
+ def help
292+
+ return <<-EOF
293+
+Take a snapshot of specified table. Examples:
294+
+
295+
+ hbase> snapshot 't1', 'my-snapshot'
296+
+ hbase> snapshot 't1', 'my-snapshot', 'global'
297+
+EOF
298+
+ end
299+
+
300+
+ def command(table, snapshot_name, snapshot_type=nil)
301+
+ format_simple_command do
302+
+ admin.snapshot(table, snapshot_name, snapshot_type)
303+
+ formatter.row(["created snapshot " + snapshot_name])
304+
+ end
305+
+ end
306+
+ end
307+
+ end
308+
+end

0 commit comments

Comments
 (0)
Please sign in to comment.