"""Read-only host maintenance export using Deck's existing backup schema. No Server construction, worker startup, installation or state write. Run as the native Deck user (or in the current container), passphrase on stdin. """ import hashlib,json,os,sqlite3,sys,threading from pathlib import Path from types import SimpleNamespace app=Path(os.environ.get('DECK_APP_DIR',str(Path(__file__).resolve().parent.parent))) if not (app/'backup.py').is_file() and Path('/app/backup.py').is_file():app=Path('/app') sys.path.insert(0,str(app)) # A maintenance repair may override one known application version. Never keep # shadowing a newer app's backup implementation after a normal app update. maintenance=Path(__file__).resolve().parent override=maintenance/'backup-override.json' if override.is_file(): spec=json.loads(override.read_text()) if hashlib.sha256((app/'backup.py').read_bytes()).hexdigest()==spec['base_sha256']: if hashlib.sha256((maintenance/'backup.py').read_bytes()).hexdigest()!=spec['module_sha256']:raise ValueError('Backup-Wartungsmodul hat eine abweichende Prüfsumme.') sys.path.insert(0,str(maintenance)) from backup import Backup,SETTINGS,validate from backup_codec import seal,open_backup from auth import CredentialStore from image_runtime import ImageRuntime from tts_runtime import TTSRuntime from prompt_enhancer import PromptEnhancer from docker_support import DockerSupport from network.client import NetworkClient def fingerprint(root): paths=[root/n for n in SETTINGS]+list((root/'models').glob('*/entry.json'))+[root/'runtime/state.json',root/'auth.json',root/'recovery/job.json']+list(root.glob('*runtime/active.json')) return {str(p):hashlib.sha256(p.read_bytes()).hexdigest() for p in paths if p.is_file()} def snapshot(root): before=fingerprint(root) job=root/'recovery/job.json' if job.exists() and json.loads(job.read_text()).get('state')=='running':raise ValueError('Restore läuft; Sicherung wird verschoben.') class Inventory: def __init__(self):self.root=root/'models';self.lock=threading.RLock() def status(self):return {'entries':[dict(json.loads(p.read_text()),id=p.parent.name) for p in self.root.glob('*/entry.json')]} # Allocate passive runtime readers without invoking constructors that may resume jobs. def reader(cls,name): r=cls.__new__(cls);r.root=root/name;r.lock=threading.RLock();r.job=None;r.image_runtime=image;return r image=ImageRuntime(root/'image-runtime');catalog=Inventory() state=json.loads((root/'runtime/state.json').read_text()) s=SimpleNamespace(catalog=catalog,profiles=SimpleNamespace(lock=threading.RLock()),endpoint=SimpleNamespace(lock=threading.RLock()),runtime=SimpleNamespace(status=lambda:state),image_runtime=image,tts_runtime=reader(TTSRuntime,'tts-runtime'),docker=DockerSupport(),network=NetworkClient(),credentials=CredentialStore(root/'auth.json')) s.prompt_enhancer=PromptEnhancer(root/'prompt-enhancers',catalog,s.profiles,image) from strata_runtime import StrataRuntime s.strata_runtime=StrataRuntime(root/'strata-runtime',catalog) from audio_cpp_runtime import AudioCppRuntime from ltx_original_runtime import LTXOriginalRuntime from separator_runtime import SeparatorRuntime from remix_runtime import RemixRuntime from xvc_runtime import XVCRuntime from applio_runtime import ApplioRuntime from acestep_runtime import AceStepRuntime from omnivoice_runtime import OmniVoiceRuntime from voxcpm_runtime import VoxCPMRuntime for attr,cls,name in [('audio_cpp_runtime',AudioCppRuntime,'audio-cpp-runtime'),('ltx_original_runtime',LTXOriginalRuntime,'ltx-original-runtime'),('separator_runtime',SeparatorRuntime,'separator-runtime'),('remix_runtime',RemixRuntime,'music-remix-runtime'),('xvc_runtime',XVCRuntime,'xvc-runtime'),('applio_runtime',ApplioRuntime,'applio-runtime'),('acestep_runtime',AceStepRuntime,'acestep-runtime'),('omnivoice_runtime',OmniVoiceRuntime,'omnivoice-runtime'),('voxcpm_runtime',VoxCPMRuntime,'voxcpm-runtime')]:setattr(s,attr,reader(cls,name)) b=Backup.__new__(Backup);b.server=s;b.root=root;b.job=None doc=b.snapshot(include_history=False) doc['warnings'].append('Vollständige Dashboard-Historie liegt im separaten Nutzdatenarchiv.') if before!=fingerprint(root):raise ValueError('Konfiguration während Export geändert; erneut versuchen.') # This deployed OmniVoice tag uses the same maintained voice-web build recipe. # Export the canonical recipe name accepted by the existing Restore UI. for service in doc['services']: if service.get('build_recipe')=='voice-web' and service.get('image')=='athena-voice-web:0.2.1-deck-random': service['image']='athena-voice-web:0.2.1-deck2' service['registry']=None doc['warnings'].append('OmniVoice: lokales Image deck-random wird beim Neuaufbau aus dem gepflegten voice-web-Rezept als deck2 gebaut. Bestehenden anders benannten Container nicht automatisch ersetzen.') return validate(doc) if __name__=='__main__': key=sys.stdin.buffer.readline().decode().strip();doc=snapshot(Path('/var/lib/deck'));raw=seal(doc,key) assert open_backup(raw,key)==doc sys.stdout.buffer.write(raw)