VolumeSnapshot
Source:
src/Fly/VolumeSnapshot.ts
A Fly.VolumeSnapshot is an on-demand snapshot of a mounted disk.
Create is fire-and-forget. Identity is the snapshot id from a
subsequent list. Destroy is a no-op. Snapshots follow Volume
retention. nuke skips this type.
Create a snapshot
Section titled “Create a snapshot”Point it at a Volume id from the parent Machine or
Service (mounts[0].volumeId).
const box = yield* Fly.Machine("Box", { app: Site, region: "iad", image: "nginx:alpine", mounts: [{ path: "/data", sizeGb: 1 }],});
export const Nightly = Fly.VolumeSnapshot("Nightly", { app: Site, volumeId: box.mounts[0].volumeId,});Restore
Section titled “Restore”Restore into a new disk with snapshotId on the mount. Create-only.
The new Machine gets a copy. The original Volume is unchanged.
const restored = yield* Fly.Machine("Restored", { app: Site, region: "iad", image: "nginx:alpine", mounts: [{ path: "/data", sizeGb: 1, snapshotId: Nightly.snapshotId }],});Restore into a Service
Section titled “Restore into a Service”Pass snapshotId on MountVolume. Same create-only rule.
export default class Api extends Fly.Service<Api>()( "Api", { app: Site, main: import.meta.url, region: "iad", port: 3000 }, Effect.gen(function* () { const disk = yield* Fly.MountVolume({ path: "/data", sizeGb: 1, snapshotId: Nightly.snapshotId, }); return { fetch: Effect.succeed(HttpServerResponse.text(disk.path)), }; }).pipe(Effect.provide(Fly.MountVolumeLive)),) {}