From 5d7a6092850876d3f212d8e27752760f456cd212 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 26 Nov 2021 16:19:18 +0700 Subject: [PATCH] skip backing up not yet existing index --- tubearchivist/home/src/index_management.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tubearchivist/home/src/index_management.py b/tubearchivist/home/src/index_management.py index d7d7a21..0ca2c40 100644 --- a/tubearchivist/home/src/index_management.py +++ b/tubearchivist/home/src/index_management.py @@ -529,6 +529,15 @@ class ElasticBackup: self.post_bulk_restore(file_name) os.remove(file_name) + def index_exists(self, index_name): + """check if index already exists to skip""" + es_url = self.config["application"]["es_url"] + es_auth = self.config["application"]["es_auth"] + url = f"{es_url}/ta_{index_name}" + response = requests.get(url, auth=es_auth) + + return response.ok + def backup_all_indexes(): """backup all es indexes to disk""" @@ -536,6 +545,8 @@ def backup_all_indexes(): for index in backup_handler.index_config: index_name = index["index_name"] + if not backup_handler.index_exists(index_name): + continue all_results = backup_handler.get_all_documents(index_name) file_content = backup_handler.build_bulk(all_results) backup_handler.write_es_json(file_content, index_name)