Hey All,
I want to create a script that will create a snapshot of a droplet, then add that snapshot to another region for redundancy. Is is possible to do this through the DO API?
Thanks
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Yes. The DigitalOcean API supports both taking a snapshot of a Droplet and transferring a copy of it to additional regions.
I’ve linked to the relevant API docs above, but here’s a quick example using doctl
, the DigitalOcean CLI:
SNAPSHOT_NAME="snapshot-$(date +%s)"
doctl compute droplet-action snapshot $DROPLET_ID \
--snapshot-name $SNAPSHOT_NAME \
--wait
IMAGE_ID=`doctl compute image list-user --no-header --format Name,ID \
| grep $SNAPSHOT_NAME \
| tr -s ' ' \
| cut -d ' ' -f2`
doctl compute image-action transfer $IMAGE_ID \
--region $NEW_REGION
--wait
flag. This blocks until the snapshot has been completed.--wait
flag here if you want the script to block until the transfer is complete.