Snapshot

A snapshot is a backup of your cluster index(s). Snapshots are stored in a repository that has been registered before. A repository can contain multiple snapshots of the same cluster. A snapshot can be created by executing the following command:

curl -XPUT localhost:9200/_snapshot/my_backup/first_snapshot

The _snapshot is REST endpoint for snapshot operations. Its second parameter is a unique snapshot name. The preceding command creates a snapshot of all open and started indices in the cluster. If you want to back up a certain index, you must specify the list of indices in the body of the request:

curl -XPUT localhost:9200/_snapshot/my_backup/first_snapshot -d '{
  "indices": "my_index",
  "ignore_unavailable": "true",
  "include_global_state": false,
  "partial": true
}'

The indices parameter supports multi-index syntax; that means you can separate the index names with commas or you can use a wildcard, like *. Default value of the ignore_unavailable parameter is true. It will cause indices that do not exist to be ignored during snapshot creation. If this behavior is not desired, the value of the parameter should be set to false. The include_global_state setting allows us to store the global state as part of the snapshot. If you want to restore the snapshot into a different cluster, the include_global_state parameter should be set to false. By default, the snapshot operation will fail when one or more indices don't have all primary shards available. This behavior can be changed by setting the partial parameter to true.

By default, a snapshot request should return immediately after snapshot initialization. This behavior can be changed by setting the wait_for_completion parameter to true, as follows:

curl-XPUT localhost:9200/_snapshot/my_backup/first_snapshot?wait_for_completion=true

Even when the wait_for_completion parameter is set to false, the snapshot request may take longer to return in some cases because during snapshot initialization, information on the all previous snapshots is loaded into memory. Therefore, if you have large repositories, the snapshot request to return may take several seconds or even minutes. After you create a snapshot, its information can be obtained using the following command:

curl -XGET localhost:9200/_snapshot/my_backup/first_snapshot
{
   "snapshots": [
      {
         "snapshot": "first_snapshot",
         "version_id": 1070199,
         "version": "1.7.3",
         "indices": [
"my_index"
         ],
         "state": "SUCCESS",
         "start_time": "2015-10-24T20:06:27.465Z",
         "start_time_in_millis": 1445717187465,
         "end_time": "2015-10-24T20:06:27.996Z",
         "end_time_in_millis": 1445717187996,
         "duration_in_millis": 531,
         "failures": [],
         "shards": {
            "total": 5,
            "failed": 0,
            "successful": 5
         }
      }
   ]
}

You can obtain information of all snapshots using the _all parameter:

curl -XGET localhost:9200/_snapshot/my_backup/_all

Also, you can get more and complete status information about currently running snapshots using the following command:

curl -XGET localhost:9200/_snapshot/_status

The preceding command will return information about all currently running snapshots. You can use the following command if you want to get status information about snapshots belonging to only a particular repository:

curl -XGET localhost:9200/_snapshot/my_backup/_status

If you want to get detailed status information about a snapshot, you must give the repository and snapshot name as following. In this case, Elasticsearch will return detailed status information for the given snapshot even if it's not currently running:

GET /_snapshot/my_backup/first_snapshot/_status
{
   "snapshots": [
      {
         "snapshot": "first_snapshot",
         "repository": "my_backup",
         "state": "SUCCESS",
         "shards_stats": {
            "initializing": 0,
            "started": 0,
            "finalizing": 0,
            "done": 5,
            "failed": 0,
            "total": 5
         },
         "stats": {
            "number_of_files": 65,
            "processed_files": 65,
            "total_size_in_bytes": 18176267,
            "processed_size_in_bytes": 18176267,
            "start_time_in_millis": 1445873862080,
            "time_in_millis": 413
         },
         "indices": {
            "my_index": {
               "shards_stats": {
                  "initializing": 0,
                  "started": 0,
                  "finalizing": 0,
                  "done": 5,
                  "failed": 0,
                  "total": 5
               },
               "stats": {
                  "number_of_files": 65,
                  "processed_files": 65,
                  "total_size_in_bytes": 18176267,
                  "processed_size_in_bytes": 18176267,
                  "start_time_in_millis": 1445873862080,
                  "time_in_millis": 413
               },
               "shards": {
                  "0": {
                     "stage": "DONE",
                     "stats": {
                        "number_of_files": 13,
                        "processed_files": 13,
                        "total_size_in_bytes": 3910310,
                        "processed_size_in_bytes": 3910310,
                        "start_time_in_millis": 1445873862234,
                        "time_in_millis": 164
                     }
                  },
                  ...
                  }
               }
            }
         }
      }
   ]
}

You can get status information about multiple snapshots, as follows:

curl-XGET localhost:9200/_snapshot/my_backup/first_snapshot,second_snapshot/_status

And, finally, a snapshot can be deleted using the following command:

curl -XDELETE localhost:9200/_snapshot/my_backup/first_snapshot

Note that the snapshot delete command can also be used to terminate snapshot process when it is running.

..................Content has been hidden....................

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