Matthias Nott
2026-02-22 7d94ec0d18b46893e23680cf8438109a34cc2a10
app/routers/restore.py
....@@ -21,6 +21,8 @@
2121 env: str,
2222 source: str,
2323 dry_run: bool,
24
+ name: str | None = None,
25
+ mode: str = "full",
2426 ) -> AsyncGenerator[str, None]:
2527 """Async generator that drives the restore workflow and yields SSE events.
2628
....@@ -28,8 +30,20 @@
2830 that use host Python venvs incompatible with the container's Python.
2931 """
3032 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
+
3139 if dry_run:
3240 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")
3347
3448 if source == "offsite":
3549 # ops offsite restore <project> <env>
....@@ -67,6 +81,8 @@
6781 env: str,
6882 source: Literal["local", "offsite"] = Query(default="local"),
6983 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"),
7086 _: str = Depends(verify_token),
7187 ) -> StreamingResponse:
7288 """
....@@ -74,9 +90,11 @@
7490
7591 Uses Server-Sent Events (SSE) to stream real-time progress.
7692 Runs on the host via nsenter for Python venv compatibility.
93
+
94
+ Modes: full (default), db (database only), wp (wp-content only).
7795 """
7896 return StreamingResponse(
79
- _restore_generator(project, env, source, dry_run),
97
+ _restore_generator(project, env, source, dry_run, name, mode),
8098 media_type="text/event-stream",
8199 headers={
82100 "Cache-Control": "no-cache",