Snapshot 备份还原
ElasticSearch    2018-09-01 00:40:10    1    0    0
cqc   ElasticSearch

注册一个仓库

PUT /_snapshot/my_backup
{
  "type": "fs",
  "settings": {
        ... repository specific settings ...
  }}
PUT /_snapshot/backup
 {
   "type": "fs",
   "settings": {
     "location": "backup",
     "compress": true
   }
 }

当仓库注册成功后,可通过该方法查看仓库设置
GET /_snapshot/backup

可通过以下方法查看当前注册的所有仓库
GET /_snapshot
GET /_snapshot/_all

在注册仓库时,在选择仓库数据保存方式为 type:fs时,需要在elasticsearch.yml配置文件中设置仓库的主目录
path.repo: ["/mount/backups", "/mount/longterm_backups"]
在注册仓库时,settings可以有如下参数:

location

Location of the snapshots. Mandatory.

compress

Turns on compression of the snapshot files. Compression is applied only to metadata files (index mapping and settings). Data files are not compressed. Defaults to true.

chunk_size

Big files can be broken down into chunks during snapshotting if needed. The chunk size can be specified in bytes or by using size value notation, i.e. 1g, 10m, 5k. Defaults to null (unlimited chunk size).

max_restore_bytes_per_sec

Throttles per node restore rate. Defaults to 40mb per second.

max_snapshot_bytes_per_sec

Throttles per node snapshot rate. Defaults to 40mb per second.

readonly

Makes repository read-only. Defaults to false.
可对注册的仓库进行正常功能进行验证,以下方法当正常时返回所有节点的信息当不正常时返回错误问题
POST /_snapshot/s3_repository/_verify

可对当前es集群执行snapshot快照(实际就是备份)操作
PUT /_snapshot/backup/20160804?wait_for_completion=true
snapshot name在一个仓库中必须是唯一的.wait_for_completion参数是指是否需要阻塞直到执行完成(由于该操作是占用资源池,当需要执行大量的操作时,最好不要阻塞,可通过另一个方式来查询执行状态)

正常snapshot操作将对集群中所有已经打开的index进行snapshot操作. 可以通过指定index名称来对个别index进行操作
PUT /_snapshot/my_backup/snapshot_1
{
  "indices": "index_1,index_2",
  "ignore_unavailable": "true",
  "include_global_state": false}
include_global_state是指集群的状态是否需要写入到快照中,我个人觉得有必要写入,这个可以保存更完整的信息. 当还原时还可选择是否还原集群状态
在一个集群中,有且仅有一条的快照操作

查看snapshot信息可通过
GET /_snapshot/my_backup/snapshot_name
GET /_snapshot/my_backup/_all(查所有)

DELETE /_snapshot/my_backup/snapshot_name 删除一个快照
DELETE /_snapshot/my_backup 删除一个仓库

POST /_snapshot/my_backup/snapshot_1/_restore 还原

POST /_snapshot/backup/20160804/_restore?wait_for_completion=true
{
  "indices": "log_init",
  "include_global_state": false,
  "index_settings": {
    "index.number_of_replicas": 0
  }
}


上一篇: Setup 安装

下一篇: Index 索引

文档导航