Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/reference/modules/snapshots.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,24 @@ restore such indices by setting `partial` to `true`. Please note, that only succ
restored in this case and all missing shards will be recreated empty.


[float]
=== Changing index settings during restore

Most of index settings can be overridden during the restore process. For example, the following command will restore
the index `index_1` without creating any replicas while switching back to default refresh interval:

[source,js]
-----------------------------------
$ curl -XPOST "localhost:9200/_snapshot/my_backup/snapshot_1/_restore" -d '{
"indices": "index_1",
"index_settings" : {
"index.number_of_replicas": 0
},
"ignore_index_settings": ["index.refresh_interval"]
}'
-----------------------------------


[float]
=== Snapshot status

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public class RestoreSnapshotRequest extends MasterNodeOperationRequest<RestoreSn

private Settings settings = EMPTY_SETTINGS;

private Settings indexSettings = EMPTY_SETTINGS;

private String[] ignoreIndexSettings = Strings.EMPTY_ARRAY;

RestoreSnapshotRequest() {
}

Expand Down Expand Up @@ -106,7 +110,12 @@ public ActionRequestValidationException validate() {
if (settings == null) {
validationException = addValidationError("settings are missing", validationException);
}

if (indexSettings == null) {
validationException = addValidationError("indexSettings are missing", validationException);
}
if (ignoreIndexSettings == null) {
validationException = addValidationError("ignoreIndexSettings are missing", validationException);
}
return validationException;
}

Expand Down Expand Up @@ -364,6 +373,29 @@ public Settings settings() {
return this.settings;
}

/**
* Sets the list of index settings and index settings groups that shouldn't be restored from snapshot
*/
public RestoreSnapshotRequest ignoreIndexSettings(String... ignoreIndexSettings) {
this.ignoreIndexSettings = ignoreIndexSettings;
return this;
}

/**
* Sets the list of index settings and index settings groups that shouldn't be restored from snapshot
*/
public RestoreSnapshotRequest ignoreIndexSettings(List<String> ignoreIndexSettings) {
this.ignoreIndexSettings = ignoreIndexSettings.toArray(new String[ignoreIndexSettings.size()]);
return this;
}

/**
* Returns the list of index settings and index settings groups that shouldn't be restored from snapshot
*/
public String[] ignoreIndexSettings() {
return ignoreIndexSettings;
}

/**
* If set to true the restore procedure will restore global cluster state.
* <p/>
Expand Down Expand Up @@ -406,6 +438,51 @@ public boolean includeAliases() {
return includeAliases;
}

/**
* Sets settings that should be added/changed in all restored indices
*/
public RestoreSnapshotRequest indexSettings(Settings settings) {
this.indexSettings = settings;
return this;
}

/**
* Sets settings that should be added/changed in all restored indices
*/
public RestoreSnapshotRequest indexSettings(Settings.Builder settings) {
this.indexSettings = settings.build();
return this;
}

/**
* Sets settings that should be added/changed in all restored indices
*/
public RestoreSnapshotRequest indexSettings(String source) {
this.indexSettings = ImmutableSettings.settingsBuilder().loadFromSource(source).build();
return this;
}

/**
* Sets settings that should be added/changed in all restored indices
*/
public RestoreSnapshotRequest indexSettings(Map<String, Object> source) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
indexSettings(builder.string());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
return this;
}

/**
* Returns settings that should be added/changed in all restored indices
*/
public Settings indexSettings() {
return this.indexSettings;
}

/**
* Parses restore definition
*
Expand Down Expand Up @@ -454,7 +531,7 @@ public RestoreSnapshotRequest source(Map source) {
partial(nodeBooleanValue(entry.getValue()));
} else if (name.equals("settings")) {
if (!(entry.getValue() instanceof Map)) {
throw new ElasticsearchIllegalArgumentException("malformed settings section, should indices an inner object");
throw new ElasticsearchIllegalArgumentException("malformed settings section");
}
settings((Map<String, Object>) entry.getValue());
} else if (name.equals("include_global_state")) {
Expand All @@ -473,6 +550,19 @@ public RestoreSnapshotRequest source(Map source) {
} else {
throw new ElasticsearchIllegalArgumentException("malformed rename_replacement");
}
} else if (name.equals("index_settings")) {
if (!(entry.getValue() instanceof Map)) {
throw new ElasticsearchIllegalArgumentException("malformed index_settings section");
}
indexSettings((Map<String, Object>) entry.getValue());
} else if (name.equals("ignore_index_settings")) {
if (entry.getValue() instanceof String) {
ignoreIndexSettings(Strings.splitStringByCommaToArray((String) entry.getValue()));
} else if (entry.getValue() instanceof List) {
ignoreIndexSettings((List<String>) entry.getValue());
} else {
throw new ElasticsearchIllegalArgumentException("malformed ignore_index_settings section, should be an array of strings");
}
} else {
throw new ElasticsearchIllegalArgumentException("Unknown parameter " + name);
}
Expand Down Expand Up @@ -563,6 +653,10 @@ public void readFrom(StreamInput in) throws IOException {
partial = in.readBoolean();
includeAliases = in.readBoolean();
settings = readSettingsFromStream(in);
if (in.getVersion().onOrAfter(Version.V_1_5_0)) {
indexSettings = readSettingsFromStream(in);
ignoreIndexSettings = in.readStringArray();
}
}

@Override
Expand All @@ -579,5 +673,9 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(partial);
out.writeBoolean(includeAliases);
writeSettingsToStream(settings, out);
if (out.getVersion().onOrAfter(Version.V_1_5_0)) {
writeSettingsToStream(indexSettings, out);
out.writeStringArray(ignoreIndexSettings);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.elasticsearch.client.ClusterAdminClient;
import org.elasticsearch.common.settings.Settings;

import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -230,6 +231,68 @@ public RestoreSnapshotRequestBuilder setIncludeAliases(boolean restoreAliases) {
return this;
}

/**
* Sets index settings that should be added or replaced during restore

* @param settings index settings
* @return this builder
*/
public RestoreSnapshotRequestBuilder setIndexSettings(Settings settings) {
request.indexSettings(settings);
return this;
}

/**
* Sets index settings that should be added or replaced during restore

* @param settings index settings
* @return this builder
*/
public RestoreSnapshotRequestBuilder setIndexSettings(Settings.Builder settings) {
request.indexSettings(settings);
return this;
}

/**
* Sets index settings that should be added or replaced during restore

* @param source index settings
* @return this builder
*/
public RestoreSnapshotRequestBuilder setIndexSettings(String source) {
request.indexSettings(source);
return this;
}

/**
* Sets index settings that should be added or replaced during restore

* @param source index settings
* @return this builder
*/
public RestoreSnapshotRequestBuilder setIndexSettings(Map<String, Object> source) {
request.indexSettings(source);
return this;
}


/**
* Sets the list of index settings and index settings groups that shouldn't be restored from snapshot
*/
public RestoreSnapshotRequestBuilder setIgnoreIndexSettings(String... ignoreIndexSettings) {
request.ignoreIndexSettings(ignoreIndexSettings);
return this;
}

/**
* Sets the list of index settings and index settings groups that shouldn't be restored from snapshot
*/
public RestoreSnapshotRequestBuilder setIgnoreIndexSettings(List<String> ignoreIndexSettings) {
request.ignoreIndexSettings(ignoreIndexSettings);
return this;
}


@Override
protected void doExecute(ActionListener<RestoreSnapshotResponse> listener) {
client.restoreSnapshot(request, listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ protected void masterOperation(final RestoreSnapshotRequest request, ClusterStat
RestoreService.RestoreRequest restoreRequest = new RestoreService.RestoreRequest(
"restore_snapshot[" + request.snapshot() + "]", request.repository(), request.snapshot(),
request.indices(), request.indicesOptions(), request.renamePattern(), request.renameReplacement(),
request.settings(), request.masterNodeTimeout(), request.includeGlobalState(), request.partial(), request.includeAliases());
request.settings(), request.masterNodeTimeout(), request.includeGlobalState(), request.partial(), request.includeAliases(),
request.indexSettings(), request.ignoreIndexSettings());

restoreService.restoreSnapshot(restoreRequest, new ActionListener<RestoreInfo>() {
@Override
Expand Down
Loading