はじめに
参考
とりあえず試す
インストール
cd /usr/share/elasticsearch sudo bin/plugin -install elasticsearch/elasticsearch-cloud-aws/2.0.0.RC1
elasticsearch.yml の設定
/etc/elasticsearch/elasticsearch.yml に S3 への接続に必要なアクセスキーとシークレットキーを設定する。
cloud:
aws:
access_key: AKxxxxxxxxxxxxxxxxxx
secret_key: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
設定後、念のために elasticsearch を再起動する。
リポジトリの登録
先ほどのローカルホストにリポジトリを登録したのと同じようにリポジトリを登録する。
curl -XPUT 'http://localhost:9200/_snapshot/my_s3_repository' -d '{
"type": "s3",
"settings": {
"bucket": "elasticsearch-snapshot",
"region": "ap-northeast-1"
}
}'
ローカルホストの時と異なるのが type が S3 になっている点、bucket と region の指定が必要となる。正常に登録出来ると以下のように出力される。
{"acknowledged":true}
スナップショット
後は前回と同じようにスナップショットを取得する。
curl -XPUT localhost:9200/_snapshot/my_s3_repository/snapshot_20140204
正常に終了すると以下のようなレスポンスが出力される。
{"accepted":true}
こわごわ S3 のバケットを確認すると...

おお、まじかよ...素晴らし。aws-cli でも確認してみる。
aws s3api list-objects --bucket elasticsearch-snapshot | jq '.Contents[]|.Key'
以下のように出力れる。
"index" "indices/test01/0/__0" "indices/test01/0/snapshot-snapshot_20140204" "indices/test01/1/__0" "indices/test01/1/snapshot-snapshot_20140204" "indices/test01/2/__0" "indices/test01/2/__1" "indices/test01/2/__2" "indices/test01/2/__3" "indices/test01/2/snapshot-snapshot_20140204" "indices/test01/3/__0" "indices/test01/3/__1" "indices/test01/3/__2" "indices/test01/3/__3" "indices/test01/3/snapshot-snapshot_20140204" "indices/test01/4/__0" "indices/test01/4/snapshot-snapshot_20140204" "indices/test01/snapshot-snapshot_20140204" "metadata-snapshot_20140204" "snapshot-snapshot_20140204"
せっかくなのでレストア
前回と同じデータをレストア!
curl -XPOST localhost:9200/_snapshot/my_s3_repository/snapshot_20140204/_restore
念のために確認!
curl -X GET localhost:9200/test01/hogehuga/_search?pretty
以下の通りレストアされている。
{
"took" : 11,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [ {
"_index" : "test01",
"_type" : "hogehuga",
"_id" : "1",
"_score" : 1.0, "_source" : {"name":"MasaharuFukuyama","email" :"masha@tfm.com","age":45}
}, {
"_index" : "test01",
"_type" : "hogehuga",
"_id" : "2",
"_score" : 1.0, "_source" : {"name":"YoheiKawahara","email" :"hage@tfm.com","age":38}
} ]
}
}
この興奮を生でお伝え出来ないのが非常に残念!