美文网首页
Elasticsearch快照使用

Elasticsearch快照使用

作者: limx | 来源:发表于2019-08-27 11:58 被阅读0次

    1、修改配置文件:

    path.repo: /data/snapshot # 先创建这个目录存放快照, mkdir /data/snapshot

    2、创建仓库:

    curl -XPUT http://localhost:9200/_snapshot/backup -d '

    {

      "type":"fs",

      "settings":{"location":"/data/snapshot","compress": true}

    }'

    curl -XPUT http://localhost:9200/_snapshot/backup -H "Content-Type: application/json" -d '

    {

      "type":"fs",

      "settings":{"location":"/data/snapshot","max_snapshot_bytes_per_sec" : "1000mb","max_restore_bytes_per_sec" : "1000mb","compress" : true}

    }'

    3、如果需要可以更新仓库:

    curl -XPOST http://localhost:9200/_snapshot/backup/ -d '

    {

      "type": "fs",

      "settings": {

        "location": "/data/snapshot",

        "max_snapshot_bytes_per_sec" : "100mb",

        "max_restore_bytes_per_sec" : "100mb",

        "compress" : true

      }

    }'

    4、创建快照:

    curl -XPUT http://localhost:9200/_snapshot/backup/snapshot1?wait_for_completion=true # 创建一个名称为snapshot1的快照,通常你会希望你的快照作为后台进程运行,不过有时候你会希望在你的脚本中一直等待到完成。这可以通过添加一个 wait_for_completion 标记实现。

    time curl -XPUT http://localhost:9200/_snapshot/backup/snapshot2?wait_for_completion=true -d '{"indices": "fofapro,index2"}' # 只快照某些索引

    5、查看快照的状态: 

    curl -XGET http://localhost:9200/_snapshot/backup/_all?pretty=true # 查看所有快照状态

    6、查看快照的进度等信息:GET http://localhost:9200/_snapshot/backup/snapshot3/_status # snapshot_3 是快照名称

    7、快照恢复:

    curl -XPOST http://localhost:9200/_snapshot/backup/snapshot1/_restore?wait_for_completion=true

    恢复某个索引

    time curl -XPOST " http://localhost:9200/_snapshot/backup/snapshot4/_restore?wait_for_completion=true" -d '{

      "indices": "netinfo-2016.12.21",

      "ignore_unavailable": "true",

      "include_global_state": false,

      "rename_pattern": "netinfo-2016.12.21",

      "rename_replacement": "netinfotest"

    }'

     这时有可以会报错:cannot restore index because it's open

    需要先关闭所有索引:

    curl  -XPOST  http://localhost:9200/index_name/_close

    curl  -XPOST  http://localhost:9200/_all/_close

    因为做快照时,索引是打开的,恢复过后索引也是打开的。

    8、删除快照:

    curl -XDELETE http://localhost:9200/_snapshot/backup/snapshot1 #取消快照也是同样的操作

    9、删除仓库:

    curl -XDELETE http://localhost:9200/_snapshot/backup

    相关文章

      网友评论

          本文标题:Elasticsearch快照使用

          本文链接:https://www.haomeiwen.com/subject/jdisectx.html