Elasticsearch: Creating Snapshots

Before proceeding with the following steps, connect to the target machine or use the machine’s external IP address (if you have the necessary permissions).

Step 1: Get All Items in Elasticsearch

List all Indexes in Elasticsearch:

curl -u "user:password" -X GET "localhost:9200/_cat/indices?v"

List all items in the specific Index:

curl -u "user:password" -X GET "localhost:9200/products/_search?pretty"

Step 2: Create a Snapshot

Create a snapshot of your Elasticsearch data:

time curl -u "user:password" -X PUT "http://localhost:9200/_snapshot/test-elasticsearch-space/snapshot_$(date +%Y%m%d%H%M%S)?wait_for_completion=true&pretty" -H 'Content-Type: application/json' -d'
{
  "indices": "*",
  "ignore_unavailable": true,
  "include_global_state": true
}
'

where:

  • http://127.0.0.1:9200: The Elasticsearch endpoint.

  • /_snapshot/test-elasticsearch-space: Specifies the registered snapshot repository (test-elasticsearch-space).

  • /snapshot_$(date +%Y%m%d%H%M%S): Dynamically generates a unique snapshot name using the current date and time in the format YYYYMMDDHHMMSS. This ensures that snapshots have unique names.

  • ?wait_for_completion=true: Ensures the operation waits until the snapshot creation is complete before returning a response.

  • &pretty: Formats the JSON response for better readability.

Verifying Snapshots

List All Available Snapshots

curl -u "user:password" -X GET "http://localhost:9200/_cat/snapshots/test-elasticsearch-space?v&s=id&pretty"

Verify all snapshots stored in the repository (for detailed inspection and debugging):

curl -u "user:password" -X GET "http://localhost:9200/_snapshot/test-elasticsearch-space/_all?pretty"

To retrieve detailed information about a specific snapshot:

curl -u "user:password" -X GET "http://localhost:9200/_snapshot/test-elasticsearch-space/snapshot_20241211144811?pretty"

Verifying Elasticsearch Data in DigitalOcean Spaces

  1. From the left-hand menu, click Spaces Object Storage under the Manage section.

  2. Select the Space where ElasticSearch snapshots are stored

  3. In the Space, open the directory configured as the base_path in Elasticsearch

image-20241212-113859.png

  1. Inside the base_path directory, look for snapshot files. These may include:

  • metadata-*.dat files: Metadata for the snapshots.

  • snapshot-*.dat files: The actual snapshot data.

  • index-* files: Index-specific metadata.

Deleting a Snapshot

curl -u "user:password" -X DELETE "http://localhost:9200/_snapshot/test-elasticsearch-space/snapshot_20241211144811?pretty"

Comments

Leave a Reply