es_dump_restore 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c543de6aac0bbd4e8380b4fdf8b9f995c2ff33c
4
- data.tar.gz: eb25e1154138dba1bb53c71080190c9a3d57a7c2
3
+ metadata.gz: 26b95784a5cbe09598686a716498b43feb08e905
4
+ data.tar.gz: fc3451f6a37dda8116891bb9daa09291faaaf485
5
5
  SHA512:
6
- metadata.gz: 5af4422476d43ff85ea997463162703f4c4d214cd617517ea4ca9950c9ef24c06367b7fa8eeeadc0acc683f0ee1ab352d250c969ae8eef3263a5b9ce9e94533c
7
- data.tar.gz: 6707141cbeae98732da6dd62d786f6c2ba2c09879f29a5b9c027559f73dca4ac588d50b7c68af71060f541a4ae7e62683633f92ddfa61a29fcf625cd340f458d
6
+ metadata.gz: dd7c79f8d006bd3ab5ac8818ab5a86b8a9d81bd9e2819b17d7d42a45cd8347d96d15b6e2bcb3d5ff880db9431c87d25e9223d9e654b1dadee55029bfd7f18db4
7
+ data.tar.gz: db90aeae9f731d02009f9cd857708cd6eac25ac135db5558adcf47cdea4bb3e73d37b89a39b44a463f7fa3fc113519854470719c3f36606e1385615284595361
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # Version 1.1.0 - May 12, 2015
2
+
3
+ * Allow specifying additional index settings to the `restore` and `restore_alias` commands (thanks again Richard Boulton!)
4
+
1
5
  # Version 1.0.0 - April 11, 2015
2
6
 
3
7
  * Add a `restore_alias` command, which performs a restore and switches an alias to point at the result (thanks Richard Boulton!)
data/README.md CHANGED
@@ -23,7 +23,30 @@ To dump an ElasticSearch index by type to a file:
23
23
 
24
24
  To restore an index to an ElasticSearch server:
25
25
 
26
- es_dump_restore restore ELASTIC_SEARCH_SERVER_URL DESTINATON_INDEX FILENAME_ZIP
26
+ es_dump_restore restore ELASTIC_SEARCH_SERVER_URL DESTINATION_INDEX FILENAME_ZIP [SETTING_OVERRIDES]
27
+
28
+ To restore an index and set an alias to point to it:
29
+
30
+ es_dump_restore restore_alias ELASTIC_SEARCH_SERVER_URL DESTINATION_ALIAS DESTINATION_INDEX FILENAME_ZIP [SETTING_OVERRIDES]
31
+
32
+ This loads the dump into an index named `DESTINATION_INDEX`, and once the load
33
+ is complete sets the alias `DESTINATION_ALIAS` to point to it. If
34
+ `DESTINATION_ALIAS` already exists, it will be atomically changed to point to
35
+ the new location. This allows a dump file to be loaded on a running server
36
+ without disrupting searches going on on that server (as long as those searches
37
+ are accessing the index via the alias).
38
+
39
+ If `SETTING_OVERRIDES` is set for a restore command, it must be a valid
40
+ serialised JSON object. This will be merged with the settings in the dump
41
+ file, allowing selected settings to be altered, but keeping any unspecified
42
+ settings as they were in the dump file. For example:
43
+
44
+ es_dump_restore restore_alias http://localhost:9200 test test-1276512 test_dump.zip '{"settings":{"index":{"number_of_replicas":"0","number_of_shards":"1"}}'
45
+
46
+ would read the dump file `test_dump.zip`, load it into an index called
47
+ `test-1276512`, then set the alias `test` to point to this index. The index
48
+ would be set to have no replicas, and only 1 shard, but have all other settings
49
+ from the dump file.
27
50
 
28
51
  ## Contributing
29
52
 
@@ -61,11 +61,11 @@ module EsDumpRestore
61
61
  end
62
62
 
63
63
  desc "restore URL INDEX_NAME FILENAME", "Restores a dumpfile into the given ElasticSearch index"
64
- def restore(url, index_name, filename)
64
+ def restore(url, index_name, filename, overrides=nil)
65
65
  client = EsClient.new(url, index_name, nil)
66
66
 
67
67
  Dumpfile.read(filename) do |dumpfile|
68
- client.create_index(dumpfile.index)
68
+ client.create_index(dumpfile.index, overrides)
69
69
 
70
70
  bar = ProgressBar.new(dumpfile.num_objects) unless options[:noprogressbar]
71
71
  dumpfile.scan_objects(1000) do |batch, size|
@@ -76,12 +76,12 @@ module EsDumpRestore
76
76
  end
77
77
 
78
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)
79
+ def restore_alias(url, alias_name, index_name, filename, overrides=nil)
80
80
  client = EsClient.new(url, index_name, nil)
81
81
  client.check_alias alias_name
82
82
 
83
83
  Dumpfile.read(filename) do |dumpfile|
84
- client.create_index(dumpfile.index)
84
+ client.create_index(dumpfile.index, overrides)
85
85
 
86
86
  bar = ProgressBar.new(dumpfile.num_objects) unless options[:noprogressbar]
87
87
  dumpfile.scan_objects(1000) do |batch, size|
@@ -73,7 +73,11 @@ module EsDumpRestore
73
73
  end
74
74
  end
75
75
 
76
- def create_index(metadata)
76
+ def create_index(metadata, overrides)
77
+ if overrides
78
+ overrides = MultiJson.load(overrides)
79
+ metadata = deep_merge(metadata, overrides)
80
+ end
77
81
  request(:post, "#{@path_prefix}", :body => MultiJson.dump(metadata))
78
82
  end
79
83
 
@@ -135,5 +139,16 @@ module EsDumpRestore
135
139
  raise e
136
140
  end
137
141
  end
142
+
143
+ def deep_merge(hash1, hash2)
144
+ merger = proc { |key, v1, v2|
145
+ if Hash === v1 && Hash === v2
146
+ v1.merge(v2, &merger)
147
+ else
148
+ v2
149
+ end
150
+ }
151
+ hash1.merge(hash2, &merger)
152
+ end
138
153
  end
139
154
  end
@@ -1,3 +1,3 @@
1
1
  module EsDumpRestore
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  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: 1.0.0
4
+ version: 1.1.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 00:00:00.000000000 Z
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  requirements: []
137
137
  rubyforge_project:
138
- rubygems_version: 2.2.2
138
+ rubygems_version: 2.4.5
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: Dump ElasticSearch indexes to files and restore them back