Skip to content

feat(server): full database backups over REST (#572, first slice) - #584

Open
MPCoreDeveloper wants to merge 7 commits into
masterfrom
feat/572-backup-rest-first
Open

MPCoreDeveloper wants to merge 7 commits into
masterfrom
feat/572-backup-rest-first

Conversation

@MPCoreDeveloper

Copy link
Copy Markdown
Owner

First slice of #572, built after verifying the existing surface in code (the engine exposes IDatabase.Flush() and the tenant service already copies a database path; the server had no backup route at all).nnAddedn- DatabaseBackupService: flush the live engine, copy to/backups//-full/, write a manifest.json (id, database, kind, createdUtc, sizeBytes, path). No storage-format access: a directory database copies as a directory, a .scdb as one file.n- POST /api/v1/backup/start?database= and GET /api/v1/backup/list — admin only.n- Docs in the same commit: REST_API (both endpoints with the exact payload), FEATURE_MATRIX, CHANGELOG including a Not in this slice section.nn**Not in this slice (so #572 stays open)**n- No restore endpoint / restore semantics (new vs existing database).n- No scheduling, retention, incremental or differential backups; no gRPC RPC (a proto change plus a capability-contract entry).n- The copy is a live-path copy after a flush, not a snapshot; concurrent writes are not coordinated.nnTests: DatabaseBackupServiceTests (4). Server suite 311/0 locally.

The server had no backup or restore management surface. DatabaseBackupService flushes the live engine (IDatabase.Flush), copies the database path to <database root>/backups/<db>/<utc>-full/ and writes a manifest, with POST /api/v1/backup/start and GET /api/v1/backup/list (admin only). Full only: no restore, no scheduling, no incremental/differential, no gRPC RPC - all stated in the CHANGELOG Not-in-this-slice section, REST_API and FEATURE_MATRIX so nobody assumes more. Verified against the code first (IDatabase.Flush, DatabaseInstanceConfiguration.DatabasePath, the copy helpers the tenant service already uses). Tests: DatabaseBackupServiceTests (4), server suite 311/0.
@codecov

codecov Bot commented Dec 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…lder (#572)

The new src/SharpCoreDB.Server.Core/Backup/ folder was silently excluded by .gitignore line 262 (Backup*/), so the service never reached the commit and every CI platform failed with CS0234 (no SharpCoreDB.Server.Core.Backup namespace) while the local build passed. Moved to Tenancy/ next to TenantBackupRestoreService, namespace SharpCoreDB.Server.Core.Tenancy, controller and test usings updated, CHANGELOG path corrected. Local: build clean, server suite 311/0.
@MPCoreDeveloper

Copy link
Copy Markdown
Owner Author

Status: builds and the full server suite pass on all three platforms (the earlier CS0234 was a .gitignore Backup*/ trap - fixed in 9b55e8e by moving the service to Tenancy/). CodeQL and SonarCloud now fail on the new path handling in DatabaseBackupService: the backup directory embeds the requested database name. Not merging a red security check. Fix direction for the next session: derive the backup root from the trusted DatabasePath only and keep the database name out of the filesystem path (manifest field for identification) - then re-run both gates.

MPCoreDeveloper and others added 2 commits December 6, 2026 10:17
CodeQL cs/path-injection and Sonar S2083 flagged DatabaseBackupService because the backup directory embedded the requested database name. The root is now derived from the configured DatabasePath only and the id is generated (<utc>-full-<random>); the database name lives in the manifest and List filters on it. Sanitize() is gone with it. Docs (REST_API payload + id/path, CHANGELOG) updated to the real layout. Server suite 311/0; backup tests 4/4.
…equest forgery token validation'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@MPCoreDeveloper

Copy link
Copy Markdown
Owner Author

Status: builds and the full server suite pass on all platforms. Two static-analysis findings still block the merge - they are precise and are the next actions.

SonarCloud on PR 584:

  • S2083 BLOCKER + four S6549 (filesystem oracle) in DatabaseBackupService.CopyAsync/SizeOf: the analyzer treats DatabaseInstanceConfiguration.DatabasePath as unsanitized input. The path comes from server configuration (the host appsettings) and never from SQL or a request body - the same trust boundary the repo already documents for SingleFileStorageProvider in docs/quality/SONAR_AND_COVERAGE.md. Next step: apply the documented precedent (annotated suppression with the reason plus the recorded project exclusion for this one file) instead of weakening the code.
  • S3776 HIGH: List() cognitive complexity 18 > 15. Next step: extract the manifest-reading loop into a private helper - a real refactor, not a suppression.

What is already fixed on the branch:

  • 9b55e8e: the service sat in src/SharpCoreDB.Server.Core/Backup/ which .gitignore (Backup*/) silently excluded, so CI failed with CS0234 while the local build passed. Moved to Tenancy/.
  • 0fd3c75: the backup path no longer embeds the requested database name - the root derives from DatabasePath only and the id is generated (-full-); the name lives in the manifest and List filters on it. Docs updated to the real layout.

Server suite 311/0 (backup tests 4/4).

MPCoreDeveloper and others added 3 commits December 6, 2026 10:27
…from user input'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…he path-injection exception (#572)

List() measured a cognitive complexity of 18 (>15): the manifest loop now lives in ReadManifests with a Matches helper. sonar-project.properties gains e2/e3 scoped to DatabaseBackupService for S2083/S6549 with the trust-boundary reasoning (path from server configuration, generated target id, requested name validated against the registry and recorded in the manifest) - the same precedent this file already documents for SingleFileStorageProvider. The project-side Sonar setting for the four scoped keys was applied via the API; the multicriteria list setting still has to be applied (the api/settings/set call for that one key answers 400).
@sonarqubecloud

sonarqubecloud Bot commented Dec 6, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
E Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@MPCoreDeveloper

Copy link
Copy Markdown
Owner Author

Latest state after 09a6a85 (merge of the Copilot Autofix commits + the S3776 refactor):

  • Builds and the full server suite: green on all platforms (311/0).
  • CodeQL: green - Copilot Autofix had already committed the CSRF attribute and the log-sanitising change; those two findings were the reason CodeQL failed, not only the path issue.
  • SonarCloud: still failing on S2083/S6549 for DatabaseBackupService. The scoped keys were stored via api/settings/set (e2/e3 ruleKey + resourceKey answer OK) but the multi-value key sonar.issue.ignore.multicriteria itself answers 400 with both values= and fieldValues=, and reads back empty.

One action left, and it needs the parameter form the documented e1 exclusion used (docs/quality/SONAR_AND_COVERAGE.md step 3 - "Project setting sonar.issue.ignore.multicriteria (e1 -> that rule, that file) set through api/settings/set"): set the list to e1,e2,e3 at project level, then push anything to re-run the automatic analysis. The rule keys and resource keys are already stored.

Everything else in this PR is verified: backup tests 4/4 and the CHANGELOG/REST_API/FEATURE_MATRIX describe the real layout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants