vmwareelasticsearch

Create and restore application backups

Backup

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, which can be initialized via the Elasticsearch REST API with the following commands:

    $ 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 /opt/bitnami/ctlscript.sh restart elasticsearch
    
  • Initialize the repository via the Elasticsearch REST API with the following commands:

    $ curl -H 'Content-Type: application/json' -XPUT 'http://localhost:9200/_snapshot/my_backup' -d '{
        "type":"fs",
        "settings":{
            "location":"/home/bitnami/backups/my_backup",
            "compress":true
        }
    }'
    

    The location property has to be set to the absolute path to the backup files. 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'
    

Restore

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