我正在尝试扩展/修改python脚本以获取aws elasticsearch快照。
我想在删除索引之前将每个索引的快照放入S3存储桶中。以下是我到目前为止的脚本。
问题:执行此操作时,它正在创建具有所有索引的快照,而我想为一个索引创建一个快照。
结果:每个索引应具有成功的快照,并且必须在其上删除该快照。
import boto3
import requests
import json
from requests_aws4auth import AWS4Auth
from elasticsearch import Elasticsearch, RequestsHttpConnection
import curator
host = 'search-xx-xxxxxas-xxxxx-xxxx-xxxxxx.us-east-1.es.amazonaws.com' # For example, search-my-domain.region.es.amazonaws.com
region = 'us-east-1' # For example, us-west-1
service = 'es'
credentials = boto3.Session().get_credentials()
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token)
TRUE = 'true'
FALSE = 'false'
# Build the Elasticsearch client.
es = Elasticsearch(
hosts = [{'host': host, 'port': 443}],
http_auth = awsauth,
use_ssl = True,
verify_certs = True,
connection_class = RequestsHttpConnection
)
index_list = curator.IndexList(es)
# Filters by age, anything with a time stamp older than 30 days in the index name.
index_list.filter_by_age(source='name', direction='older', timestring='%Y.%m.%d', unit='days', unit_count=67)
print("Found %s indices to delete" % len(index_list.indices))
## Creating snapshots for the above.
for x in range(len(index_list.indices)):
index = index_list.indices[x]
print(type(index))
url = 'https://'+host+'/_snapshot/qc-snapshots/'+ index
payload_dict = {
"indices": index,
"ignore_unavailable": True ,
"include_global_state": False
}
payload = json.dumps(payload_dict)
headers = {
'Content-Type': "application/json",
'Cache-Control': "no-cache"
}
print(url)
print(payload)
print(headers)
r = requests.put(url, auth=awsauth, json=payload, headers=headers)
print(r.status_code)
print(r.text)