| .. | .. |
|---|
| 21 | 21 | env: str, |
|---|
| 22 | 22 | source: str, |
|---|
| 23 | 23 | dry_run: bool, |
|---|
| 24 | + name: str | None = None, |
|---|
| 25 | + mode: str = "full", |
|---|
| 24 | 26 | ) -> AsyncGenerator[str, None]: |
|---|
| 25 | 27 | """Async generator that drives the restore workflow and yields SSE events. |
|---|
| 26 | 28 | |
|---|
| .. | .. |
|---|
| 28 | 30 | that use host Python venvs incompatible with the container's Python. |
|---|
| 29 | 31 | """ |
|---|
| 30 | 32 | base_args = ["restore", project, env] |
|---|
| 33 | + |
|---|
| 34 | + # Pass the backup file path to avoid interactive selection prompt |
|---|
| 35 | + if name: |
|---|
| 36 | + backup_path = f"/opt/data/backups/{project}/{env}/{name}" |
|---|
| 37 | + base_args.append(backup_path) |
|---|
| 38 | + |
|---|
| 31 | 39 | if dry_run: |
|---|
| 32 | 40 | base_args.append("--dry-run") |
|---|
| 41 | + |
|---|
| 42 | + # Granular restore mode |
|---|
| 43 | + if mode == "db": |
|---|
| 44 | + base_args.append("--db-only") |
|---|
| 45 | + elif mode == "wp": |
|---|
| 46 | + base_args.append("--wp-only") |
|---|
| 33 | 47 | |
|---|
| 34 | 48 | if source == "offsite": |
|---|
| 35 | 49 | # ops offsite restore <project> <env> |
|---|
| .. | .. |
|---|
| 67 | 81 | env: str, |
|---|
| 68 | 82 | source: Literal["local", "offsite"] = Query(default="local"), |
|---|
| 69 | 83 | dry_run: bool = Query(default=False, alias="dry_run"), |
|---|
| 84 | + name: str | None = Query(default=None), |
|---|
| 85 | + mode: Literal["full", "db", "wp"] = Query(default="full"), |
|---|
| 70 | 86 | _: str = Depends(verify_token), |
|---|
| 71 | 87 | ) -> StreamingResponse: |
|---|
| 72 | 88 | """ |
|---|
| .. | .. |
|---|
| 74 | 90 | |
|---|
| 75 | 91 | Uses Server-Sent Events (SSE) to stream real-time progress. |
|---|
| 76 | 92 | Runs on the host via nsenter for Python venv compatibility. |
|---|
| 93 | + |
|---|
| 94 | + Modes: full (default), db (database only), wp (wp-content only). |
|---|
| 77 | 95 | """ |
|---|
| 78 | 96 | return StreamingResponse( |
|---|
| 79 | | - _restore_generator(project, env, source, dry_run), |
|---|
| 97 | + _restore_generator(project, env, source, dry_run, name, mode), |
|---|
| 80 | 98 | media_type="text/event-stream", |
|---|
| 81 | 99 | headers={ |
|---|
| 82 | 100 | "Cache-Control": "no-cache", |
|---|