elasticsearch 的备份

1.配置 path.repo
path.repo: ["/data/elasticsearch/repo","/workdata/esdata"]

2.创建测试数据

点击查看代码
PUT /person/_bulk
{"index":{"_index":"person"}}
{"name":"张三","age":20,"mail":"111@qq.com","hobby":"羽毛球,乒乓球,足球"}
{"index":{"_index":"person"}}
{"name":"李四","age":21,"mail":"222@qq.com","hobby":"羽毛球,乒乓球,足球,篮球"}
{"index":{"_index":"person"}}
{"name":"王五","age":22,"mail":"333@qq.com","hobby":"羽毛球,篮球,游泳,听音乐"}
{"index":{"_index":"person"}}
{"name":"赵六","age":23,"mail":"444@qq.com","hobby":"跑步,游泳"}
{"index":{"_index":"person"}}
{"name":"孙七","age":24,"mail":"555@qq.com","hobby":"听音乐,看电影"}

3.在ES创建 backup 目录

点击查看代码
put _snapshot/esbackup
{
  "type":"fs",
  "settings": {
    "location": "/workdata/esdata/backup",
    "compress": true
  }
}

4.对elasticsearch 进行备份
put /_snapshot/esbackup/es20211115121500?wait_for_completion=true

对指定索引备份
点击查看代码
put _snapshot/esbackup/person_snapshot_1?wait_for_completion=true
{
  "indices":"person",
  "ignore_unavailable":true,
  "clude_global_state":false,
  "metadata":{
    "taken_by":"Leo",
    "taken_beacause":"backup_for_upgrading"
  }
}

5 查看 备份

get _snapshot/esbackup/_all
get _snapshot/esbackup/person_snapshot_1

6 删除索引
delete person

7 恢复索引

点击查看代码
POSt _snapshot/esbackup/person_snapshot_1/_restore
{
  "indices":"person"
}

8 查看 恢复数据
get person/_search

posted on 2021-11-15 00:33  InnoLeo  阅读(579)  评论(0编辑  收藏  举报