Elasticsearch数据如何备份

在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,用于存在备份数据

PUT _snapshot/my_backup 
{
    "type": "fs", 
    "settings": {
        "location": "/mount/backups/my_backup" 
    }
}

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" 
}

Restore only the index_1 index, ignoring the rest that are present in the snapshot.

Find any indices being restored that match the provided pattern.

Then rename them with the replacement pattern.

This will restore index_1 into your cluster, but rename it to restored_index_1.


猜你喜欢

转载自blog.csdn.net/smithallenyu/article/details/52093730