Explorer
/proc/thread-self/root/tmp/aa050_backup.py
← Zurück ↓ Download
import sqlite3,json,hashlib,shutil,datetime,os
DB='/opt/struktur/youtube-research/knowledge.db'; out='/opt/struktur/reports/aa050-backup/'+datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%SZ'); os.makedirs(out)
con=sqlite3.connect('file:'+DB+'?mode=ro',uri=True); con.row_factory=sqlite3.Row
rows=[dict(r) for r in con.execute("select * from graphiti_import_queue where graphiti_status='processing' order by id")]
open(out+'/processing-before.json','w').write(json.dumps({'checked_at_utc':datetime.datetime.now(datetime.timezone.utc).isoformat(),'rows':rows},indent=2,default=str))
# consistent sqlite backup
src=sqlite3.connect(DB); dst=sqlite3.connect(out+'/knowledge.db'); src.backup(dst); dst.close(); src.close(); con.close()
for p in ['/opt/struktur/graphiti/service/main.py','/opt/struktur/graphiti/service/graphiti_worker.py','/opt/struktur/graphiti/service/llm_call_worker.py','/opt/struktur/graphiti/service/requirements.txt','/opt/struktur/graphiti/service/Dockerfile']:
 if os.path.exists(p): shutil.copy2(p,out+'/'+os.path.basename(p))
manifest=[]
for root,ds,fs in os.walk(out):
 for f in fs:
  p=os.path.join(root,f); h=hashlib.sha256(open(p,'rb').read()).hexdigest(); manifest.append({'path':p,'size':os.path.getsize(p),'sha256':h})
open(out+'/manifest.json','w').write(json.dumps({'created_utc':datetime.datetime.now(datetime.timezone.utc).isoformat(),'files':manifest},indent=2))
print(json.dumps({'backup':out,'processing_count':len(rows),'ids':[r['id'] for r in rows],'manifest':out+'/manifest.json'},indent=2))