By csabatothus
The GUI offers “Add to Region” and “Restore Droplet” for a snapshot. How can I perform those actions on a backup or snapshot through the API?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
After you take a snapshot of a Droplet, you can find the ID of that snapshot via the API by querying the /v2/images?private=true endpoint.
curl -X GET -H "Content-Type: application/json" \
-H "Authorization: Bearer $DO_TOKEN" \
"https://api.digitalocean.com/v2/images?private=true"
You can also use doctl, the DigitalOcean command line client, to acomplish this:
doctl compute image list-user
Once you have found the ID of your snapshot, you can make a POST to the /v2/droplets/$DROPLET_ID/actions endpoint to restore the snapshot to an existing Droplet:
curl -X POST -H "Content-Type: application/json" \
-H "Authorization: Bearer $DO_TOKEN" \
-d '{"type":"restore", "image": $SNAPSHOT_ID }' \
"https://api.digitalocean.com/v2/droplets/$DROPLET_ID/actions"
Or with doctl:
doctl compute droplet-action restore $DROPLET_ID --image-id $SNAPSHOT_ID
You can also add snapshots to additional regions with the API:
curl -X POST -H "Content-Type: application/json" \
-H "Authorization: Bearer $DO_TOKEN" \
-d '{"type":"transfer","region":"nyc2"}' \
"https://api.digitalocean.com/v2/images/$SNAPSHOT_ID/actions"
And with doctl:
doctl compute image-action transfer $SNAPSHOT_ID --region nyc2
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.