Guide
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 it after you install dependencies, clone a repo, or warm a model.
Create a snapshot and restore it
Capture a sandbox after you prime it, then 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 click Create.
- A snapshot ID will appear.
- 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 to 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 does not 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
- 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.