How to backup on-prem Elasticsearch cluster to S3 bucket and restore reverse way

Hello
I have a Elasticsearch cluster installed in my on-premise infrastructure. Also installed repository plug-in by running

bin/elasticsearch-plugin install repository-s3

'''
curl -X PUT "localhost:9200/_snapshot/tenant_s3_repository?pretty" -H 'Content-Type: application/json' -d'
{
"type": "s3",
"settings": {
"bucket": "tenant-snapshot"
}
}
'
'''

While I executed this raised error:
'''
{
"error" : {
"root_cause" : [
{
"type" : "repository_verification_exception",
"reason" : "[tenant_s3_repository] path is not accessible on master node"
}
],
"type" : "repository_verification_exception",
"reason" : "[tenant_s3_repository] path is not accessible on master node",
"caused_by" : {
"type" : "i_o_exception",
"reason" : "Unable to upload object [tests-Vc1KJgFnQ3G6HqYKBRsIsA/master.dat] using a single upload",
"caused_by" : {
"type" : "amazon_service_exception",
"reason" : "Internal Server Error (Service: null; Status Code: 500; Error Code: null; Request ID: null)"
}
}
},
"status" : 500
}
'''

I know i have to register a repository, But i dont know how to. Did not even find any documentation on it.

I would appreciate your suggestions and guideline. Thanks

Welcome to our community! :smiley:

The documentation here goes into that - Snapshot and restore | Elasticsearch Reference [7.11] | Elastic

Useful link, thanks for sharing Mark.

I have made full poof steps for version 6.8. here are those.

Taking a snapshot of on-prem to S3

Custom Policy: We will create a custom policy with the following policy document:

{
"Statement": [
{
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation",
"s3:ListBucketMultipartUploads",
"s3:ListBucketVersions"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::S3-BUCKET-NAME"
]
},
{
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject",
"s3:AbortMultipartUpload",
"s3:ListMultipartUploadParts"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::S3-BUCKET-NAME/*"
]
}
],
"Version": "2012-10-17"
}

IAM User: Then, we will create an IAM user attaching the custom policy. We need to collect the ACCESS_KEY_ID and SECRET_ACCESS_KEY.

S3 Elasticsearch Plugin Installation :
Install S3 plugin:

cd /usr/share/elasticsearch
sudo bin/elasticsearch-plugin install --batch repository-s3

For easy setup, set -Des.allow_insecure_settings=true to /etc/elasticsearch/jvm.options.

Snapshot Repository Registration :

curl -X PUT "localhost:9200/_snapshot/REPOSITORY_NAME?pretty" -H 'Content-Type: application/json' -d'
{
"type": "s3",
"settings": {
"bucket": "S3-BUCKET-NAME",
"region": "AWS_REGION",
"access_key": "ACCESS_KEY_ID",
"secret_key": "SECRET_ACCESS_KEY"
}
}
'

Taking Snapshot :
We can take a snapshot from running elasticsearch cluser by the following command, Here, SNAPSHOT_NAME is unique per REPOSITORY_NAME.

curl -X PUT "localhost:9200/_snapshot/REPOSITORY_NAME/SNAPSHOT_NAME?wait_for_completion=true&pretty" -H 'Content-Type:application/json' -d'
{
"indices": "index_1,index_2",
"ignore_unavailable": true,
"include_global_state": false
}
'

Example

Registering snapshot for on-prem

curl -XPUT "localhost:9200/_snapshot/tenant-repo?pretty" -H 'Content-Type: application/json' -d'
{
"type": "s3",
"settings": {
"bucket": "tenant-snapshot",
"region": "us-west-2",
"access_key": "AKIAUZIOM7PN2URJHIPO",
"secret_key": "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"
}
}
'

Taking a snapshot(method-1)
curl -X PUT "localhost:9200/_snapshot/tenant-repo/tenant-snap01?wait_for_completion=true&pretty" -H 'Content-Type:application/json' -d'
{
"indices": "index_1,index_2",
"ignore_unavailable": true,
"include_global_state": false
}
'

Taking a snapshot(method-2)
curl -XPUT 'localhost:9200/_snapshot/tenant-repo/tenant-snap01'

To restore all the indices to target ES cluster:
Another process of repository registration and restoration.

Thanks.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.