feat(6848): Settings restore rolls back, from the destination or a file, after a preview
CI & Build / Plugin hooks (push) Successful in 10s
CI & Build / Python lint (push) Successful in 1s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 1m42s
CI & Build / integration (push) Successful in 1m48s
CI & Build / Build & push image (push) Canceled after 22s
CI & Build / Plugin hooks (push) Successful in 10s
CI & Build / Python lint (push) Successful in 1s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 1m42s
CI & Build / integration (push) Successful in 1m48s
CI & Build / Build & push image (push) Canceled after 22s
The web restore no longer copies a backup in beside the live data. - GET /api/admin/restore/sources lists the backups at the backup destination, newest first. - POST /api/admin/restore/preview says what a restore would do, changing nothing: fresh or rollback, when the backup was taken, and counts now and after per kind. A backup that cannot apply here gets a 409 with the reason. - POST /api/admin/restore?confirm=rollback runs backup_job.rollback_to_backup: safety backup, replace, then search rebuilt in the background. Each takes ?source=<name> (a backup at the destination) or an upload. The destination path exists because uploads are held to the request-size limit, and a real instance's backup is far over it. backup_s3.get_file downloads from a bucket. backup_destination.list_backups/open_backup only accept names the scheduled backup writes, so a request cannot reach any other file. Settings -> Data -> Restore from Backup opens RestoreBackupDialog. The dialog: 1. Pick a backup at the destination or a file. 2. Read the preview. 3. Type "roll back". 4. Run it. The dialog then says where the replaced state was saved, and sends the user to sign in again. Closes #6840. Milestone 582, step 4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2998,6 +2998,29 @@ async def check_replace(data: dict) -> str:
|
||||
return await _replace_mode(session, data)
|
||||
|
||||
|
||||
# What the restore preview counts, now and in the backup: the kinds a person
|
||||
# recognises, not every table.
|
||||
_PREVIEW_KINDS = (
|
||||
("users", "Accounts"), ("projects", "Projects"), ("milestones", "Plans"),
|
||||
("notes", "Notes and tasks"), ("rules", "Rules and preferences"),
|
||||
)
|
||||
|
||||
|
||||
async def replace_preview(data: dict) -> dict:
|
||||
"""What replacing this store with `data` would do, changing nothing: the
|
||||
mode, when the backup was taken, and per kind how many there are now and
|
||||
how many there will be. RestoreRefused when it can't be applied here."""
|
||||
from grimoire.models import Base
|
||||
|
||||
async with async_session() as session:
|
||||
mode = await _replace_mode(session, data)
|
||||
counts = []
|
||||
for table, label in _PREVIEW_KINDS:
|
||||
now = await _count(session, Base.metadata.tables[table])
|
||||
counts.append({"kind": label, "now": now, "after": len(data.get(table) or [])})
|
||||
return {"mode": mode, "exported_at": data.get("exported_at"), "counts": counts}
|
||||
|
||||
|
||||
async def replace_from_backup(data: dict) -> dict:
|
||||
"""Put this store back to a full backup, in one transaction.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user