in DevOps

Snapshot Elasticsearch in AWS S3

Snapshot and Restore Elasticsearch 5.x in S3.

Register S3 repository

curl -XPUT 'http://localhost:9200/_snapshot/s3_backup' -d '{
    "type": "s3",
    "settings": {
        "access_key": "ACCESS_KEY_TOCKEN",
        "secret_key": "SECURITY_KEY_TOCKEN",
        "bucket": "es-backups",  
        "region": "us-west-1",
        "base_path": "elasticsearch",
        "max_retries": 3
    }
}'
Response->{"acknowledged":true}

Create a Snapshot

#For all indices
curl -XPUT http://localhost:9200/_snapshot/s3_backup/backup_1/\?wait_for_completion=true
# Or for specific indices
curl -XPUT 'http://localhost:9200/_snapshot/s3_backup/backup_1?wait_for_completion=true' -d '{
    "indices": "your_index1, your_index2",
    "ignore_unavailable": "true",
    "include_global_state": false
}'
Set "wait_for_completion=false" to run snapshot in background.

Restoring

curl -XPOST 'http://localhost:9200/_snapshot/s_backup/backup_1/_restore' -d '{
    "indices": "your index",
    "ignore_unavailable": "true",
    "include_global_state": false
}'

Some commands to view information

#List all registries
curl -X GET http://localhost:9200/_snapshot/_all?pretty=true
#List all snapshot
curl -XGET "http://localhost:9200/_snapshot/s3_backup/_all"
#View status
curl -XGET "http://localhost:9200/_snapshot/s3_backup/backup_1/_status"
#Detail information of snapshot
curl -XGET "http://localhost:9200/_snapshot/s3_backup/backup_1"
#Delete a snapshot
curl -XDELETE "http://localhost:9200/_snapshot/s3_backup/backup_1"
#Delete all snapshot
curl -XDELETE "http://localhost:9200/_snapshot/s3_backup"