Elasticsearch and S3 Buckets (Windows)
This guide walks through how to configure Elasticsearch to store snapshots in an S3 bucket, and how to upload a snapshot to a configured S3 bucket. This guide uses the default Elasticsearch host and port (localhost:9208). If your Elasticsearch instance is running on a different host or port, replace localhost:9208 in all commands with your actual Elasticsearch address (e.g., elasticsearch.example.com:9200).
Prerequisites
- The access and secret key to the S3 bucket
- Command-line access to your Elasticsearch installation directory
Step 1: Add S3 Credentials to Keystore
[!NOTE] Replace
CLIENT-NAME-HEREin the following commands with your desired client identifier (e.g.,my-s3-client). Use the same name consistently throughout these steps.
Launch an elevated command prompt and navigate to the .\bin directory for Elasticsearch (by default, located in C:\Entrinsik\elasticsearch\elasticsearch-8.2.2\bin\ and run the following commands to add your S3 access key to the Elasticsearch keystore:
.\elasticsearch-keystore add s3.client.CLIENT-NAME-HERE.access_key
When prompted, paste your S3 access key and press Enter. Then add your S3 secret key:
.\elasticsearch-keystore add s3.client.CLIENT-NAME-HERE.secret_key
When prompted, paste your S3 secret key and press Enter. Restart the Elasticsearch service to load the new credentials.
Step 2: Create S3 Snapshot Repository
Register your S3 bucket as a snapshot repository:
curl -L -X PUT "http://localhost:9208/_snapshot/REPO-NAME-HERE" \
-H "Content-Type: application/json" \
-d "{\"type\":\"s3\",\"settings\":{\"bucket\":\"BUCKET-NAME-HERE\",\"client\":\"CLIENT-NAME-HERE\"}}"
Parameters:
REPO-NAME-HERE— repository name (can be customized)BUCKET-NAME-HERE— your S3 bucket nameCLIENT-NAME-HERE— must match the keystore client name from Step 1
Step 3: Create A Snapshot
Create and upload a snapshot with the following command:
curl -L -X POST "http://localhost:9208/_snapshot/REPO-NAME-HERE/SNAPSHOT-NAME-HERE" \
-H "Content-Type: application/json" \
-d "{}"
Parameters:
REPO-NAME-HERE— repository name (this should be the same as the one set in the previous step)SNAPSHOT-NAME-HERE— snapshot (must be unique)
This will initiate a snapshot backup to S3. Monitor progress with:
curl -L -X GET "http://localhost:9208/_snapshot/REPO-NAME-HERE/SNAPSHOT-NAME-HERE"
Verification
List all snapshots in your repository:
curl -L -X GET "http://localhost:9208/_snapshot/REPO-NAME-HERE/_all"
The SNAPSHOT-NAME-HERE snapshot should appear in the response with a SUCCESS state.