Restoring a snapshot

Once you have snapshots of your data, it can be restored. The restore process is very fast: the indexed shard data is simply copied on the nodes and activated.

Getting ready

You need an up-and-running Elasticsearch installation as we described in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.

To execute curl via the command line, you need to install curl for your operative system.

To correctly execute the following command, the backup created in the previous recipe is required.

How to do it...

To restore a snapshot, we will perform the following steps:

  1. To restore a snapshot called snap_1 for the test and test1 indices, the HTTP method is PUT and the curl command is:
    curl -XPOST 
            "http://localhost:9200/_snapshot/my_repository/snap_1/_restore? 
            pretty" -d '{
            "indices": "test-index,test-2",
            "ignore_unavailable": "true",
            "include_global_state": false,
            "rename_pattern": "test-(.+)",
            "rename_replacement": "copy_$1"
    }'
    

    The result will be:

                  { 
                    "accepted" : true 
                  }
    
  2. The restore is finished when the cluster state changes from red to yellow or green.

How it works...

The restore process is very fast. The process comprises the following steps:

  1. The data is copied on the primary shard of the restored index (during this step the cluster is in red state).
  2. The primary shards are recovered (during this step the cluster turns from red to yellow/green).
  3. If a replica is set, the primary shards are copied onto other nodes.

It's possible to control the restore process via some parameters, including:

  • indices: This controls the indices that must be restored. If not defined, all indices in the snapshot are restored (a comma delimited list of indices; wildcards are accepted).
  • ignore_unavailable: This stops the restore from failing if some indices are missing (default false).
  • include_global_state: This allows the restoration of the global state from the snapshot (defaults to true, available values are true/false).
  • rename_pattern and rename_replacement: The first one is a pattern that must be matched, and the second one uses regular expression replacement to define a new index name.
  • partial: If it set to true, it is allows the restoration of indices with missing shards (default false).
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.164.24