Skip to content

Backup import: improvements - #10920

Draft
adoriandoran wants to merge 18 commits into
mainfrom
feat/backup-import-3
Draft

Backup import: improvements#10920
adoriandoran wants to merge 18 commits into
mainfrom
feat/backup-import-3

Conversation

@adoriandoran

Copy link
Copy Markdown
Member

No description provided.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🖥️ App preview is ready!

🔗 Preview URL: https://pr-10920.trilium-app.pages.dev
📖 Production URL: https://app.triliumnotes.org

✅ All checks passed

This preview will be updated automatically with new commits.

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 25.28kB (0.02%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
standalone-esm 53.35MB 27.4kB (0.05%) ⬆️
client-esm* 48.94MB -2.12kB (-0.0%) ⬇️

ℹ️ *Bundle size includes cached data from a previous commit

Affected Assets, Files, and Routes:

view changes for bundle: client-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
src/chunk-*.js -160 bytes 207.59kB -0.08%
src/architectureDiagram-*.js -423 bytes 148.56kB -0.28%
src/MindMap-*.js -98 bytes 119.59kB -0.08%
src/xychartDiagram-*.js -8 bytes 41.63kB -0.02%
src/mermaid.core-*.js -187 bytes 31.13kB -0.6%
src/MindMap-*.css -1.1kB 21.66kB -4.82%
src/diagram-*.js -147 bytes 5.93kB -2.42%
view changes for bundle: standalone-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/abstract_provider-*.js 1.75kB 2.07MB 0.08%
assets/src-*.js 2.63kB 240.09kB 1.11%
src/dist-*.js 7 bytes 63 bytes 12.5% ⚠️
src/dist-*.js -7 bytes 56 bytes -11.11%
src/ContentWidget-*.js 581 bytes 151.69kB 0.38%
assets/zip-*.js 3 bytes 56.75kB 0.01%
src/setup-*.js 10.36kB 35.03kB 42.01% ⚠️
src/ContentWidget-*.css 484 bytes 29.97kB 1.64%
assets/web-*.js (New) 23.39kB 23.39kB 100.0% 🚀
src/main-*.js 35 bytes 9.35kB 0.38%
assets/browser_routes-*.js 93 bytes 8.53kB 1.1%
assets/local-*.js 1.22kB 7.07kB 20.82% ⚠️
src/local-*.js 1.14kB 6.63kB 20.83% ⚠️
src/setup-*.css 1.76kB 5.44kB 47.8% ⚠️
sw.js 1.39kB 3.86kB 56.27% ⚠️
assets/html-*.js -5 bytes 2.92kB -0.17%
assets/database_restore-*.js -20.62kB 2.8kB -88.04%
src/DatabaseFileBadges-*.js 2.09kB 2.77kB 306.9% ⚠️
assets/backup-*.js (New) 2.42kB 2.42kB 100.0% 🚀
assets/request-*.js 79 bytes 1.81kB 4.55%
assets/zh-*.js 32 bytes 1.54kB 2.12%
assets/zh-*.js -32 bytes 1.51kB -2.07%
assets/pt-*.js -16 bytes 1.28kB -1.23%
assets/pt-*.js 16 bytes 1.3kB 1.25%
assets/setup_marker-*.js (New) 657 bytes 657 bytes 100.0% 🚀
assets/backup_provider-*.js -2.06kB 561 bytes -78.6%

Files in src/main-*.js:

  • ./src/main.ts → Total Size: 2.67kB

@greptile-apps

greptile-apps Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR expands backup import and restore support across server, standalone, desktop, and browser clients, including container backups, resumable uploads, setup-mode restoration, and backup downloads.

  • Adds chunked upload retry, resumption, supersession, and completion caching.
  • Introduces backup-container reading, writing, validation, and optional passphrase handling.
  • Adds setup flows for preserving existing data, downloading backups, and restoring uploaded or existing backups.
  • Extends server and standalone database providers to stage and activate restored databases.

Confidence Score: 3/5

The PR is not yet safe to merge because replacement admission can destroy the active upload before rejecting its successor, and concurrent finish requests can invoke restoration twice.

The server still drops an accepted session before checking free space for its replacement, leaving neither upload active when admission fails, while overlapping finish requests still perform the completion lookup outside the session mutex and can repeat the completion callback.

Files Needing Attention: apps/server/src/services/chunked_upload.ts

Important Files Changed

Filename Overview
apps/server/src/services/chunked_upload.ts Adds upload supersession, process-stamped identifiers, terminal-state caching, and retry-friendly status responses; the previously reported replacement-order and concurrent-finish defects remain.
apps/client/src/services/chunked_upload.ts Extends chunked uploads with request-level retries, online/foreground recovery, resynchronization, cancellation, and reconnecting progress.
apps/server/src/services/database_restore.ts Implements staged database validation, restoration, cleanup, and redacted restore diagnostics.
apps/server/src/backup_provider.ts Extends backup discovery, container generation, download, and path-constrained backup resolution.
packages/trilium-backup-container/src/format.ts Defines the shared backup-container format and validation used across server and standalone targets.
apps/client/src/setup.tsx Integrates backup, existing-data, and restore screens into the setup wizard.

Sequence Diagram

sequenceDiagram
    participant U as User
    participant C as Setup client
    participant API as Restore API
    participant Upload as Chunked upload service
    participant Restore as Database restore service
    participant DB as SQLite database
    U->>C: Select backup
    C->>API: Begin restore upload
    API->>Upload: Create session
    loop Until all bytes arrive
        C->>Upload: Send chunk with offset
        Upload-->>C: Received-byte status
    end
    C->>Upload: Finish upload
    Upload->>Restore: Hand off staged backup
    Restore->>Restore: Validate/decrypt container
    Restore->>DB: Replace and initialize database
    Restore-->>C: Restore status
Loading

Reviews (17): Last reviewed commit: "client/options/backup: add a prompt befo..." | Re-trigger Greptile

Comment on lines +207 to +209
const [ oldest ] = sessions.values();
remember(oldest.uploadId, { kind: "superseded" });
await drop(oldest);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security Replacement destroys active upload

When a second restore request cannot satisfy the free-space check, the supersede loop has already deleted the accepted session and its partial file, causing the original upload to receive 410 and the replacement to be rejected without leaving an active upload. How this was verified: The restore route enables supersession, and the admission path drops the current session before requireRoomFor validates the replacement.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

Comment thread apps/server/src/services/chunked_upload.ts
Comment thread apps/server/src/services/chunked_upload.ts
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