快照和恢复Snapshot And Restore

2019-09-12 15:50发布

快照和恢复Snapshot And Restore

查看库

GET /_snapshot/my_backup
GET /_snapshot/repo*,*backup*
GET /_snapshot
GET /_snapshot/_all

返回如下

{

  "my_backup": {

    "type": "fs",

    "settings": {

      "location": "my_backup_location"

    }

  }

}

配置(所有master和data节点)

Assuming that the shared filesystem is mounted to /mount/backups/my_fs_backup_location, the following setting should be added to elasticsearch.yml file:

path.repo: ["/mount/backups", "/mount/longterm_backups"]

注册库

PUT /_snapshot/my_fs_backup

{

    "type": "fs",

    "settings": {

        "location": "/mount/backups/my_fs_backup_location",

        "compress": true

    }

}

使用相对路径则相对于path.repo配置的第一个参数

PUT /_snapshot/my_fs_backup

{

    "type": "fs",

    "settings": {

        "location": "my_fs_backup_location",   # 快照存放位置

        "compress": true      # 是否压缩metadata ,默认true

    }

}

快照

一个库可以有多个快照

在my_backup库中创建snapshot_1 快照

PUT /_snapshot/my_backup/snapshot_1

指定索引快照

PUT /_snapshot/my_backup/snapshot_2

{

  "indices": "index_1,index_2",

  "ignore_unavailable": true,   # 默认没有设置,遇到indices that do not exist snapshot request will fail

  "include_global_state": false,

  "metadata": {

    "taken_by": "kimchy",

    "taken_because": "backup before upgrading"

  }

按日期创建快照

# PUT /_snapshot/my_backup/

PUT /_snapshot/my_backup/%3Csnapshot-%7Bnow%2Fd%7D%3E

索引快照过程是增量的

快照过程以非阻塞方式执行。可以继续针对正在创建快照的索引执行所有索引和搜索操作。但是快照进程启动后添加到索引的记录将不会出现在快照中。

对于已启动且当前未重定位的主分片,Elasticsearch(1.2.0版本之后)在快照之前等待重新分配或初始化分片。

任何时候只能在群集中执行一个快照过程。在创建特定分片的快照时,此分片无法移动到另一个节点

查看快照

GET /_snapshot/my_backup/snapshot_1

GET / _snapshot / my_backup / _all 

GET / _snapshot / my_backup / snapshot _ *,some_other_snapshot 

查看正在运行的快照

GET / _snapshot / my_backup / _current 

删除快照

DELETE / _snapshot / my_backup / snapshot_2 

删除快照还可以取消快照(快照期间创建的文件会被清除)

注销库

DELETE /_snapshot/my_backup

取消注册存储库时,Elasticsearch仅删除对存储库存储快照的位置的引用(only removes the reference to the location where the repository is storing the snapshots)。快照本身保持不变。

快照恢复

默认恢复所有所有,并且

POST /_snapshot/my_backup/snapshot_1/_restore

默认情况下,将恢复快照中的所有索引,并且不会还原群集状态 

POST /_snapshot/my_backup/snapshot_1/_restore

{

  "indices": "index_1,index_2",

  "ignore_unavailable": true,     # 

  "include_global_state": true,

  "include_aliases": false,  # 防止别名与关联索引一起恢复

  "rename_pattern": "index_(.+)",

  "rename_replacement": "restored_index_$1"   # $1表示rename_pattern中第一个括号内容,$2以此类推

}

所以只有在关闭或者不存在的情况下才能被恢复,恢复之后自动打开

查看快照状态

GET /_snapshot/_status

GET /_snapshot/my_backup/_status

GET /_snapshot/my_backup/snapshot_1/_status

GET /_snapshot/my_backup/snapshot_1,snapshot_2/_status



登录 后发表评论
0条评论
还没有人评论过~