handle aliased zip file restore

This commit is contained in:
Simon 2026-01-24 18:06:25 +07:00
parent 229113a1ed
commit aa2edbbb06
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 8 additions and 3 deletions

View File

@ -7,6 +7,7 @@ Functionality:
import json
import os
import re
import zipfile
from datetime import datetime
@ -101,8 +102,7 @@ class ElasticBackup:
def post_bulk_restore(self, file_name):
"""send bulk to es"""
file_path = os.path.join(self.CACHE_DIR, file_name)
with open(file_path, "r", encoding="utf-8") as f:
with open(file_name, "r", encoding="utf-8") as f:
data = f.read()
if not data.strip():
@ -256,7 +256,7 @@ class BackupCallback:
for document in self.source:
document_id = document["_id"]
es_index = document["_index"]
es_index = re.sub(r"_v\d+$", "", document["_index"]) # remove _v
action = {"index": {"_index": es_index, "_id": document_id}}
source = document["_source"]
bulk_list.append(json.dumps(action))

View File

@ -55,6 +55,8 @@ class ElasticIndex:
"""check if index already exists and return mapping if it does"""
response, status_code = ElasticWrap(self.index_namespace).get()
exists = status_code == 200
if not exists:
return False, False
index_key = f"{self.index_namespace}"
current_version = self.get_current_version()
@ -357,6 +359,9 @@ class ElasticIndexWrap:
index_name, _, _ = self._config_split(index)
print(f"[ta_{index_name}] reset elastic index")
handler = ElasticIndex(index_name)
if not handler.exists:
continue
current_version = handler.get_current_version()
handler.delete_index(by_version=current_version)