Table of contents

Elasticsearch: dump and restore indices

Creating a dump

Sometimes you may need to take a backup of Elasticsearch before a critical operation and all Elasticsearch servers create their own nightly backups via the following cronjob:

$ sudo crontab -lu elasticsearch
/usr/bin/es_dump http://localhost:9200 /var/es_dump

The first argument is the Elasticsearch instance and the second is the directory in which to store the output. The user running the dump needs permission to write to this directory.

Restoring a dump

Restoring to an index which exists is additive - it doesn’t replace the existing data or delete any documents which don’t exist in the dump. This means that:

If you want to replace something, you have to delete it first:

$ curl -XDELETE 'http://localhost:9200/indexname/'

If the import fails (as it sometimes does), you can simply re-run the command.

Given a dump, which will typically be a zipfile, then it can be restored into Elasticsearch:

$ es_dump_restore http://localhost:9200/ <indexname>

Given a directory of dumps named after their respective indices, you can use the script to restore them.

This page is owned by #2ndline and needs to be reviewed