Create and restore application backups


Elasticsearch provides a snapshot function that you can use to back up your data. Follow these steps:

  • Register a repository where the snapshot will be stored. This may be a local directory or cloud storage (which requires additional plugins). In this example, we will use a local repository. Create the directory and set the correct permissions:

      $ cd /home/bitnami
      $ mkdir backups
      $ sudo chown elasticsearch:bitnami /home/bitnami/backups/
      $ sudo chmod u+rwx /home/bitnami/backups/
  • Update the /opt/bitnami/elasticsearch/config/elasticsearch.yml file and add the path.repo variable to it as shown below, pointing to the above repository location:

      path.repo: ["/home/bitnami/backups"]
  • Restart Elasticsearch:

      $ sudo service bitnami restart elasticsearch
  • Initialize the repository via the Elasticsearch REST API with the following commands:

      $ curl -XPUT 'http://localhost:9200/_snapshot/my_backup' -H 'Content-Type: application/json' -d'{

    IMPORTANT: The location property is set to a directory relative to the path.repo location. This location must be registered in the path.repo setting on all cluster nodes.

    In this example, my_backup is the name of the backup repository.

    See registered repositories with this command:

      $ curl -XGET 'http://localhost:9200/_snapshot?pretty'
  • Once the repository is registered, launch the backup with the following command:

      $ curl -XPUT 'localhost:9200/_snapshot/my_backup/snapshot_1?wait_for_completion=true&pretty'

    In this example, my_backup is the name of the repository created previously and snapshot_1 is the name for the backup. The wait_for_completion option will block the command line until the snapshot is complete. To create the snapshot in the background, simply omit this option, as shown below:

      $ curl -XPUT 'localhost:9200/_snapshot/my_backup/snapshot_1'


To restore a backup over existing data, follow these steps:

  • Close the specific indices that will be overwritten with this command:

      $ curl -XPOST 'localhost:9200/my_index/_close'

    Optionally, close all indices:

      $ curl -XPOST 'localhost:9200/_all/_close'
  • Restore the backup with the following command. This command will also reopen the indices closed before.

      $ curl -XPOST 'localhost:9200/_snapshot/my_backup/snapshot_1/_restore'

For more information, refer to the official documentation.

Last modification October 2, 2019