elasticsearch 快照及從快照中恢復數據

集羣使用sanpshot快照須要共享文件系統,因此要先配置個nfsapp

####elastichsearch配置 實驗使用1.6的elasticsearch,發現須要在master的elasticsearch.yml中添加path.repo:/data/app/snapshot後重啓es後才能建立倉庫curl

####安裝nfselasticsearch

# yum install nfs-utils -yurl

# mkdir /data/app/es_snapshotrest

# vi /etc/exportscode

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

# setenforce 0rpc

# service rpcbind startget

# service nfs startit

####全部es掛載nfsio

# 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}}}
相關文章
相關標籤/搜索