快照仓库

注册快照存储库

POST _snapshot/my_backup 
{
    "type": "fs", 
    "settings": {
        "location": "/mount/backups/my_backup",
         "max_snapshot_bytes_per_sec" : "50mb", 
         "max_restore_bytes_per_sec" : "50mb"
    }
}

POST _snapshot/search_user_v6
{
    "type": "fs",
    "settings": {
      "location": "search_user_v6",
      "max_restore_bytes_per_sec": "60mb",
      "compress": "true",
      "max_snapshot_bytes_per_sec": "60mb"
    }
  }
  • my_backup 仓库的名字
  • max_snapshot_bytes_per_sec:当快照数据进入仓库时,这个参数控制这个过程的限流情况。默认是每秒 20mb
  • max_restore_bytes_per_sec:当从仓库恢复数据时,这个参数控制什么时候恢复过程会被限流以保障你的网络不会被占满。默认是每秒 20mb

查看所有快照仓库

GET /_snapshot/_all

删除快照仓库

DELETE /_snapshot/my_repository

快照

创建快照

备份单个索引

备份 index_1,index_2 索引到my_repository 仓库下,命名为:status_v7_snapshot

PUT /_snapshot/my_repository/status_v7_snapshot
{
  "indices":"index_1,index_2",
  "ignore_unavailable":true,
  "include_global_state":true
}

备份所有索引

备份所有打开的索引到 my_backup 仓库下命名为:snapshot_1

PUT _snapshot/my_backup/snapshot_1?wait_for_completion=true
  • wait_for_completion:这个会阻塞调用直到快照完成。注意大型快照会花很长时间才返回。

查看备份信息

GET _snapshot/my_backup/snapshot_2

返回结果

{
   "snapshots": [
      {
         "snapshot": "snapshot_1",
         "indices": [
            ".marvel_2014_28_10",
            "index1",
            "index2"
         ],
         "state": "SUCCESS",
         "start_time": "2014-09-02T13:01:43.115Z",
         "start_time_in_millis": 1409662903115,
         "end_time": "2014-09-02T13:01:43.439Z",
         "end_time_in_millis": 1409662903439,
         "duration_in_millis": 324,
         "failures": [],
         "shards": {
            "total": 10,
            "failed": 0,
            "successful": 10
         }
      }
   ]
}

查看 my_backup 仓库中所有快照

GET _snapshot/my_backup/_all

删除快照

删除 my_backup 仓库中 snapshot_2 备份

DELETE _snapshot/my_backup/snapshot_2

监控快照进度

_status API 立刻返回

GET _snapshot/my_backup/snapshot_3/_status

返回结果

{
   "snapshots": [
      {
         "snapshot": "snapshot_3",
         "repository": "my_backup",
1.         "state": "IN_PROGRESS", 
         "shards_stats": {
            "initializing": 0,
2.            "started": 1, 
            "finalizing": 0,
            "done": 4,
            "failed": 0,
            "total": 5
         },
         "stats": {
            "number_of_files": 5,
            "processed_files": 5,
            "total_size_in_bytes": 1792,
            "processed_size_in_bytes": 1792,
            "start_time_in_millis": 1409663054859,
            "time_in_millis": 64
         },
         "indices": {
            "index_3": {
               "shards_stats": {
                  "initializing": 0,
                  "started": 0,
                  "finalizing": 0,
                  "done": 5,
                  "failed": 0,
                  "total": 5
               },
               "stats": {
                  "number_of_files": 5,
                  "processed_files": 5,
                  "total_size_in_bytes": 1792,
                  "processed_size_in_bytes": 1792,
                  "start_time_in_millis": 1409663054859,
                  "time_in_millis": 64
               },
               "shards": {
                  "0": {
                     "stage": "DONE",
                     "stats": {
                        "number_of_files": 1,
                        "processed_files": 1,
                        "total_size_in_bytes": 514,
                        "processed_size_in_bytes": 514,
                        "start_time_in_millis": 1409663054862,
                        "time_in_millis": 22
                     }
                  },
                  ...
  1. 一个正在运行的快照会显示 IN_PROGRESS 作为状态。
  2. 这个特定快照有一个分片还在传输(另外四个已经完成)。

取消一个快照

取消正在备份的快照:直接删除就可以了。

DELETE _snapshot/my_backup/snapshot_3

从快照恢复

恢复

默认将快照里所有的索引都恢复

POST _snapshot/my_backup/snapshot_1/_restore

指定恢复索引

这个会恢复 index_1 到你及群里,但是重命名成了 restored_index_1

POST /_snapshot/my_backup/snapshot_1/_restore
{
1    "indices": "index_1", 
2    "rename_pattern": "index_(.+)", 
3    "rename_replacement": "restored_index_$1" 
}
  1. 只恢复 index_1 索引,忽略其他索引。
  2. 模式能匹配上的正在恢复的索引。
  3. 然后把它们重命名成替代的模式。

监控

监控 restored_index_3 索引恢复情况

GET restored_index_3/_recovery

查看你集群里所有索引

GET /_recovery/

返回结果

{
  "restored_index_3" : {
    "shards" : [ {
      "id" : 0,
1      "type" : "snapshot", 
      "stage" : "index",
      "primary" : true,
      "start_time" : "2014-02-24T12:15:59.716",
      "stop_time" : 0,
      "total_time_in_millis" : 175576,
2      "source" : { 
        "repository" : "my_backup",
        "snapshot" : "snapshot_3",
        "index" : "restored_index_3"
      },
      "target" : {
        "id" : "ryqJ5lO5S4-lSFbGntkEkg",
        "hostname" : "my.fqdn",
        "ip" : "10.0.1.7",
        "name" : "my_es_node"
      },
      "index" : {
        "files" : {
          "total" : 73,
          "reused" : 0,
          "recovered" : 69,
3          "percent" : "94.5%" 
        },
        "bytes" : {
          "total" : 79063092,
          "reused" : 0,
          "recovered" : 68891939,
          "percent" : "87.1%"
        },
        "total_time_in_millis" : 0
      },
      "translog" : {
        "recovered" : 0,
        "total_time_in_millis" : 0
      },
      "start" : {
        "check_index_time" : 0,
        "total_time_in_millis" : 0
      }
    } ]
  }
}
  1. type 字段告诉你恢复的本质;这个分片是在从一个快照恢复。
  2. source 哈希描述了作为恢复来源的特定快照和仓库。
  3. percent 字段让你对恢复的状态有个概念。这个特定分片目前已经恢复了 94% 的文件;它就快完成了。

取消恢复

取消正在备份的快照:直接删除就可以了。

DELETE /restored_index_3

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部