Elasticsearch data backup and recovery operation guide
# Elasticsearch data backup and recovery operation guide
Elasticsearch is an open source distributed search engine, which is very suitable for searching, analysis and storage on large -scale data sets.When you use Elasticsearch, data backup and recovery are very important operations.This article will guide you how to backup and restore Elasticsearch data.
## data backup
### snapshot and restore function
Elasticsearch provides snapshots and restore functions. Through these functions, it can be easily backed up and restored to Elasticsearch indexes.
#### Configuration of the repository
Before using a snapshot and restore function, you need to configure a repository to store the reserve file.The repository can be a local file system, a remote file system or a cloud storage.Below is an example of using a local file system as a repository:
PUT _snapshot/my_backup
{
"type": "fs",
"settings": {
"location": "/path/to/backup/folder"
}
}
You can replace the `My_backup` into your favorite repository name, and replace the`/path/to/backup/folder` with the path you want to save the file.
#### Create a snapshot
Once the repository configuration is completed, you can create a snapshot.Below is a snapshot named `my_snapshot`:
PUT _snapshot/my_backup/my_snapshot
This command will create a snapshot called `my_snapshot` and store it in the repository of the` My_backup`.
### Data Recovery
#### Return to snapshot
To restore the snapshots created before, you can use the following command:
POST _snapshot/my_backup/my_snapshot/_restore
This command will restore the `My_SNAPSHOT snapshot in the repository of the repository of the repository.
## automatic backup
In addition to creating express photos manually, you can also automatically backup through the API of Elasticsearch.The following is an example. Demonstration of how to use timing tasks to automatically create snapshots:
#### Configuration timing task
Before creating a fixed task, you need to set the following parameters in the configuration file of elasticsearch.yml` in Elasticsearch.yml`:
xpack.ilm.enabled: true
xpack.ilm.rollover_alias: "my_index"
xpack.snapshot.policy.my_policy.schedule: "0 0 1 * * ?"
In the above configuration, `mypolicy` is your custom strategy name,` my_index` is your index aliases, `0 0 1 * *?
#### Perform timing snapshots
You can use the following API to execute timing snapshots:
POST _snapshot/my_backup/_execute
This command will execute a timing snapshot called `my_snapshot` and store it in the` My_backup` in the repository.
## Summarize
In this article, we introduce how to backup and restore Elasticsearch data through snapshots and restoration functions.We also discussed how to automatically create snapshots with timing tasks.Backup and recovery are an important step to ensure your data security. I hope this article will help you.