Backing Up Elasticsearch Example

We cannot simply copy the data from es data dirs, because it could result in corrupt indices and missing data. Instead we will be using the ‘snapshot’ api of ES to create and restore backups (i.e. snapshots).

More on: elasticsearch snapshot api.

Testing ES Snapshot

See also the production example, backup-prod.sh and restore-prod.sh.

ES_URL=$(docker port tr_elasticsearch 9200)

# register a snapshot repository
curl -XPUT $ES_URL/_snapshot/backup \
  -H 'content-type:application/json' \
  -d '{"type":"fs","settings":{"location":"/backup"}}'

# create a snapshot:
curl -XPUT "$ES_URL/_snapshot/backup/snapshot_1?wait_for_completion=true" | jq

# when starting with fresh es install, first restore snapshot repository:
curl -XPUT $ES_URL/_snapshot/backup \
  -H 'content-type:application/json' \
  -d '{"type":"fs","settings":{"location":"/backup"}}'

# and restore snapshot:
curl -XPOST "$ES_URL/_snapshot/backup/snapshot_1/_restore" \
  -H 'content-type:application/json' \
  -d '{}'