Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 3b8d153

Browse files
committed
feat: enable restore from previous backups
1 parent 86d70aa commit 3b8d153

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.github/workflows/import_packages.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ jobs:
4444
if_no_artifact_found: ignore
4545

4646
- name: Run sync
47+
env:
48+
BACKUP_FILESYSTEM_PATH: /tmp/
49+
BACKUP_FOLDER: backup
4750
run: |
4851
export PYTHONPATH=$PYTHONPATH:./
4952
python scripts/import_packages.py

scripts/import_packages.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
from datetime import date
32
import json
43
import os
54

@@ -30,6 +29,13 @@ def __init__(self):
3029
self.inference_engine = LlamaCppInferenceEngine()
3130
self.model_path = "./models/all-minilm-L6-v2-q5_k_m.gguf"
3231

32+
def restore_backup(self):
33+
if os.getenv("BACKUP_FOLDER"):
34+
try:
35+
self.client.backup.restore(backup_id=os.getenv("BACKUP_ORIGIN_ID", "backup"), backend="filesystem", wait_for_completion=True)
36+
except Exception as e:
37+
print(f"Failed to restore backup: {e}")
38+
3339
def setup_schema(self):
3440
if not self.client.collections.exists("Package"):
3541
self.client.collections.create(
@@ -87,11 +93,12 @@ async def add_data(self):
8793
)
8894

8995
async def run_import(self):
96+
self.restore_backup()
9097
self.setup_schema()
9198
# await self.add_data()
9299

93100
#  take a backup of the data
94-
self.client.backup.create(backup_id="backup-"+date.today().strftime("%Y-%m-%d"), backend="filesystem", wait_for_completion=True)
101+
self.client.backup.create(backup_id=os.getenv("BACKUP_TARGET_ID", "backup"), backend="filesystem", wait_for_completion=True)
95102

96103

97104
if __name__ == "__main__":

0 commit comments

Comments
 (0)