def create_snapshot(self, repo_path, snapshot_name):
        """ Create snapshot of elasticsearch in given repository. """

        sc = SnapshotClient(self.es)
        response = sc.create(repository=repo_path,
                             snapshot=snapshot_name,
                             wait_for_completion=True,
                             master_timeout=600)
        return response["snapshot"]
 def restore_snapshot(es, date, indices):
     snapshot_client = SnapshotClient(es)
     env = settings.SERVER_ENVIRONMENT
     repo_name = '{}_es_snapshot'.format(env)
     kwargs = {}
     if indices != '_all':
         kwargs['body'] = {'indices': indices}
     snapshot_client.restore(repo_name,
                             '{repo_name}_{year}_{month}_{day}'.format(
                                 repo_name=repo_name, year=date.year,
                                 month=date.month, day=date.day
                             ),
                             wait_for_completion=True,
                             **kwargs)
	def __init__(self, host, port, username, password, indexname):
		"""
		Initializes this Elasticsearch Client.
		
		:param host: the HTTP address of the Elasticsearch server.
		:param port: the HTTP port of the Elasticsearch server.
		:param username: the username for connecting to the index.
		:param password: the password for connecting to the index.
		:param indexname: the name of the Elasticsearch index.
		"""
		self.indexname = indexname
		self.client = Elasticsearch(connection_class = SafeRequestsHttpConnection, host = host, port = int(port), http_auth = [username, password])
		self.snapshotclient = SnapshotClient(self.client)
		self.indicesclient = IndicesClient(self.client)
Пример #4
0
def getSnapshotStatus():
    sn = SnapshotClient(ES)
    status = sn.get(repository="fias", snapshot="fias_full")
    return status
Пример #5
0
from elasticsearch.client import SnapshotClient
from fiases.fias_data import ES
import fiases.fias_data

sn = SnapshotClient(ES)


def register(location="/usr/share/elasticsearch/snapshots"):
    sn_body = {
        "type": "fs",
        "settings": {
            "compress": "true",
            "location": location
        }
    }
    sn.create_repository(repository="fias", body=sn_body)


def restore():
    ES.indices.delete(index=address.INDEX, ignore=[400, 404])
    ES.indices.delete(index=houses.INDEX, ignore=[400, 404])

    sn.restore(repository="fias",
               snapshot="fias_full",
               body={"indices": [address.INDEX, houses.INDEX]})


def restoreIfNotExist():
    if not ES.indices.exists(address.INDEX):
        sn.restore(repository="fias",
                   snapshot="fias_full",
Пример #6
0
 def __init__(self, url, index_name, repo_name):
     self._url = url
     self._index_name = index_name
     self._repo_name = repo_name
     self._client = SnapshotClient(Elasticsearch(self._url))