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
- The first command creates the snapshot of the Droplet. It sets its name to include the unix timestamp of when it was created. Note the use of the
--wait
flag. This blocks until the snapshot has been completed.
- The next command finds the ID of the newly created image and stores it in a variable for use latter. Explaining the bash a bit: First it finds the image with the name we gave it. Next trims the white space. Finally it grabs the image ID.
- The final command transfers the image to a new region. You can also use the
--wait
flag here if you want the script to block until the transfer is complete.