elasticsearch 快照及从快照中恢复数据

集群使用sanpshot快照需要共享文件系统,所以要先配置个nfs

####elastichsearch配置 实验使用1.6的elasticsearch,发现需要在master的elasticsearch.yml中添加path.repo:/data/app/snapshot后重启es后才能创建仓库

####安装nfs

# yum install nfs-utils -y

# mkdir /data/app/es_snapshot

# vi /etc/exports

/data/app/es_snapshot 192.168.10.*(rw,sync,no_root_squash)

# setenforce 0

# service rpcbind start

# service nfs start

####所有es挂载nfs

# mkdir -p /data/app/snapshot

# yum install nfs-utils -y

# mount 192.168.10.94:/data/app/es_snapshot/ /data/app/snapshot/

####开启快照

  • 查看快照仓库

快照仓库为空

# curl http://192.168.10.91:9200/_snapshot/

{}

  • 创建快照,设置快照目录

# curl -XPUT http://192.168.10.91:9200/_snapshot/snapshot1 -d '{"type":"fs","settings":{"location":"/data/app/snapshot/","compress":"true"}}'

{"acknowledged":true}
  • 再次查询仓库

# curl http://192.168.10.91:9200/_snapshot/

{"snapshot1":{"type":"fs","settings":{"compress":"true","location":"/data/app/snapshot/"}}}
  • 快照备份

# curl -XPUT http://192.168.10.91:9200/_snapshot/snapshot1/backup1?wait_for_completion=true #等待快照完成后返回

{"snapshot":{"snapshot":"backup1","indices":["index1","index2"],"state":"SUCCESS","start_time":"2016-04-14T14:21:41.094Z","start_time_in_millis":1460643701094,"end_time":"2016-04-14T14:21:41.545Z","end_time_in_millis":1460643701545,"duration_in_millis":451,"failures":[],"shards":{"total":10,"failed":0,"successful":10}}}
  • 查看快照

# curl http://192.168.10.91:9200/_snapshot/snapshot1/_all?pretty=true

  "snapshots" : [ {
    "snapshot" : "backup1",
    "indices" : [ "index1", "index2" ],
    "state" : "SUCCESS",
    "start_time" : "2016-04-14T14:21:41.094Z",
    "start_time_in_millis" : 1460643701094,
    "end_time" : "2016-04-14T14:21:41.545Z",
    "end_time_in_millis" : 1460643701545,
    "duration_in_millis" : 451,
    "failures" : [ ],
    "shards" : {
      "total" : 10,
      "failed" : 0,
      "successful" : 10
    }
  }, {
    "snapshot" : "backup2",
    "indices" : [ "index1", "index2" ],
    "state" : "SUCCESS",
    "start_time" : "2016-04-14T14:22:02.182Z",
    "start_time_in_millis" : 1460643722182,
    "end_time" : "2016-04-14T14:22:02.366Z",
    "end_time_in_millis" : 1460643722366,
    "duration_in_millis" : 184,
    "failures" : [ ],
    "shards" : {
      "total" : 10,
      "failed" : 0,
      "successful" : 10
    }
  } ]
}
  • 删除快照

# curl -XDELETE http://192.168.10.91:9200/_snapshot/snapshot1/backup1

{"acknowledged":true}
  • 从快照恢复

# curl -XDELETE http://192.168.10.91:9200/* 删除重名的index,不然恢复会报错

# curl -XPOST http://192.168.10.91:9200/_snapshot/snapshot1/backup2/_restore?wait_for_completion=true #恢复

{"snapshot":{"snapshot":"backup2","indices":["index1","index2"],"shards":{"total":10,"failed":0,"successful":10}}}

转载于:https://my.oschina.net/u/1791060/blog/659334

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值