Schedule snapshots
Take machine images of instances on a schedule with a snapshot policy, keeping the newest few of each.
Last updated 18 November 2026View as Markdown
A snapshot policy takes machine images of instances; it does not snapshot volumes. Replace the ids with your own.
Important
The images a policy takes are metered as snapshot storage for their size until they are deleted. Where snapshot storage is not charged yet, they show as "metered, not charged yet"; you are told before charging starts. Set the retention with that in mind.
Prerequisites
- Permission for
ec2:CreateSnapshotPolicy; changing, pausing and running it now needec2:UpdateSnapshotPolicy; deletingec2:DeleteSnapshotPolicy. Withoutec2:UpdateSnapshotPolicyorec2:DeleteSnapshotPolicythe matching buttons are unavailable. - In the console, also
ec2:DescribeSnapshotPoliciesto open Snapshot policies (without it the page says "Access denied"). - Room in the snapshot policies quota.
- The instances to target,
runningorstopped, in the policy's region. The console lists only those.
Create a policy
- Open Compute, then Snapshot policies, and choose Create policy.
- For Name, enter nightly-web; its images are named after it.
- Under Instances, select the instances to snapshot.
- (Optional) For Tag key and Tag value, enter one tag to also take every instance that carries it, including instances launched later.
- For Every, choose the interval (default Daily).
- For From (UTC), enter the start time as
HH:MM(default03:00). - For Images to keep, enter 1 to 100 (default 7).
- Choose Create policy. The policy appears in the list with its next run.
dcloud ec2 snapshot-policies create --name nightly-web --region-id de1 \
--target-instance-ids i-3f9a2c07 --target-tags backup=daily \
--interval-hours 24 --start-time 03:00 --retain-count 7POST /ec2/api/snapshot-policies
{
"name": "nightly-web",
"regionId": "de1",
"targetInstanceIds": ["i-3f9a2c07"],
"targetTags": { "backup": "daily" },
"intervalHours": 24,
"startTime": "03:00",
"retainCount": 7
}resource "dcloud_snapshot_policy" "nightly" {
name = "nightly-web"
target_instance_ids = [dcloud_instance.web.id]
target_tags = { backup = "daily" }
interval_hours = 24
start_time = "03:00"
retain_count = 7
}How a policy runs
- Targets: the instances named, plus every instance carrying all of the target tags, including
ones launched later; only instances in the policy's region that are
runningorstoppedare snapshotted. At least one target is required (400"Name at least one instance or one tag to target"); an instance id that is not one of your instances is refused with400"Instances not found: …". - Schedule:
intervalHoursis 1, 2, 3, 4, 6, 8, 12, 24 or 168 (weekly, on Mondays). Runs fall onstartTime(UTC) plus whole intervals. Due policies are picked up every five minutes, so a run can start up to five minutes late. The targets are snapshotted one after the other, and a snapshot of a running instance is crash-consistent. - Retention: after an instance's image lands, the policy deregisters that instance's oldest
images beyond
retainCount. It counts only available images this policy took, so a failed run never removes the last good image, and an image you took by hand is never touched. - Each image is named
<policy> <instance name or id> <YYYY-MM-DD HH:MM>(UTC) and records the policy. A target that fails does not stop the others; the policy's last-run error (lastRunError, Last run: in the console) says which one failed, or "No instance matched the policy targets."
Run, pause, change or delete it
- Open Compute, then Snapshot policies, and choose the policy in the list.
- Choose Run now, Pause or Resume. Changing the schedule, targets or retention is done with the CLI, the API or Terraform.
- To delete it, under Delete this policy choose Delete policy, enter the policy name and choose Delete policy.
dcloud ec2 snapshot-policies run esp-0a1b2c3d
dcloud ec2 snapshot-policies update esp-0a1b2c3d --retain-count 14
dcloud ec2 snapshot-policies delete esp-0a1b2c3dPATCH /ec2/api/snapshot-policies/esp-0a1b2c3d
{ "enabled": false }POST /ec2/api/snapshot-policies/{id}/run runs it now; DELETE deletes it.
Change the dcloud_snapshot_policy (enabled = false pauses it), or remove it.
- Run now answers
202and leaves the schedule alone;queuedis false when a run was already waiting. - Resuming starts from the next slot: missed slots are not made up. Changing the schedule moves the next run onto the new one.
- Deleting keeps the images the policy took; they stay metered until you delete them under Images.
Related
Did this page help you?