Friday, August 21, 2015

Backup and Restore ElasticSearch Indices

This instructions are very basic and intended for someone who is new to ElasticSearch.

To backup and restore elasticsearch data follow these steps:

Source Server:
1.       In source server, ensure the path.repo is configured in the elasticsearch.yml (found in elasticsearch-<version>\config folder)
Example: Add this line at the end of elasticsearch.yml
path.repo: [ "C:\\ESBkup" ]
NOTE: This can be a network path too.
2.       Create the repository
Example:
PUT _snapshot/mybackup
{
  "type": "fs",
  "settings": {
      "location": "/ESBkup/mybackup"
    }
}
        NOTE: The path starts from the ESBkup
3.       Create the snapshot
PUT _snapshot/mybackup/snapshot_1?wait_for_completion=true
4.       Now you can open and see the C:\ESBkup folder and notice all the indices are backed up. You can copy the entire ESB folder to the target server.

Target Server:
1.       In target server, ensure the path.repo is configured in the elasticsearch.yml  as above. The path should be the same folder where you have copied the snapshot files from source server.
2.       Create the repository as above.
3.       Example:
PUT _snapshot/mybackup
{
  "type": "fs",
  "settings": {
      "location": "mybackup"
    }
}
                NOTE: the location is the direct snapshot folder and its not starting from the root folder (ESB).
4.       Now you can query the snapshot to find out what indices it has:
GET _snapshot/mybackup/_all
5.       To restore backup
POST /_snapshot/mybackup/snapshot_1/_restore?wait_for_completion=true
{
  "indices": "indexA,indexB,indexC"
}
                NOTE: you can use the indices to selectively restore indices


There are far more capabilities in ElasticSearch such as asynchronously triggering and monitoring snapshot backup etc. Refer to ElasticSearch documentation for more details.  

No comments:

Post a Comment