快照和恢复模块可以将单个索引或者整个集群做一个快照并存放到远程仓库上。目前支持共享文件系统仓库和官方通过插件方式提供的其他仓库。
1、仓库注册
在创建或恢复仓库数据之前,首先需要到ElasticSearch里进行注册,如下命令用my_backup注册一个共享文件系统,快照数据将存放在/mount/backups/my_bakup上:
1
2
3
4
5
6
7
8
9
10 1 $ curl -XPUT 'http://localhost:9200/_snapshot/my_backup' -d '
2{
3 "type": "fs",(共享的文件系统仓库)
4 "settings": {
5 "location": "/mount/backups/my_backup", (快照存放位置)
6 "compress": true (快照是否压缩,默认true)
7
8 }
9}'
10
2、查看仓库信息:
1
2
3
4
5
6
7
8
9
10
11 1$ curl -XGET 'http://localhost:9200/_snapshot/my_backup?pretty'
2{
3 "my_backup" : {
4 "type" : "fs",
5 "settings" : {
6 "compress" : "true",
7 "location" : "/mount/backups/my_backup"
8 }
9 }
10}
11
3、创建快照
同一个集群中,一个仓库中可以存放多个快照。快照在集群中的名称是唯一的。使用下面命令创建快照名为snapshot_1的快照:
1
2
3
4
5
6 1$ curl -XPUT "localhost:9200/_snapshot/my_backup/snapshot_1"-d '{
2 "indices": "index_1,index_2",
3 "ignore_unavailable": "true",
4 "include_global_state": false
5}'
6
4、查看快照信息:
1
2 1 $ curl -XGET "localhost:9200/_snapshot/my_backup/snapshot_1"
2
5、快照恢复
1
2
3
4
5
6
7
8 1$ curl -XPOST "localhost:9200/_snapshot/my_backup/snapshot_1/_restore"-d '{
2 "indices": "index_1,index_2",
3 "ignore_unavailable": "true",
4 "include_global_state": false,
5 "rename_pattern": "index_(.+)",
6 "rename_replacement": "restored_index_$1"
7}'
8
6、监控快照创建或恢复过程
1
2 1$ curl -XGET "localhost:9200/_snapshot/my_backup/snapshot_1/_status"
2
1
2 1</pre><div style="background:#F0F0F0"><pre>
2
1
2 1 【参考】: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index.html
2