Capture and restore snapshots
Freeze a running sandbox into a snapshot. Restore that state into new sandboxes when you need a primed environment without repeating setup.
A snapshot is a group-scoped copy of a sandbox at one point in time. Use one after you install dependencies, clone a repo, or warm a model.
A snapshot captures a sandbox's memory and disk state, along with its compute size, container spec, and attached blob volumes. Networking settings, such as egress policies, ingress ports, and VNet integration, are not part of the snapshot and must be specified on each sandbox you create from it.
Create a snapshot and restore it
After you prime a sandbox, capture it and create another sandbox from the snapshot.
- In the ACA Sandboxes portal, open your sandbox group.
- Select Sandbox in the left menu.
- Select a running Sandbox.
- From the sandbox's toolbar, select Snapshot, and then select Create.
- The snapshot ID appears.
- Go to the Snapshots page and select a Snapshot.
- Select Create sandbox from the toolbar.
- Bash
- PowerShell
- SDK
SNAP_NAME="getting-started-snap-$RANDOM"
LOCAL_FILE=/tmp/aca-sample-payload.txt
aca sandbox create --disk ubuntu --label name=snap-source
printf 'data-before-snapshot' > "$LOCAL_FILE"
aca sandbox fs write -l name=snap-source --path /tmp/payload.txt --file "$LOCAL_FILE"
aca sandbox snapshot -l name=snap-source --name "$SNAP_NAME"
aca sandbox create --snapshot "$SNAP_NAME" --label name=snap-restored
aca sandbox fs cat -l name=snap-restored --path /tmp/payload.txt
$SnapName = "getting-started-snap-$(Get-Random)"
$LocalFile = "$env:TEMP/aca-sample-payload.txt"
aca sandbox create --disk ubuntu --label name=snap-source
'data-before-snapshot' | Set-Content -NoNewline $LocalFile
aca sandbox fs write -l name=snap-source --path /tmp/payload.txt --file $LocalFile
aca sandbox snapshot -l name=snap-source --name $SnapName
aca sandbox create --snapshot $SnapName --label name=snap-restored
aca sandbox fs cat -l name=snap-restored --path /tmp/payload.txt
import os
import time
from azure.identity import DefaultAzureCredential
from azure.containerapps.sandbox import SandboxGroupClient, endpoint_for_region
credential = DefaultAzureCredential()
client = SandboxGroupClient(
endpoint_for_region(os.environ["ACA_SANDBOXGROUP_REGION"]),
credential,
subscription_id=os.environ["AZURE_SUBSCRIPTION_ID"],
resource_group=os.environ["ACA_RESOURCE_GROUP"],
sandbox_group=os.environ["ACA_SANDBOX_GROUP"],
)
sandbox_a = client.begin_create_sandbox(disk="ubuntu").result()
sandbox_a.write_file("/tmp/payload.txt", "data-before-snapshot")
snap = sandbox_a.create_snapshot(name="getting-started-snap")
time.sleep(5)
sandbox_b = client.begin_create_sandbox(snapshot_id=snap.id).result()
time.sleep(15)
content = sandbox_b.read_file("/tmp/payload.txt").decode()
print(content)
List and inspect snapshots
Snapshots belong to the sandbox group, not the source sandbox page.
- In the ACA Sandboxes portal, open the sandbox group.
- Select Snapshots.
- Select a snapshot row to open its details, including source sandbox, size, and creation time.
- Bash
- PowerShell
- SDK
aca sandboxgroup snapshot list
aca sandboxgroup snapshot get --selector "name=$SNAP_NAME"
aca sandboxgroup snapshot list
aca sandboxgroup snapshot get --selector "name=$SnapName"
for s in client.list_snapshots():
marker = " <-- just created" if s.id == snap.id else ""
label = s.labels.get("name", "")
print(f"{s.id} name={label} size={s.resources}{marker}")
detail = client.get_snapshot(snap.id)
print(detail.sandbox_id, detail.created_at_utc)
Delete a snapshot
Delete snapshots you no longer need. Deleting a snapshot doesn't delete sandboxes that were already restored from it.
- In the ACA Sandboxes portal, open the sandbox group.
- Select Snapshots.
- Select the snapshot, then select Delete.
- Confirm the deletion.
- Bash
- PowerShell
- SDK
aca sandboxgroup snapshot delete --selector "name=$SNAP_NAME"
aca sandboxgroup snapshot delete --selector "name=$SnapName"
client.delete_snapshot(snap.id)
Notes
- A restore needs a short warm-up.
- Snapshots depend on the disk image they were created from.
- Fan out from one snapshot when many sandboxes need the same primed state.