OpenSearch Snapshot and Restore
Back up and restore any HEAL index with OpenSearch snapshots: create the snapshot repository, take snapshots, and restore them on the same or another cluster.
Note
Scope. Use this page to back up and restore any HEAL index (for example heal_signals*) with a snapshot folder on the OpenSearch node servers. To restore on another cluster, you first copy the contents of the snapshot folder to the servers of that cluster and register the repository there (step b under Snapshot Restore). To back up Jaeger trace indices to an NFS mount that two clusters share and restore them on another cluster, see Jaeger Trace Snapshot and Restore through NFS Mount.
In the commands below, replace <opensearch_ip> and <opensearch_port> with the address of your OpenSearch node, and <user> and <password> with your OpenSearch username and password.
OpenSearch Snapshot#
1. Create and configure a snapshot repository in your server.
a) Create a snapshot folder in <Install Path>/opensearch path in all the OpenSearch node servers using the below command:
mkdir opensearchsnapshot
b. Stop the OpenSearch nomad service.
c. Add the below entry as the volume in opensearch.nomad file to specify snapshot directory:
/<InstallPath>/opensearch/opensearchsnapshot:/usr/share/opensearch/opensearchsnapshot
d. Add the below entry in opensearch.yml and opensearch.yml.tpl files present in:
/<InstallPath>/Appsone_Service/opensearch/config directory.path.repo:
["/usr/share/opensearch/opensearchsnapshot"]
e. Start OpenSearch nomad service.
2. Register repository.
Execute the below curl command on the HEAL server (where OpenSearch is running):
curl command : curl -XPUT -k -u '<user>:<password>'
"https://<opensearch_ip>:<opensearch_port>/_snapshot/<repository_name>" -H 'Content-Type:
application/json' -d'{ "type": "fs", "settings": { "location":
“/usr/share/opensearch/opensearchsnapshot" }}'
If the request is successful, the response from OpenSearch will be minimal as below:
{
"acknowledged": true
}
3. Take a snapshot.
a) Use the below REST API or the curl command below to take a snapshot of all indices and cluster state.
PUT _snapshot/<repository name>/<snapshot name>
Curl command:
curl -XPUT -k -u '<user>:<password>' "https://<opensearch_ip>:<opensearch_port>/_snapshot/<repository
name>/<snapshot name>"
b) You can also add a request body to include or exclude certain indices or specify other settings.
PUT _snapshot/<repository name>/<snapshot name>
{
"indices": "heal_signals*, my-index*, my-index-2022",
"ignore_unavailable": true,
"include_global_state": false,
"partial": false
}
Curl command:
curl -XPUT -k -u '<user>:<password>' "https://<opensearch_ip>:<opensearch_port>/_snapshot/<repository
name>/<snapshot name>" -H 'Content-Type: application/json' -d'{ "indices": "heal_signals*, my-
index*, my-index-2022", "ignore_unavailable": true, "include_global_state": false, "partial": false}'
Snapshots have the following states:
i) indices: The indices you want to include in the snapshot. You can use it to create a list of indices, * To specify an index pattern and to exclude certain indices.
Note: Don’t add space between items. The default is all indices.
ii) ignore_unavailable: If an index from the indices list doesn’t exist (whether to ignore it rather than fail the snapshot). The default is false.
iii) include_global_state: Whether to include cluster state in the snapshot. The default is true.
iv) partial: Whether to allow partial snapshots. The default is false (which fails the entire snapshot if one or more shards fail to store).
c) If you want to wait for the snapshot to finish before continuing, add the wait_for_completion parameter to your request.
Rest API:
PUT _snapshot/<repository name>/<snapshot name>?wait_for_completion=true
Curl command:
curl -XPUT -k -u '<user>:<password>' "https://<opensearch_ip>:<opensearch_port>/_snapshot/<repository
name>/<snapshot name>?wait_for_completion=true"
Snapshots have the following states:
i) SUCCESS: The snapshot successfully stored all shards
ii) IN_PROGRESS: The snapshot is currently running.
iii) PARTIAL: At least one shard failed to store successfully. It can only occur if you set partial to true when taking the snapshot.
iv) FAILED: The snapshot encountered an error and stored no data.
v) INCOMPATIBLE: The snapshot is incompatible with the version of OpenSearch running on this cluster
d) You can’t take a snapshot if one is currently in progress. To check the status, use the below API:
GET _snapshot/_status
Curl command:
curl -XGET -k -u '<user>:<password>' "https://<opensearch_ip>:<opensearch_port>/_snapshot/_status"
Snapshot Restore#
a) The first step in restoring a snapshot is retrieving existing snapshots. To see all the snapshot repositories, execute the following command:
GET _snapshot/_all
Curl command:
curl -XGET -k -u '<user>:<password>' "https://<opensearch_ip>:<opensearch_port>/_snapshot/_all"
To see all snapshots in a repository:
GET _snapshot/<repository name>/_all
Curl command:
curl -XGET -k -u '<user>:<password>' "https://<opensearch_ip>:<opensearch_port>/_snapshot/<repository
name>/_all"
b) Please note that if you are taking a snapshot on one cluster and restoring on another cluster, below steps need to be performed before performing restore:
i) Perform all the steps from step 1 to create and configure the snapshot repository. Copy all the contents from the opensearchsnapshot directory on the server where the snapshot was taken to the opensearchsnapshot directory of the servers where the restore is to be done.
ii) The repository containing the snapshot must be registered and made available to the new cluster.
c) To restore the snapshot, use below REST API:
POST _snapshot/<repository name>/<snapshot name>/_restore
Curl command:
curl cmd : curl -XPOST -k -u '<user>:<password>'
"https://<opensearch_ip>:<opensearch_port>/_snapshot/<repository
name>/<snapshot_name>/_restore"
d) While taking a snapshot, you can add a request body to include or exclude certain indices or specify some other settings:
POST _snapshot//<repository name>/<snapshot name>/_restore
{
"indices": "heal_signals*",
"ignore_unavailable": true,
"include_global_state": false,
"partial": false,
"rename_pattern": "heal_signals(.+)",
"rename_replacement": "restored1-heal_signals$1"
}
Curl command:
curl -XPOST -k -u '<user>:<password>'
"https://<opensearch_ip>:<opensearch_port>/_snapshot/<repository_name>/<snapshot_name>/_r
estore" -H 'Content-Type: application/json' -d'{ "indices": "heal_signals*", "ignore_unavailable":
true, "include_global_state": false, "partial": false, "rename_pattern": "heal_signals(.+)",
"rename_replacement": "restored1-heal_signals$1"}'
Snapshots have the following states:
i) indices: The indices you want to restore. You can use it to create a list of indices, * To specify an index pattern and to exclude certain indices.
Note: Don’t add space between items. The default is all indices.
ii) ignore_unavailable: If an index from the indices list doesn’t exist, whether to ignore it rather than fail the restore operation. The default is false.
iii) include_global_state: Whether to restore the cluster state. The default is false.
iv) include_aliases: Whether to restore aliases alongside their associated indices. The default is true.
v) partial: Whether to allow the restoration of partial snapshots. The default is false.
vi) rename_pattern: If you want to rename indices as you restore them, use this option to specify a regular expression that matches all indices you want to restore. Use capture groups (()) to reuse portions of the index name.
vii) rename_replacement: If you want to rename indices as you restore them (use this option to specify the replacement pattern). Use $0 to include the entire matching index name, $1 to include the content of the first capture group, etc.
viii) index_settings: If you want to change index settings on restore, specify them here.
ix) ignore_index_settings: Rather than explicitly specifying new settings with index_settings, you can ignore certain index settings in the snapshot and use the cluster defaults on restore.