restore

package
v9.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Restore a snapshot. Restore a snapshot of a cluster or data streams and indices.

You can restore a snapshot only to a running cluster with an elected master node. The snapshot repository must be registered and available to the cluster. The snapshot and cluster versions must be compatible.

To restore a snapshot, the cluster's global metadata must be writable. Ensure there are't any cluster blocks that prevent writes. The restore operation ignores index blocks.

Before you restore a data stream, ensure the cluster contains a matching index template with data streams enabled. To check, use the index management feature in Kibana or the get index template API:

``` GET _index_template/*?filter_path=index_templates.name,index_templates.index_template.index_patterns,index_templates.index_template.data_stream ```

If no such template exists, you can create one or restore a cluster state that contains one. Without a matching index template, a data stream can't roll over or create backing indices.

If your snapshot contains data from App Search or Workplace Search, you must restore the Enterprise Search encryption key before you restore the snapshot.

Index

Constants

This section is empty.

Variables

View Source
var ErrBuildPath = errors.New("cannot build path, check for missing path parameters")

ErrBuildPath is returned in case of missing parameters within the build of the request.

Functions

This section is empty.

Types

type NewRestore

type NewRestore func(repository, snapshot string) *Restore

NewRestore type alias for index.

func NewRestoreFunc

func NewRestoreFunc(tp elastictransport.Interface) NewRestore

NewRestoreFunc returns a new instance of Restore with the provided transport. Used in the index of the library this allows to retrieve every apis in once place.

type Request

type Request struct {

	// FeatureStates The feature states to restore.
	// If `include_global_state` is `true`, the request restores all feature states
	// in the snapshot by default.
	// If `include_global_state` is `false`, the request restores no feature states
	// by default.
	// Note that specifying an empty array will result in the default behavior.
	// To restore no feature states, regardless of the `include_global_state` value,
	// specify an array containing only the value `none` (`["none"]`).
	FeatureStates []string `json:"feature_states,omitempty"`
	// IgnoreIndexSettings The index settings to not restore from the snapshot.
	// You can't use this option to ignore `index.number_of_shards`.
	//
	// For data streams, this option applies only to restored backing indices.
	// New backing indices are configured using the data stream's matching index
	// template.
	IgnoreIndexSettings []string `json:"ignore_index_settings,omitempty"`
	// IgnoreUnavailable If `true`, the request ignores any index or data stream in indices that's
	// missing from the snapshot.
	// If `false`, the request returns an error for any missing index or data
	// stream.
	IgnoreUnavailable *bool `json:"ignore_unavailable,omitempty"`
	// IncludeAliases If `true`, the request restores aliases for any restored data streams and
	// indices.
	// If `false`, the request doesn’t restore aliases.
	IncludeAliases *bool `json:"include_aliases,omitempty"`
	// IncludeGlobalState If `true`, restore the cluster state. The cluster state includes:
	//
	// * Persistent cluster settings
	// * Index templates
	// * Legacy index templates
	// * Ingest pipelines
	// * Index lifecycle management (ILM) policies
	// * Stored scripts
	// * For snapshots taken after 7.12.0, feature states
	//
	// If `include_global_state` is `true`, the restore operation merges the legacy
	// index templates in your cluster with the templates contained in the snapshot,
	// replacing any existing ones whose name matches one in the snapshot.
	// It completely removes all persistent settings, non-legacy index templates,
	// ingest pipelines, and ILM lifecycle policies that exist in your cluster and
	// replaces them with the corresponding items from the snapshot.
	//
	// Use the `feature_states` parameter to configure how feature states are
	// restored.
	//
	// If `include_global_state` is `true` and a snapshot was created without a
	// global state then the restore request will fail.
	IncludeGlobalState *bool `json:"include_global_state,omitempty"`
	// IndexSettings Index settings to add or change in restored indices, including backing
	// indices.
	// You can't use this option to change `index.number_of_shards`.
	//
	// For data streams, this option applies only to restored backing indices.
	// New backing indices are configured using the data stream's matching index
	// template.
	IndexSettings *types.IndexSettings `json:"index_settings,omitempty"`
	// Indices A comma-separated list of indices and data streams to restore.
	// It supports a multi-target syntax.
	// The default behavior is all regular indices and regular data streams in the
	// snapshot.
	//
	// You can't use this parameter to restore system indices or system data
	// streams.
	// Use `feature_states` instead.
	Indices []string `json:"indices,omitempty"`
	// Partial If `false`, the entire restore operation will fail if one or more indices
	// included in the snapshot do not have all primary shards available.
	//
	// If true, it allows restoring a partial snapshot of indices with unavailable
	// shards.
	// Only shards that were successfully included in the snapshot will be restored.
	// All missing shards will be recreated as empty.
	Partial *bool `json:"partial,omitempty"`
	// RenamePattern A rename pattern to apply to restored data streams and indices.
	// Data streams and indices matching the rename pattern will be renamed
	// according to `rename_replacement`.
	//
	// The rename pattern is applied as defined by the regular expression that
	// supports referencing the original text, according to the `appendReplacement`
	// logic.
	RenamePattern *string `json:"rename_pattern,omitempty"`
	// RenameReplacement The rename replacement string that is used with the `rename_pattern`.
	RenameReplacement *string `json:"rename_replacement,omitempty"`
}

Request holds the request body struct for the package restore

https://github.com/elastic/elasticsearch-specification/blob/907d11a72a6bfd37b777d526880c56202889609e/specification/snapshot/restore/SnapshotRestoreRequest.ts#L25-L175

func NewRequest

func NewRequest() *Request

NewRequest returns a Request

func (*Request) FromJSON

func (r *Request) FromJSON(data string) (*Request, error)

FromJSON allows to load an arbitrary json into the request structure

func (*Request) UnmarshalJSON

func (s *Request) UnmarshalJSON(data []byte) error

type Response

type Response struct {
	Accepted *bool                  `json:"accepted,omitempty"`
	Snapshot *types.SnapshotRestore `json:"snapshot,omitempty"`
}

Response holds the response body struct for the package restore

https://github.com/elastic/elasticsearch-specification/blob/907d11a72a6bfd37b777d526880c56202889609e/specification/snapshot/restore/SnapshotRestoreResponse.ts#L23-L28

func NewResponse

func NewResponse() *Response

NewResponse returns a Response

type Restore

type Restore struct {
	// contains filtered or unexported fields
}

func New

Restore a snapshot. Restore a snapshot of a cluster or data streams and indices.

You can restore a snapshot only to a running cluster with an elected master node. The snapshot repository must be registered and available to the cluster. The snapshot and cluster versions must be compatible.

To restore a snapshot, the cluster's global metadata must be writable. Ensure there are't any cluster blocks that prevent writes. The restore operation ignores index blocks.

Before you restore a data stream, ensure the cluster contains a matching index template with data streams enabled. To check, use the index management feature in Kibana or the get index template API:

``` GET _index_template/*?filter_path=index_templates.name,index_templates.index_template.index_patterns,index_templates.index_template.data_stream ```

If no such template exists, you can create one or restore a cluster state that contains one. Without a matching index template, a data stream can't roll over or create backing indices.

If your snapshot contains data from App Search or Workplace Search, you must restore the Enterprise Search encryption key before you restore the snapshot.

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-snapshot-restore

func (Restore) Do

func (r Restore) Do(providedCtx context.Context) (*Response, error)

Do runs the request through the transport, handle the response and returns a restore.Response

func (*Restore) ErrorTrace

func (r *Restore) ErrorTrace(errortrace bool) *Restore

ErrorTrace When set to `true` Elasticsearch will include the full stack trace of errors when they occur. API name: error_trace

func (*Restore) FeatureStates

func (r *Restore) FeatureStates(featurestates ...string) *Restore

The feature states to restore. If `include_global_state` is `true`, the request restores all feature states in the snapshot by default. If `include_global_state` is `false`, the request restores no feature states by default. Note that specifying an empty array will result in the default behavior. To restore no feature states, regardless of the `include_global_state` value, specify an array containing only the value `none` (`["none"]`). API name: feature_states

func (*Restore) FilterPath

func (r *Restore) FilterPath(filterpaths ...string) *Restore

FilterPath Comma-separated list of filters in dot notation which reduce the response returned by Elasticsearch. API name: filter_path

func (*Restore) Header

func (r *Restore) Header(key, value string) *Restore

Header set a key, value pair in the Restore headers map.

func (*Restore) HttpRequest

func (r *Restore) HttpRequest(ctx context.Context) (*http.Request, error)

HttpRequest returns the http.Request object built from the given parameters.

func (*Restore) Human

func (r *Restore) Human(human bool) *Restore

Human When set to `true` will return statistics in a format suitable for humans. For example `"exists_time": "1h"` for humans and `"exists_time_in_millis": 3600000` for computers. When disabled the human readable values will be omitted. This makes sense for responses being consumed only by machines. API name: human

func (*Restore) IgnoreIndexSettings

func (r *Restore) IgnoreIndexSettings(ignoreindexsettings ...string) *Restore

The index settings to not restore from the snapshot. You can't use this option to ignore `index.number_of_shards`.

For data streams, this option applies only to restored backing indices. New backing indices are configured using the data stream's matching index template. API name: ignore_index_settings

func (*Restore) IgnoreUnavailable

func (r *Restore) IgnoreUnavailable(ignoreunavailable bool) *Restore

If `true`, the request ignores any index or data stream in indices that's missing from the snapshot. If `false`, the request returns an error for any missing index or data stream. API name: ignore_unavailable

func (*Restore) IncludeAliases

func (r *Restore) IncludeAliases(includealiases bool) *Restore

If `true`, the request restores aliases for any restored data streams and indices. If `false`, the request doesn’t restore aliases. API name: include_aliases

func (*Restore) IncludeGlobalState

func (r *Restore) IncludeGlobalState(includeglobalstate bool) *Restore

If `true`, restore the cluster state. The cluster state includes:

* Persistent cluster settings * Index templates * Legacy index templates * Ingest pipelines * Index lifecycle management (ILM) policies * Stored scripts * For snapshots taken after 7.12.0, feature states

If `include_global_state` is `true`, the restore operation merges the legacy index templates in your cluster with the templates contained in the snapshot, replacing any existing ones whose name matches one in the snapshot. It completely removes all persistent settings, non-legacy index templates, ingest pipelines, and ILM lifecycle policies that exist in your cluster and replaces them with the corresponding items from the snapshot.

Use the `feature_states` parameter to configure how feature states are restored.

If `include_global_state` is `true` and a snapshot was created without a global state then the restore request will fail. API name: include_global_state

func (*Restore) IndexSettings

func (r *Restore) IndexSettings(indexsettings types.IndexSettingsVariant) *Restore

Index settings to add or change in restored indices, including backing indices. You can't use this option to change `index.number_of_shards`.

For data streams, this option applies only to restored backing indices. New backing indices are configured using the data stream's matching index template. API name: index_settings

func (*Restore) Indices

func (r *Restore) Indices(indices ...string) *Restore

A comma-separated list of indices and data streams to restore. It supports a multi-target syntax. The default behavior is all regular indices and regular data streams in the snapshot.

You can't use this parameter to restore system indices or system data streams. Use `feature_states` instead. API name: indices

func (*Restore) MasterTimeout

func (r *Restore) MasterTimeout(duration string) *Restore

MasterTimeout The period to wait for the master node. If the master node is not available before the timeout expires, the request fails and returns an error. To indicate that the request should never timeout, set it to `-1`. API name: master_timeout

func (*Restore) Partial

func (r *Restore) Partial(partial bool) *Restore

If `false`, the entire restore operation will fail if one or more indices included in the snapshot do not have all primary shards available.

If true, it allows restoring a partial snapshot of indices with unavailable shards. Only shards that were successfully included in the snapshot will be restored. All missing shards will be recreated as empty. API name: partial

func (Restore) Perform

func (r Restore) Perform(providedCtx context.Context) (*http.Response, error)

Perform runs the http.Request through the provided transport and returns an http.Response.

func (*Restore) Pretty

func (r *Restore) Pretty(pretty bool) *Restore

Pretty If set to `true` the returned JSON will be "pretty-formatted". Only use this option for debugging only. API name: pretty

func (*Restore) Raw

func (r *Restore) Raw(raw io.Reader) *Restore

Raw takes a json payload as input which is then passed to the http.Request If specified Raw takes precedence on Request method.

func (*Restore) RenamePattern

func (r *Restore) RenamePattern(renamepattern string) *Restore

A rename pattern to apply to restored data streams and indices. Data streams and indices matching the rename pattern will be renamed according to `rename_replacement`.

The rename pattern is applied as defined by the regular expression that supports referencing the original text, according to the `appendReplacement` logic. API name: rename_pattern

func (*Restore) RenameReplacement

func (r *Restore) RenameReplacement(renamereplacement string) *Restore

The rename replacement string that is used with the `rename_pattern`. API name: rename_replacement

func (*Restore) Request

func (r *Restore) Request(req *Request) *Restore

Request allows to set the request property with the appropriate payload.

func (*Restore) WaitForCompletion

func (r *Restore) WaitForCompletion(waitforcompletion bool) *Restore

WaitForCompletion If `true`, the request returns a response when the restore operation completes. The operation is complete when it finishes all attempts to recover primary shards for restored indices. This applies even if one or more of the recovery attempts fail.

If `false`, the request returns a response when the restore operation initializes. API name: wait_for_completion

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL