Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add index_prefix option for filter indices on ES #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Graylog Archiver
Archives graylog indices to `backup_dir`, keeping the latest ones (`max_indices`).
Archives graylog indices (`index_prefix`) to `backup_dir`, keeping the latest ones (`max_indices`).

For example, if you have the following indices:

Expand Down Expand Up @@ -33,6 +33,7 @@ Create a configuration file for graylog archiver `graylog_archiver.json`:
"elasticsearch": {
"hosts": "localhost"
},
"index_prefix": "graylog",
"max_indices": 3,
"backup_dir": "/srv/backups/elasticsearch/graylog",
"delete": false
Expand Down
1 change: 1 addition & 0 deletions graylog_archiver/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def main():

archiver = GraylogArchiver(
es=Elasticsearch(**args.config.get("elasticsearch")),
index_prefix=args.config.get("index_prefix"),
max_indices=args.config.get("max_indices"),
backup_dir=args.config.get("backup_dir"),
delete=args.config.get("delete")
Expand Down
5 changes: 3 additions & 2 deletions graylog_archiver/graylog_archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@


class GraylogArchiver:
def __init__(self, es, max_indices, backup_dir, delete=False):
def __init__(self, es, index_prefix, max_indices, backup_dir, delete=False):
self.es = es
self.index_prefix = index_prefix
self.max_indices = max_indices
self.backup_dir = backup_dir
self.delete = delete
self.logger = logs.create_logger()
self.graylog = GraylogElasticsearch(es, max_indices, backup_dir)
self.graylog = GraylogElasticsearch(es, index_prefix, max_indices, backup_dir)

def archive(self):
self.logger.info("Indices: %s" % self.graylog.indices())
Expand Down
5 changes: 3 additions & 2 deletions graylog_archiver/graylog_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ def sort_indices(indices):


class GraylogElasticsearch:
def __init__(self, es, max_indices, backup_dir):
def __init__(self, es, index_prefix, max_indices, backup_dir):
self.es = es
self.index_prefix = index_prefix
self.max_indices = max_indices
self.backup_dir = backup_dir

def indices(self):
return list(self.es.indices.get_mapping().keys())
return list(filter(lambda x: x.startswith(self.index_prefix), list(self.es.indices.get_mapping().keys())))

def indices_to_archive(self):
indices_sorted = sort_indices(self.indices())
Expand Down
1 change: 1 addition & 0 deletions test/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{"host" : "localhost", "port": 9201}
]
},
"index_prefix": "graylog",
"max_indices": 1,
"backup_dir": "/srv/containers/elasticsearch_backups",
"delete": false
Expand Down