Skip to content

Instantly share code, notes, and snippets.

View yodlegists's full-sized avatar

Yodle Gists yodlegists

View GitHub Profile
@yodlegists
yodlegists / close_indices.py
Created June 18, 2016 02:17
Closing indices
prod_indices = get_prod_indices(client)
print 'Indices to close: ', prod_indices
close_successful = curator.close_indices(client, prod_indices)
@yodlegists
yodlegists / client_connect.py
Last active June 18, 2016 02:45
Connecting to your cluster
# Specify your host machines as a list of dictionaries with keys "host" and "port", defaults to localhost:9200
client = elasticsearch.Elasticsearch(hosts=HOST_LIST)
@yodlegists
yodlegists / get_most_recent_snapshot.py
Created June 18, 2016 02:13
Getting the most recent snapshot
def get_most_recent_snapshot(client):
snapshots = curator.get_snapshots(client, REPOSITORY)
return sorted(snapshots)[-1]
@yodlegists
yodlegists / get_prod_indices.py
Created June 18, 2016 02:11
Getting all indices prefixed with "prod_"
def get_prod_indices(client):
indices = curator.get_indices(client)
prefix_filter = curator.build_filter(kindOf="prefix", value=PROD_PREFIX)
return curator.apply_filter(items=indices, **prefix_filter)
@yodlegists
yodlegists / recover_snapshot.py
Last active June 18, 2016 02:24
running restore process
def recover_snapshot(client, snapshot):
payload = {
"ignore_unavailable": True,
"rename_pattern": "(.+)",
"rename_replacement": "prod_$1",
"include_aliases": False,
"index_settings": {
"index.number_of_replicas": 1
}
}
@yodlegists
yodlegists / get_snapshot_indices.py
Created June 18, 2016 02:08
Getting snapshot indices
def get_snapshot_indices(client, latest_snapshot):
snap_details = curator.get_snapshot(client, REPOSITORY, latest_snapshot)
return snap_details['snapshots'][0]['indices']
@yodlegists
yodlegists / indices_not_in_snapshot.py
Created June 18, 2016 02:07
Indices not in snapshot
def get_indices_not_in_snapshot(prod_indices, snapshot_indices):
prefixed_snapshot_indices = ["prod_"+index for index in snapshot_indices]
return list(set(prod_indices).difference(prefixed_snapshot_indices))
@yodlegists
yodlegists / elastic_restore.py
Last active February 19, 2018 09:41
elastic restore script
import elasticsearch # https://www.elastic.co/guide/en/elasticsearch/client/python-api/current/index.html
import curator # http://curator.readthedocs.io/en/v3.4.1/examples.html
import sys
PROD_PREFIX = "prod_"
REPOSITORY = "Your repository here
HOST_LIST = [{"host": "Friendly-hostname-here", "port": 9200}]
def main():
@yodlegists
yodlegists / curator_delete.sh
Last active June 18, 2016 01:18
Curator Delete
curator \
--host localhost:9200 \
--timeout 43200 \
delete snapshots \
--repository prod_s3_repository \
--prefix snapshot- \
--older-than 30 \
--time-unit days \
--timestring %Y%m%d%H%M%S
@yodlegists
yodlegists / curator_snapshot.sh
Last active June 24, 2016 14:44
curator snapshot
curator \
--host localhost:9200 \
snapshot \
--repository prod_s3_repository \
--prefix snapshot- \
--wait_for_completion true \
--include_global_state false \
--request_timeout 43200 \
indices --all-indices