Sandboxes now support createBackup() and restoreBackup() methods for creating and restoring point-in-time snapshots of directories.
This allows you to restore environments quickly. For instance, in order to develop in a sandbox, you may need to include a user’s codebase and run a build step.
Unfortunately git clone and npm install can take minutes, and you don’t want to run these steps every time the user starts their sandbox.
Now, after the initial setup, you can just call createBackup(), then restoreBackup() the next time this environment is needed. This makes it practical to pick up exactly
where a user left off, even after days of inactivity, without repeating expensive setup steps.
const sandbox = getSandbox(env.Sandbox, "my-sandbox");
// Make non-trivial changes to the file systemawait sandbox.gitCheckout(endUserRepo, { targetDir: "/workspace" });await sandbox.exec("npm install", { cwd: "/workspace" });
// Create a point-in-time backup of the directoryconst backup = await sandbox.createBackup({ dir: "/workspace" });
// Store the handle for later useawait env.KV.put(`backup:${userId}`, JSON.stringify(backup));
// ... in a future session...
// Restore instead of re-cloning and reinstallingawait sandbox.restoreBackup(backup);Backups are stored in R2 and can take advantage of R2 object lifecycle rules to ensure they do not persist forever.
Key capabilities:
- Persist and reuse across sandbox sessions — Easily store backup handles in KV, D1, or Durable Object storage for use in subsequent sessions
- Usable across multiple instances — Fork a backup across many sandboxes for parallel work
- Named backups — Provide optional human-readable labels for easier management
- TTLs — Set time-to-live durations so backups are automatically removed from storage once they are no longer neeeded
To get started, refer to the backup and restore guide for setup instructions and usage patterns, or the Backups API reference for full method documentation.
Source: Cloudflare
Latest Posts
- (Updated) Microsoft 365: Modern Access Request and Access Denied web page [MC1188599]
![(Updated) Microsoft 365: Modern Access Request and Access Denied web page [MC1188599] 2 pexels joshsorenson 1714208](data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==)
- Amazon S3 Tables are now available in AWS GovCloud (US) Regions

- AWS Elemental Media Services Now Available in Asia Pacific (Malaysia) Region

- Amazon announces generative AI-based artifacts in Amazon Q Developer for visualizing resource and cost data


![(Updated) Microsoft 365: Modern Access Request and Access Denied web page [MC1188599] 2 pexels joshsorenson 1714208](https://mwpro.co.uk/wp-content/uploads/2024/08/pexels-joshsorenson-1714208-150x150.webp)


