Elasticsearch バージョン 6.2.4、そのプラグイン searchguard 6.2.4-12、s3-repository-plugin を使用しています。設定を使用してelasticsearch.ymlのsearchguardに対してSSLが無効になっています
searchguard.ssl.http.enabled: false
設定を使用して、serarchguard のすべてのユーザーに対してスナップショットの復元が有効になります。
searchguard.enable_snapshot_restore_privilege: true
テスト目的で、インデックスを次のように作成しました。
curl -uUSERNAME:PASSWORD -X PUT "localhost:9200/filebeat-2018.04.11" -H 'Content-Type: application/json' -d'
{
"settings" : {
"index" : {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
}
}
'
これにより、インデックスが正常に作成されました。次に、このスクリプトを使用してスナップショットを作成します。
daysagoyear=$(date --date="30 days ago" +'%Y')
daysagomonth=$(date --date="30 days ago" +'%m')
daysagoday=$(date --date="30 days ago" +'%d')
INDEX_PREFIXES='filebeat-'
es_username="USERNAME"
es_password="PASSWORD"
indices=`curl -u "$es_username":"$es_password" localhost:9200/_cat/indices?v|grep $INDEX_PREFIXES|awk '{print $3}'`
for index in $indices
do
index_date=`echo "$index"|cut -d "-" -f2`
index_date=`echo "$index_date"|tr . -`
index_date_yr=`date -d $index_date "+%Y"`
index_date_mon=`date -d $index_date "+%m"`
index_date_day=`date -d $index_date "+%d"`
delete=0
SNAPSHOT_NAME=${INDEX_PREFIXES}${index_date}"-snapshot"
bucket_name="elklogsireland"
if [ "$daysagoyear" -gt "$index_date_yr" ]
then
delete=1
elif [ "$daysagoyear" -eq "$index_date_yr" -a "$daysagomonth" -gt "$index_date_mon" ]
then
delete=1
elif [ "$daysagoyear" -eq "$index_date_yr" -a "$daysagomonth" -eq "$index_date_mon" -a "$daysagoday" -ge "$index_date_day" ]
then
delete=1
fi
if [ $delete -eq 1 ]
then
echo "Creating snapshot of $index ..."
# Setting Base Path for S3 Bucket
#curlsettingstring="-d \'{\"type\": \"s3\", \"settings\": {\"bucket\": \"${bucket_name}\", \"base_path\": \"${index_date}\" }}\'"
curl -u $es_username:$es_password -XPUT "localhost:9200/_snapshot/$bucket_name" -H 'Content-Type: application/json' -d '{
"type": "s3",
"settings": {
"bucket": "'$bucket_name'",
"base_path": "'${INDEX_PREFIXES}${index_date}'"
}
}'
curl -u $es_username:$es_password -XPUT "http://localhost:9200/_snapshot/$bucket_name/$SNAPSHOT_NAME?wait_for_completion=true" -H 'Content-Type: application/json' -d '{
"indices": "'${index}'",
"ignore_unavailable": "true",
"include_global_state": false
}'
if [ $? -eq 0 ];then
echo "Removing $index ...."
curl -u $es_username:$es_password -XDELETE "http://localhost:9200/$index"
else
echo "$(date +"%Y-%m-%d:%H:%M:%S") ---- Unable to form snapshot $SNAPSHOT_NAME on s3" >> /var/log/messages
fi
fi
done
このスクリプトは、30 日前のインデックスのスナップショットを作成し、それらを s3 バケットにアップロードしてから削除することを目的としています。処理中、インデックスにちなんで名付けられた s3 のフォルダーにインデックス スナップショット ファイルをアップロードします。正常に実行され、スナップショット ファイルが s3 バケットにアップロードされます。復元すると、次のようにスクリプトを実行しています。
if [ $# -lt 1 ]
then
echo "Missing argument. Please provide index name."
exit 1
fi
es_username="USERNAME"
es_password="PASSWORD"
bucket_name="elklogsireland"
index_name=$1
echo "Index Name: ${index_name}"
curl -u $es_username:$es_password -XPOST "localhost:9200/_snapshot/${bucket_name}/${index_name}-snapshot/_restore" -H 'Content-Type: application/json' -d '{
"indices": "'$index_name'",
"ignore_unavailable": "true",
"include_global_state": false
}'
引数にインデックス名をとります。そして、私がそれを実行すると、以下が返されます:
{"snapshot":{"snapshot":"filebeat-2018-04-10-snapshot","indices":[],"shards":{"total":0,"failed":0,"successful":0}}}
インデックスは実際には形成されません。私に欠けているものと、さらに何をする必要があるか教えてください。