es_dump_restore 0.0.13 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/es_dump_restore/app.rb +18 -0
- data/lib/es_dump_restore/es_client.rb +42 -4
- data/lib/es_dump_restore/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c543de6aac0bbd4e8380b4fdf8b9f995c2ff33c
|
4
|
+
data.tar.gz: eb25e1154138dba1bb53c71080190c9a3d57a7c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5af4422476d43ff85ea997463162703f4c4d214cd617517ea4ca9950c9ef24c06367b7fa8eeeadc0acc683f0ee1ab352d250c969ae8eef3263a5b9ce9e94533c
|
7
|
+
data.tar.gz: 6707141cbeae98732da6dd62d786f6c2ba2c09879f29a5b9c027559f73dca4ac588d50b7c68af71060f541a4ae7e62683633f92ddfa61a29fcf625cd340f458d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# Version 1.0.0 - April 11, 2015
|
2
|
+
|
3
|
+
* Add a `restore_alias` command, which performs a restore and switches an alias to point at the result (thanks Richard Boulton!)
|
4
|
+
* Fixes a bug preventing index restoration on newer ES releases (thanks again Richard Boulton!)
|
5
|
+
* Richard Boulton tells us he's used `es_dump_restore` to perform a migration on the www.gov.uk indexes, so we think it's high time we started calling this tool ready for prime time. Announcing 1.0.0!
|
6
|
+
|
1
7
|
# Version 0.0.13 - April 10, 2015
|
2
8
|
|
3
9
|
* Fix a regression introduced for ES version 0.90.x by the previous release (thanks again Richard Boulton!)
|
data/lib/es_dump_restore/app.rb
CHANGED
@@ -75,5 +75,23 @@ module EsDumpRestore
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
desc "restore_alias URL ALIAS_NAME INDEX_NAME FILENAME", "Restores a dumpfile into the given ElasticSearch index, and then sets the alias to point at that index, removing any existing indexes pointed at by the alias"
|
79
|
+
def restore_alias(url, alias_name, index_name, filename)
|
80
|
+
client = EsClient.new(url, index_name, nil)
|
81
|
+
client.check_alias alias_name
|
82
|
+
|
83
|
+
Dumpfile.read(filename) do |dumpfile|
|
84
|
+
client.create_index(dumpfile.index)
|
85
|
+
|
86
|
+
bar = ProgressBar.new(dumpfile.num_objects) unless options[:noprogressbar]
|
87
|
+
dumpfile.scan_objects(1000) do |batch, size|
|
88
|
+
client.bulk_index batch
|
89
|
+
bar.increment!(size) unless options[:noprogressbar]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
client.replace_alias_and_close_old_index alias_name
|
94
|
+
end
|
95
|
+
|
78
96
|
end
|
79
97
|
end
|
@@ -74,11 +74,50 @@ module EsDumpRestore
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def create_index(metadata)
|
77
|
-
request(:post, "", :body => MultiJson.dump(metadata))
|
77
|
+
request(:post, "#{@path_prefix}", :body => MultiJson.dump(metadata))
|
78
|
+
end
|
79
|
+
|
80
|
+
def check_alias(alias_name)
|
81
|
+
# Checks that it's possible to do an atomic restore using the given alias
|
82
|
+
# name. This requires that:
|
83
|
+
# - `alias_name` doesn't point to an existing index
|
84
|
+
# - `index_name` doesn't point to an existing index
|
85
|
+
existing = request(:get, "_aliases")
|
86
|
+
if existing.include? index_name
|
87
|
+
raise "There is already an index called #{index_name}"
|
88
|
+
end
|
89
|
+
if existing.include? alias_name
|
90
|
+
raise "There is already an index called #{alias_name}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def replace_alias_and_close_old_index(alias_name)
|
95
|
+
existing = request(:get, "_aliases")
|
96
|
+
|
97
|
+
# Response of the form:
|
98
|
+
# { "index_name" => { "aliases" => { "a1" => {}, "a2" => {} } } }
|
99
|
+
old_aliased_indices = existing.select { |name, details|
|
100
|
+
details.fetch("aliases", {}).keys.include? alias_name
|
101
|
+
}
|
102
|
+
old_aliased_indices = old_aliased_indices.keys
|
103
|
+
|
104
|
+
# For any existing indices with this alias, remove the alias
|
105
|
+
# We would normally expect 0 or 1 such index, but several is
|
106
|
+
# valid too
|
107
|
+
actions = old_aliased_indices.map { |old_index_name|
|
108
|
+
{ "remove" => { "index" => old_index_name, "alias" => alias_name } }
|
109
|
+
}
|
110
|
+
|
111
|
+
actions << { "add" => { "index" => index_name, "alias" => alias_name } }
|
112
|
+
|
113
|
+
request(:post, "_aliases", :body => MultiJson.dump({ "actions" => actions }))
|
114
|
+
old_aliased_indices.each do |old_index_name|
|
115
|
+
request(:post, "#{old_index_name}/_close")
|
116
|
+
end
|
78
117
|
end
|
79
118
|
|
80
119
|
def bulk_index(data)
|
81
|
-
request(:post, "_bulk", :body => data)
|
120
|
+
request(:post, "#{@path_prefix}/_bulk", :body => data)
|
82
121
|
end
|
83
122
|
|
84
123
|
private
|
@@ -88,12 +127,11 @@ module EsDumpRestore
|
|
88
127
|
begin
|
89
128
|
response = @httpclient.request(method, request_uri, options)
|
90
129
|
unless response.ok? or extra_allowed_exitcodes.include? response.status
|
91
|
-
raise "Request failed with status #{response.status}: #{response.reason}"
|
130
|
+
raise "Request failed with status #{response.status}: #{response.reason} #{response.content}"
|
92
131
|
end
|
93
132
|
MultiJson.load(response.content)
|
94
133
|
rescue Exception => e
|
95
134
|
puts "Exception caught issuing HTTP request to #{request_uri}"
|
96
|
-
puts "options: #{options}"
|
97
135
|
raise e
|
98
136
|
end
|
99
137
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: es_dump_restore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nat Budin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|