Skip to content

Mount backup archives from R2 during restore#577

Merged
whoiskatrin merged 4 commits intomainfrom
backup-restore-r2-mount
Apr 13, 2026
Merged

Mount backup archives from R2 during restore#577
whoiskatrin merged 4 commits intomainfrom
backup-restore-r2-mount

Conversation

@whoiskatrin
Copy link
Copy Markdown
Collaborator

@whoiskatrin whoiskatrin commented Apr 13, 2026

Summary

  • restore backups from an R2-backed s3fs mount instead of downloading data.sqsh into local container storage first
  • reuse the existing bucket-mount credential and password-file flow for restore-time R2 mounts
  • tear down prior restore overlay, lower, and backing R2 mounts before remounting, including a lazy-unmount fallback for repeat restores
  • update unit coverage for the mounted archive path and R2 mount cleanup behavior

Why

squashfuse already reads the archive through normal file reads, so restore does not need a full local copy of the archive first. Mounting the backup prefix directly keeps the restore path simpler and avoids the extra download step.

Reviewer Notes

  • packages/sandbox-container/src/services/backup-service.ts is unchanged. The container restore path still only takes an archivePath and mounts it with squashfuse plus fuse-overlayfs.
  • The SDK-side behavior change is that archivePath now points to /var/backups/r2mount/<id>/data.sqsh instead of /var/backups/<id>.sqsh.
  • Restore teardown now has to clean up both the existing overlay/lower mounts and the backing s3fs mount before a second restore of the same backup.
  • The lazy-unmount fallback was added for the second-restore/copy-on-write case where FUSE teardown can be timing-sensitive.
  • No Dockerfile change was needed in this repo because the runtime image already installs Ubuntu's s3fs package.

Testing

  • npm run check
  • npm test

Avoid downloading the full backup archive into local storage before
restore. Mount the R2 backup prefix with s3fs instead so squashfuse can
read archive blocks on demand.
Avoid downloading the full backup archive into local storage before
restore. Mount the R2 backup prefix with s3fs instead so squashfuse can
read archive blocks on demand.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 13, 2026

🦋 Changeset detected

Latest commit: 28a807c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/sandbox Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 13, 2026

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/sandbox-sdk/@cloudflare/sandbox@577

commit: 28a807c

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 13, 2026

📦 Preview Build

Version: 0.0.0-pr-577-28a807c

Install the SDK preview:

npm i https://pkg.pr.new/cloudflare/sandbox-sdk/@cloudflare/sandbox@577

🐳 Docker images were not rebuilt — no container changes detected. Use the latest release images from Docker Hub.

Restore can reuse the same backup after copy-on-write writes, which leaves
FUSE teardown timing-sensitive. Fall back to lazy unmount for the restore
R2 mount before remounting it.
Document the restore path change in the next SDK release so users see
that backup restores now mount archives from R2 instead of downloading
a local copy first.
@whoiskatrin whoiskatrin marked this pull request as ready for review April 13, 2026 10:51
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

@whoiskatrin whoiskatrin merged commit a56898c into main Apr 13, 2026
20 checks passed
@whoiskatrin whoiskatrin deleted the backup-restore-r2-mount branch April 13, 2026 11:14
@sandy-bonk sandy-bonk Bot mentioned this pull request Apr 13, 2026
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