在ES中是有replica的存在的, 默认, 一个索引会分成5个shard,每个shard有一个replica.
replica机制使得ES有较好的容错机制,保证了数据的安全。
但是我们仍然觉得数据的备份是很有必要的(在replica之上的)。
ES提供了_snapshot的API,来支持数据的快照。snapshot支持多种文件系统,e.g. Shared filesystem, such as a NAS/AWS S3/HDFS等
要建立一个ES data的备份, 需要的步骤如下:
1. 建立一个repository,用于存在备份数据
repository的名字叫my_backup |
|
type of the repository should be a shared filesystem. |
|
And finally, we provide a mounted drive as the destination. 且该path能够被cluster内的所有nodes访问到。 |
2. 对某个索引或者所有索引建立一个snapshot
异步:PUT _snapshot/my_backup/snapshot_1
同步PUT _snapshot/my_backup/snapshot_1?wait_for_completion=true
为某个index建立snapshot
PUT _snapshot/my_backup/snapshot_2 { "indices": "index_1,index_2" }
3. 获取某个snapshot的信息
GET _snapshot/my_backup/snapshot_2
GET _snapshot/my_backup/_all
4. delete某个snapshot
DELETE _snapshot/my_backup/snapshot_2
5. 使用snapshot: restore
restore所有的索引:
POST _snapshot/my_backup/snapshot_1/_restore
POST _snapshot/my_backup/snapshot_1/_restore?wait_for_completion=true
restore某些索引:
POST /_snapshot/my_backup/snapshot_1/_restore { "indices": "index_1", "rename_pattern": "index_(.+)", "rename_replacement": "restored_index_$1" }
|
index_1 into your cluster, but rename it to restored_index_1 . |