2013-11-08 19:20:43 -05:00
[[modules-snapshots]]
== Snapshot And Restore
The snapshot and restore module allows to create snapshots of individual indices or an entire cluster into a remote
2014-04-03 21:29:51 -04:00
repository. At the time of the initial release only shared file system repository was supported, but now a range of
backends are available via officially supported repository plugins.
2013-11-08 19:20:43 -05:00
[float]
=== Repositories
Before any snapshot or restore operation can be performed a snapshot repository should be registered in
2015-05-13 20:03:50 -04:00
Elasticsearch. The repository settings are repository-type specific. See below for details.
2013-11-08 19:20:43 -05:00
[source,js]
-----------------------------------
2015-06-19 12:04:52 -04:00
PUT /_snapshot/my_backup
{
"type": "fs",
"settings": {
2015-05-13 20:03:50 -04:00
... repository specific settings ...
2015-06-19 12:04:52 -04:00
}
}
2013-11-08 19:20:43 -05:00
-----------------------------------
2015-02-12 05:00:21 -05:00
Once a repository is registered, its information can be obtained using the following command:
2013-11-08 19:20:43 -05:00
[source,js]
-----------------------------------
2015-06-19 12:04:52 -04:00
GET /_snapshot/my_backup
2013-11-08 19:20:43 -05:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
which returns:
2013-11-08 19:20:43 -05:00
[source,js]
-----------------------------------
{
2015-06-19 12:04:52 -04:00
"my_backup": {
"type": "fs",
"settings": {
"compress": "true",
"location": "/mount/backups/my_backup"
2013-11-08 19:20:43 -05:00
}
}
}
-----------------------------------
If a repository name is not specified, or `_all` is used as repository name Elasticsearch will return information about
all repositories currently registered in the cluster:
[source,js]
-----------------------------------
2015-06-19 12:04:52 -04:00
GET /_snapshot
2013-11-08 19:20:43 -05:00
-----------------------------------
or
[source,js]
-----------------------------------
2015-06-19 12:04:52 -04:00
GET /_snapshot/_all
2013-11-08 19:20:43 -05:00
-----------------------------------
[float]
===== Shared File System Repository
2015-05-13 20:03:50 -04:00
The shared file system repository (`"type": "fs"`) uses the shared file system to store snapshots. In order to register
the shared file system repository it is necessary to mount the same shared filesystem to the same location on all
master and data nodes. This location (or one of its parent directories) has to be registered in the `path.repo`
setting on all master and data nodes.
Assuming that the shared filesystem is mounted to `/mount/backups/my_backup`, the following setting should be added to
`elasticsearch.yml` file:
[source,yaml]
--------------
path.repo: ["/mount/backups", "/mount/longterm_backups"]
--------------
After all nodes are restarted, the following command can be used to register the shared file system repository with
the name `my_backup`:
[source,js]
-----------------------------------
$ curl -XPUT 'http://localhost:9200/_snapshot/my_backup' -d '{
"type": "fs",
"settings": {
"location": "/mount/backups/my_backup",
"compress": true
}
}'
-----------------------------------
If the repository location is specified as a relative path this path will be resolved against the first path specified
in `path.repo`:
[source,js]
-----------------------------------
$ curl -XPUT 'http://localhost:9200/_snapshot/my_backup' -d '{
"type": "fs",
"settings": {
"location": "my_backup",
"compress": true
}
}'
-----------------------------------
The following settings are supported:
2013-11-08 19:20:43 -05:00
[horizontal]
`location`:: Location of the snapshots. Mandatory.
2014-09-09 00:17:38 -04:00
`compress`:: Turns on compression of the snapshot files. Compression is applied only to metadata files (index mapping and settings). Data files are not compressed. Defaults to `true`.
2013-11-08 19:20:43 -05:00
`chunk_size`:: Big files can be broken down into chunks during snapshotting if needed. The chunk size can be specified in bytes or by
using size value notation, i.e. 1g, 10m, 5k. Defaults to `null` (unlimited chunk size).
2015-03-20 16:09:42 -04:00
`max_restore_bytes_per_sec`:: Throttles per node restore rate. Defaults to `40mb` per second.
`max_snapshot_bytes_per_sec`:: Throttles per node snapshot rate. Defaults to `40mb` per second.
2013-11-08 19:20:43 -05:00
2014-01-15 12:57:05 -05:00
[float]
===== Read-only URL Repository
2014-12-17 06:22:17 -05:00
The URL repository (`"type": "url"`) can be used as an alternative read-only way to access data created by the shared file
system repository. The URL specified in the `url` parameter should
2014-01-15 12:57:05 -05:00
point to the root of the shared filesystem repository. The following settings are supported:
[horizontal]
`url`:: Location of the snapshots. Mandatory.
2014-02-05 11:43:14 -05:00
[float]
===== Repository plugins
Other repository backends are available in these official plugins:
* https://github.com/elasticsearch/elasticsearch-cloud-aws#s3-repository[AWS Cloud Plugin] for S3 repositories
2014-02-06 11:40:13 -05:00
* https://github.com/elasticsearch/elasticsearch-hadoop/tree/master/repository-hdfs[HDFS Plugin] for Hadoop environments
2014-03-17 14:40:28 -04:00
* https://github.com/elasticsearch/elasticsearch-cloud-azure#azure-repository[Azure Cloud Plugin] for Azure storage repositories
2014-02-05 11:43:14 -05:00
2014-10-07 12:33:21 -04:00
[float]
2015-01-29 14:57:12 -05:00
===== Repository Verification
2015-01-29 06:15:20 -05:00
When a repository is registered, it's immediately verified on all master and data nodes to make sure that it is functional
2015-04-01 04:18:29 -04:00
on all nodes currently present in the cluster. The `verify` parameter can be used to explicitly disable the repository
verification when registering or updating a repository:
[source,js]
-----------------------------------
2015-06-19 12:04:52 -04:00
PUT /_snapshot/s3_repository?verify=false
{
"type": "s3",
"settings": {
"bucket": "my_s3_bucket",
"region": "eu-west-1"
}
}
2015-04-01 04:18:29 -04:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2015-04-01 04:18:29 -04:00
The verification process can also be executed manually by running the following command:
2014-09-10 21:49:15 -04:00
[source,js]
-----------------------------------
2015-06-19 12:04:52 -04:00
POST /_snapshot/my_backup/_verify
2014-09-10 21:49:15 -04:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2014-09-10 21:49:15 -04:00
2014-10-07 12:33:21 -04:00
It returns a list of nodes where repository was successfully verified or an error message if verification process failed.
2014-09-10 21:49:15 -04:00
2013-11-08 19:20:43 -05:00
[float]
=== Snapshot
A repository can contain multiple snapshots of the same cluster. Snapshot are identified by unique names within the
cluster. A snapshot with the name `snapshot_1` in the repository `my_backup` can be created by executing the following
command:
[source,js]
-----------------------------------
2015-06-19 12:04:52 -04:00
PUT /_snapshot/my_backup/snapshot_1?wait_for_completion=true
2013-11-08 19:20:43 -05:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2013-11-08 19:20:43 -05:00
2014-10-08 08:43:06 -04:00
The `wait_for_completion` parameter specifies whether or not the request should return immediately after snapshot
initialization (default) or wait for snapshot completion. During snapshot initialization, information about all
previous snapshots is loaded into the memory, which means that in large repositories it may take several seconds (or
even minutes) for this command to return even if the `wait_for_completion` parameter is set to `false`.
2015-02-12 05:00:21 -05:00
By default a snapshot of all open and started indices in the cluster is created. This behavior can be changed by
2014-10-08 08:43:06 -04:00
specifying the list of indices in the body of the snapshot request.
2013-11-08 19:20:43 -05:00
[source,js]
-----------------------------------
2015-06-19 12:04:52 -04:00
PUT /_snapshot/my_backup/snapshot_1
{
"indices": "index_1,index_2",
"ignore_unavailable": "true",
"include_global_state": false
}
2013-11-08 19:20:43 -05:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2013-11-08 19:20:43 -05:00
The list of indices that should be included into the snapshot can be specified using the `indices` parameter that
supports <<search-multi-index-type,multi index syntax>>. The snapshot request also supports the
2014-04-03 19:54:37 -04:00
`ignore_unavailable` option. Setting it to `true` will cause indices that do not exist to be ignored during snapshot
2013-12-11 18:30:12 -05:00
creation. By default, when `ignore_unavailable` option is not set and an index is missing the snapshot request will fail.
2013-11-08 19:20:43 -05:00
By setting `include_global_state` to false it's possible to prevent the cluster global state to be stored as part of
2015-02-12 05:00:21 -05:00
the snapshot. By default, the entire snapshot will fail if one or more indices participating in the snapshot don't have
2014-01-13 11:22:13 -05:00
all primary shards available. This behaviour can be changed by setting `partial` to `true`.
2013-11-08 19:20:43 -05:00
The index snapshot process is incremental. In the process of making the index snapshot Elasticsearch analyses
the list of the index files that are already stored in the repository and copies only files that were created or
changed since the last snapshot. That allows multiple snapshots to be preserved in the repository in a compact form.
Snapshotting process is executed in non-blocking fashion. All indexing and searching operation can continue to be
executed against the index that is being snapshotted. However, a snapshot represents the point-in-time view of the index
2015-02-12 05:00:21 -05:00
at the moment when snapshot was created, so no records that were added to the index after the snapshot process was started
2014-05-12 17:19:10 -04:00
will be present in the snapshot. The snapshot process starts immediately for the primary shards that has been started
2014-07-17 15:25:34 -04:00
and are not relocating at the moment. Before version 1.2.0, the snapshot operation fails if the cluster has any relocating or
2014-05-12 17:19:10 -04:00
initializing primaries of indices participating in the snapshot. Starting with version 1.2.0, Elasticsearch waits for
2014-07-17 15:25:34 -04:00
relocation or initialization of shards to complete before snapshotting them.
2013-11-08 19:20:43 -05:00
Besides creating a copy of each index the snapshot process can also store global cluster metadata, which includes persistent
cluster settings and templates. The transient settings and registered snapshot repositories are not stored as part of
the snapshot.
Only one snapshot process can be executed in the cluster at any time. While snapshot of a particular shard is being
created this shard cannot be moved to another node, which can interfere with rebalancing process and allocation
2015-02-12 05:00:21 -05:00
filtering. Elasticsearch will only be able to move a shard to another node (according to the current allocation
filtering settings and rebalancing algorithm) once the snapshot is finished.
2013-11-08 19:20:43 -05:00
Once a snapshot is created information about this snapshot can be obtained using the following command:
2015-07-14 12:14:09 -04:00
[source,sh]
2013-11-08 19:20:43 -05:00
-----------------------------------
2015-06-19 12:04:52 -04:00
GET /_snapshot/my_backup/snapshot_1
2013-11-08 19:20:43 -05:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2013-11-08 19:20:43 -05:00
All snapshots currently stored in the repository can be listed using the following command:
2015-07-14 12:14:09 -04:00
[source,sh]
2013-11-08 19:20:43 -05:00
-----------------------------------
2015-06-19 12:04:52 -04:00
GET /_snapshot/my_backup/_all
2013-11-08 19:20:43 -05:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2013-11-08 19:20:43 -05:00
2015-01-23 15:31:29 -05:00
coming[2.0] A currently running snapshot can be retrieved using the following command:
2015-07-14 12:14:09 -04:00
[source,sh]
2015-01-23 15:31:29 -05:00
-----------------------------------
$ curl -XGET "localhost:9200/_snapshot/my_backup/_current"
-----------------------------------
2013-11-08 19:20:43 -05:00
A snapshot can be deleted from the repository using the following command:
2015-07-14 12:14:09 -04:00
[source,sh]
2013-11-08 19:20:43 -05:00
-----------------------------------
2015-06-19 12:04:52 -04:00
DELETE /_snapshot/my_backup/snapshot_1
2013-11-08 19:20:43 -05:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2013-11-08 19:20:43 -05:00
When a snapshot is deleted from a repository, Elasticsearch deletes all files that are associated with the deleted
snapshot and not used by any other snapshots. If the deleted snapshot operation is executed while the snapshot is being
created the snapshotting process will be aborted and all files created as part of the snapshotting process will be
cleaned. Therefore, the delete snapshot operation can be used to cancel long running snapshot operations that were
started by mistake.
2014-10-20 21:04:34 -04:00
A repository can be deleted using the following command:
2015-07-14 12:14:09 -04:00
[source,sh]
2014-10-20 21:04:34 -04:00
-----------------------------------
2015-06-19 12:04:52 -04:00
DELETE /_snapshot/my_backup
2014-10-20 21:04:34 -04:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2014-10-20 21:04:34 -04:00
When a repository is deleted, Elasticsearch only removes the reference to the location where the repository is storing
the snapshots. The snapshots themselves are left untouched and in place.
2013-11-08 19:20:43 -05:00
[float]
=== Restore
2014-03-15 18:58:18 -04:00
A snapshot can be restored using the following command:
2013-11-08 19:20:43 -05:00
2015-07-14 12:14:09 -04:00
[source,sh]
2013-11-08 19:20:43 -05:00
-----------------------------------
2015-06-19 12:04:52 -04:00
POST /_snapshot/my_backup/snapshot_1/_restore
2013-11-08 19:20:43 -05:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2013-11-08 19:20:43 -05:00
By default, all indices in the snapshot as well as cluster state are restored. It's possible to select indices that
should be restored as well as prevent global cluster state from being restored by using `indices` and
`include_global_state` options in the restore request body. The list of indices supports
<<search-multi-index-type,multi index syntax>>. The `rename_pattern` and `rename_replacement` options can be also used to
rename index on restore using regular expression that supports referencing the original text as explained
http://docs.oracle.com/javase/6/docs/api/java/util/regex/Matcher.html#appendReplacement(java.lang.StringBuffer,%20java.lang.String)[here].
2014-09-26 15:04:42 -04:00
Set `include_aliases` to `false` to prevent aliases from being restored together with associated indices
2013-11-08 19:20:43 -05:00
[source,js]
-----------------------------------
2015-06-19 12:04:52 -04:00
POST /_snapshot/my_backup/snapshot_1/_restore
{
"indices": "index_1,index_2",
"ignore_unavailable": "true",
"include_global_state": false,
"rename_pattern": "index_(.+)",
"rename_replacement": "restored_index_$1"
}
2013-11-08 19:20:43 -05:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2013-11-08 19:20:43 -05:00
The restore operation can be performed on a functioning cluster. However, an existing index can be only restored if it's
2015-05-12 20:59:24 -04:00
<<indices-open-close,closed>> and has the same number of shards as the index in the snapshot.
The restore operation automatically opens restored indices if they were closed and creates new indices if they
2013-11-08 19:20:43 -05:00
didn't exist in the cluster. If cluster state is restored, the restored templates that don't currently exist in the
cluster are added and existing templates with the same name are replaced by the restored templates. The restored
persistent settings are added to the existing persistent settings.
2014-03-15 18:58:18 -04:00
2014-06-01 15:13:13 -04:00
[float]
2015-05-12 20:59:24 -04:00
==== Partial restore
2014-06-01 15:13:13 -04:00
2015-02-12 05:00:21 -05:00
By default, the entire restore operation will fail if one or more indices participating in the operation don't have
2014-06-01 15:13:13 -04:00
snapshots of all shards available. It can occur if some shards failed to snapshot for example. It is still possible to
restore such indices by setting `partial` to `true`. Please note, that only successfully snapshotted shards will be
restored in this case and all missing shards will be recreated empty.
2014-03-15 18:58:18 -04:00
2015-01-13 19:16:37 -05:00
[float]
2015-05-12 20:59:24 -04:00
==== Changing index settings during restore
2015-01-13 19:16:37 -05:00
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]
-----------------------------------
2015-06-19 12:04:52 -04:00
POST /_snapshot/my_backup/snapshot_1/_restore
{
"indices": "index_1",
"index_settings": {
"index.number_of_replicas": 0
},
"ignore_index_settings": [
"index.refresh_interval"
]
}
2015-01-13 19:16:37 -05:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2015-01-13 19:16:37 -05:00
2015-05-12 20:59:24 -04:00
Please note, that some settings such as `index.number_of_shards` cannot be changed during restore operation.
[float]
==== Restoring to a different cluster
The information stored in a snapshot is not tied to a particular cluster or a cluster name. Therefore it's possible to
restore a snapshot made from one cluster into another cluster. All that is required is registering the repository
containing the snapshot in the new cluster and starting the restore process. The new cluster doesn't have to have the
same size or topology. However, the version of the new cluster should be the same or newer than the cluster that was
used to create the snapshot.
If the new cluster has a smaller size additional considerations should be made. First of all it's necessary to make sure
that new cluster have enough capacity to store all indices in the snapshot. It's possible to change indices settings
during restore to reduce the number of replicas, which can help with restoring snapshots into smaller cluster. It's also
possible to select only subset of the indices using the `indices` parameter. Prior to version 1.5.0 elasticsearch
didn't check restored persistent settings making it possible to accidentally restore an incompatible
`discovery.zen.minimum_master_nodes` setting, and as a result disable a smaller cluster until the required number of
master eligible nodes is added. Starting with version 1.5.0 incompatible settings are ignored.
If indices in the original cluster were assigned to particular nodes using
<<shard-allocation-filtering,shard allocation filtering>>, the same rules will be enforced in the new cluster. Therefore
if the new cluster doesn't contain nodes with appropriate attributes that a restored index can be allocated on, such
index will not be successfully restored unless these index allocation settings are changed during restore operation.
2015-01-13 19:16:37 -05:00
2014-03-15 18:58:18 -04:00
[float]
=== Snapshot status
A list of currently running snapshots with their detailed status information can be obtained using the following command:
2015-07-14 12:14:09 -04:00
[source,sh]
2014-03-15 18:58:18 -04:00
-----------------------------------
2015-06-19 12:04:52 -04:00
GET /_snapshot/_status
2014-03-15 18:58:18 -04:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2014-03-15 18:58:18 -04:00
In this format, the command will return information about all currently running snapshots. By specifying a repository name, it's possible
to limit the results to a particular repository:
2015-07-14 12:14:09 -04:00
[source,sh]
2014-03-15 18:58:18 -04:00
-----------------------------------
2015-06-19 12:04:52 -04:00
GET /_snapshot/my_backup/_status
2014-03-15 18:58:18 -04:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2014-03-15 18:58:18 -04:00
If both repository name and snapshot id are specified, this command will return detailed status information for the given snapshot even
if it's not currently running:
2015-07-14 12:14:09 -04:00
[source,sh]
2014-03-15 18:58:18 -04:00
-----------------------------------
2015-06-19 12:04:52 -04:00
GET /_snapshot/my_backup/snapshot_1/_status
2014-03-15 18:58:18 -04:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2014-03-15 18:58:18 -04:00
Multiple ids are also supported:
2015-07-14 12:14:09 -04:00
[source,sh]
2014-03-15 18:58:18 -04:00
-----------------------------------
2015-06-19 12:04:52 -04:00
GET /_snapshot/my_backup/snapshot_1,snapshot_2/_status
2014-03-15 18:58:18 -04:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2014-06-11 20:52:45 -04:00
[float]
=== Monitoring snapshot/restore progress
There are several ways to monitor the progress of the snapshot and restores processes while they are running. Both
operations support `wait_for_completion` parameter that would block client until the operation is completed. This is
the simplest method that can be used to get notified about operation completion.
The snapshot operation can be also monitored by periodic calls to the snapshot info:
2015-07-14 12:14:09 -04:00
[source,sh]
2014-06-11 20:52:45 -04:00
-----------------------------------
2015-06-19 12:04:52 -04:00
GET /_snapshot/my_backup/snapshot_1
2014-06-11 20:52:45 -04:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2014-06-11 20:52:45 -04:00
2014-12-17 06:22:17 -05:00
Please note that snapshot info operation uses the same resources and thread pool as the snapshot operation. So,
executing a snapshot info operation while large shards are being snapshotted can cause the snapshot info operation to wait
2014-06-11 20:52:45 -04:00
for available resources before returning the result. On very large shards the wait time can be significant.
To get more immediate and complete information about snapshots the snapshot status command can be used instead:
2015-07-14 12:14:09 -04:00
[source,sh]
2014-06-11 20:52:45 -04:00
-----------------------------------
2015-06-19 12:04:52 -04:00
GET /_snapshot/my_backup/snapshot_1/_status
2014-06-11 20:52:45 -04:00
-----------------------------------
2015-06-19 12:04:52 -04:00
// AUTOSENSE
2014-06-11 20:52:45 -04:00
While snapshot info method returns only basic information about the snapshot in progress, the snapshot status returns
complete breakdown of the current state for each shard participating in the snapshot.
The restore process piggybacks on the standard recovery mechanism of the Elasticsearch. As a result, standard recovery
monitoring services can be used to monitor the state of restore. When restore operation is executed the cluster
typically goes into `red` state. It happens because the restore operation starts with "recovering" primary shards of the
restored indices. During this operation the primary shards become unavailable which manifests itself in the `red` cluster
state. Once recovery of primary shards is completed Elasticsearch is switching to standard replication process that
creates the required number of replicas at this moment cluster switches to the `yellow` state. Once all required replicas
are created, the cluster switches to the `green` states.
The cluster health operation provides only a high level status of the restore process. It’ s possible to get more
detailed insight into the current state of the recovery process by using <<indices-recovery, indices recovery>> and
<<cat-recovery, cat recovery>> APIs.
[float]
=== Stopping currently running snapshot and restore operations
2015-02-12 05:00:21 -05:00
The snapshot and restore framework allows running only one snapshot or one restore operation at a time. If a currently
running snapshot was executed by mistake, or takes unusually long, it can be terminated using the snapshot delete operation.
The snapshot delete operation checks if the deleted snapshot is currently running and if it does, the delete operation stops
that snapshot before deleting the snapshot data from the repository.
2014-06-11 20:52:45 -04:00
2014-12-17 06:22:17 -05:00
The restore operation uses the standard shard recovery mechanism. Therefore, any currently running restore operation can
2014-06-11 20:52:45 -04:00
be canceled by deleting indices that are being restored. Please note that data for all deleted indices will be removed
from the cluster as a result of this operation.
2015-06-10 12:57:45 -04:00
[float]
=== Effect of cluster blocks on snapshot and restore operations
Many snapshot and restore operations are affected by cluster and index blocks. For example, registering and unregistering
repositories require write global metadata access. The snapshot operation requires that all indices and their metadata as
well as the global metadata were readable. The restore operation requires the global metadata to be writable, however
the index level blocks are ignored during restore because indices are essentially recreated during restore.
Please note that a repository content is not part of the cluster and therefore cluster blocks don't affect internal
repository operations such as listing or deleting snapshots from an already registered repository.
2014-06-11 20:52:45 -04:00