Skip to content

Instantly share code, notes, and snippets.

@khaledosman
Last active April 3, 2019 16:44
Show Gist options
  • Save khaledosman/d95e333359760856ce4b10cdf0a7db75 to your computer and use it in GitHub Desktop.
Save khaledosman/d95e333359760856ce4b10cdf0a7db75 to your computer and use it in GitHub Desktop.

S3 Repository

  • Both Local And Remote *
  1. sudo bin/elasticsearch-plugin install repository-s3 (or setup from config / yaml file if docker)
  2. run elastic-search (./bin/elastic)
  3. Create s3 bucket
  4. Create IAM role with access to the s3 bucket and copy his access & secret keys
  5. Add your credentials to elastic search configuration or via config/ elastic-search.yaml file
bin/elasticsearch-keystore add s3.client.default.access_key
bin/elasticsearch-keystore add s3.client.default.secret_key
  1. Create a Snapshot repository PUT localhost:9200/_snapshot/<repo-name>
{
  "type": "s3",
  "settings": {
    "bucket": "<bucket-name>",
    "region": "<aws-region>",
   // "access_key": "AWS_ACCESS_KEY",
   // "secret_key": "AWS_SECRET_KEY",
    "compress": true
  }
}
  • Remote *
  1. Create Snapshot in that repository PUT localhost:9200/_snapshot/<repo-name>/<snapshot-name>
  • Local *
  1. Restore a snapshot POST localhost:9200/_snapshot/<repo-name>/<snapshot-name>/_restore

Local Repository

  1. Configure the local repo path from elastic-search.yml file by adding path.repo: ["<your backup dir name>"]
  2. Create a fs snapshot repository PUT http://localhost:9200/_snapshot/<repo-name>
{
  "type": "fs",
  "settings": {
    "location": "my_backup_location"
  }
}
  1. Move existing backup content to that directory. (The directory name = {one you created from step1}/{location from step2}) or download backup content from s3 via aws-cli aws s3 sync s3://<Bucket-Name> <Local-Dir-Name>/
  2. List all snapshots in the repository GET /_snapshot/localbackup/_all
  3. Restore a snapshot POST localhost:9200/_snapshot/<repo-name>/<snapshot-name>/_restore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment