because the company's Elasticsearch cluster only uses two servers. As long as one server data loss Elasticsearch will lose half the data. Therefore, the backup and recovery of data is very important. Elasticsearch snapshot and recovery modules can create a single index or a snapshot of the entire cluster to a remote repository for data backup and recovery.
The following is a backup recovery. Kibana Index as an example
Data backup and Recovery
1. Modify the Elasticsearch configuration file
Vim Elasticsearch.yml
Add Path.repo: ["/mnt/bak"]
#设置仓库路径
Note If you have more than one Ealsticsearch server as a cluster, you can first turn off the Shard server only on the master Master node server to change. or set up a shared folder before creating the library
2. Create a warehouse
Curl-xput http://192.168.10.49:9200/_snapshot/my_backup-d ' {"type": "FS", "Settings": {"Location": "/mnt /bak "," Compress ": true}} '
Returns the result {"acknowledged": true} after running the above command
Indicates that the warehouse was created successfully.
Compress whether to compress
Max_snapshot_bytes_per_sec the speed at which snapshots are made default 20mb/s
Max_restore_bytes_per_sec Snapshot recovery Speed default 20mb/s
View Warehouse
Curl-get http://192.168.10.49:9200/_snapshot{"My_backup": {"type": "FS", "Settings": {"compress": "true", "location": "/mnt/bak"}}}
3. Backup Data
Curl-xput http://192.168.10.49:9200/_snapshot/my_backup/snapshot_20161207
Executing the above command will snapshot all the indexes on the Ealsticsearch.
If you want the index specified by the snapshot
Curl-xput http://192.168.10.49:9200/_snapshot/my_backup/snapshot_20161207-d ' {"Indices": ". Kibana"} '
If the result is successfully returned {"Accepted": true}
4. View Backup
Curl-xget http://192.168.10.49:9200/_snapshot/my_backup/snapshot_20161207
This command is to view the snapshot in case the data returned is more
{"Snapshots": [{"snapshot": "snapshot_20161207", "version_id": 2030599, "version": "2.3.5", "indices": ["es-index-
......... Middle n rows of data .....
{"Total": $, "failed": 0, "successful": 37}}]}
You can also use the following command to view the status of a snapshot
curl -xget http://192.168.10.49:9200/_snapshot/my_backup/ snapshot_20161207/_status{"Snapshots": [{"snapshot": "snapshot_20161207", "Repository": "My_backup", "state": " SUCCESS "," Shards_stats ": {" initializing ": 0," Started ": 0," finalizing ": 0," Done ": 1," failed ": 0," Total ": 1}," stats ": {" Number_of_files ":" Processed_files ": +," total_size_in_bytes ": 143273," processed_size_in_bytes ": 143273," Start_ Time_in_millis ": 1481060674078," Time_in_millis ": []," indices ": {". Kibana ": {" shards_stats ": {" initializing ": 0," Started ": 0," finalizing ": 0," Done ": 1," failed ": 0," Total ": 1}," stats ": {" number_of_files ": +," processed_files ": 14," Total_size_in_bytes ": 143273," processed_size_in_bytes ": 143273," Start_time_in_millis ": 1481060674078," Time_in_ Millis ":", "shards": {"0": {"stage": "Done", "stats": {"number_of_files": +, "processed_files": +, "total_size_in_ Bytes ": 143273," processed_size_in_bytes ": 143273," Start_time_in_millis ": 1481060674078," Time_in_millis ": 50}}}}] }
5. Cancel Backup
Curl-xdelete http://192.168.10.49:9200/_snapshot/my_backup/snapshot_20161207
6. Restore Backup
Curl-xpost Http://192.168.10.49:9200/_snapshot/my_backup/snapshot_20160812/_restore
If you have a cluster and you do not configure a shared folder when you create the warehouse, the following error will be reported
{"Error": "repositoryexception[[my_backup] failed to create repository]; nested: CREATIONEXCEPTION[GUICE&NBSP;CREATION&NBSP;ERRORS:\N\N1) Error injecting constructor, ORG.ELASTICSEARCH.REPOSITORIES.REPOSITORYEXCEPTION:&NBSP;[MY_BACKUP]&NBSP;LOCATION&NBSP;[/MNT/BAK]&NBSP;DOESN ' t match any of the locations specified by path.repo because this setting is empty\n at org.elasticsearch.repositories.fs.fsrepository.< Init> (Unknown source) \n while locating org.elasticsearch.repositories.fs.fsrepository\n while locating Org.elasticsearch.repositories.repository\n\n1 error]; nested: repositoryexception[[my_backup] &NBSP;LOCATION&NBSP;[/MNT/BAK]&NBSP;DOESN ' t match any of the locations specified by path.repo because this setting is empty];&nbSP; "," Status ": 500}
Workaround Close Pivot Server Elasticsearch service re-execution is successful.
If it already exists. The Kibana index can be closed first.
After successful data recovery, only the primary node server exists. Kibana index. We want to execute the following command when all node servers are present at this index
Curl-xput ' http://192.168.10.49:9200/.kibanna/_settings '-d ' {"index": {"Number_of_replicas": 1}} '
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/8B/3F/wKiom1hHvBLRdaY3AAAapXtteRI780.png "title=" tw%4~ Y7d]%2kortwgb@9e7p.png "alt=" Wkiom1hhvblrday3aaaapxtteri780.png "/>
This article is from the "Tranquility Zhiyuan" blog, please be sure to keep this source http://irow10.blog.51cto.com/2425361/1880365
Elk Data Backup, migration, and recovery