You can take snapshots of volumes. Volume snapshots save all the contents from the volume, and you can use them to create new volumes. By default, the data on volumes and their snapshots is encrypted at rest.
The same general guidelines apply for creating snapshots of volumes as apply with snapshots of Droplets: if there are applications that are actively writing to the volume, you should power off the Droplet attached to the volume before taking a snapshot to ensure data consistency.
Because snapshots of volumes operate at the block storage level, the snapshot size may not match what the filesystem reports. For example, filesystems may not immediately mark blocks as unused, which makes the block storage system include them in snapshots even though they don’t contain data.
You can trim or discard unused blocks to make your snapshots smaller and therefore less expensive. Configuring periodic fstrim
or mounting your volume with the discard option helps ensure that the block storage system knows which blocks are used and which are not.
Snapshot a Volume using the Control Panel
To create a snapshot of a volume from the control panel, in the left menu, click Droplets, then click the Volumes tab. Open the More menu for the volume you want to snapshot, then click Take Snapshot.
The window that opens lets you customize the name of the snapshot. Enter the name you’d like to use or accept the default, then click Take Snapshot to create a new snapshot.
Snapshot a Volume using Automation
How to Create a Block Storage Volume Snapshot Using the DigitalOcean CLI
- Install
doctl
, the official DigitalOcean CLI.
- Create a personal access token and save it for use with
doctl
.
- Use the token to grant
doctl
access to your DigitalOcean account.
- Finally, run
doctl compute volume snapshot
. Basic usage looks like this, but you can read the usage docs for more details:
doctl compute volume snapshot <volume-id> [flags]
The following example creates a snapshot of a volume with the UUID f81d4fae-7dec-11d0-a765-00a0c91e6bf6
:
doctl compute volume snapshot f81d4fae-7dec-11d0-a765-00a0c91e6bf6 --snapshot-name example-snapshot --tag frontend,backend
How to Create Snapshot From a Volume Using the DigitalOcean API
- Create a personal access token and save it for use with the API.
- Send a POST request to
https://api.digitalocean.com/v2/volumes/{volume_id}/snapshots
.
cURL
Using cURL:
curl -X POST \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
-d '{"name":"big-data-snapshot1475261774", "tags":["aninterestingtag"]}' \
"https://api.digitalocean.com/v2/volumes/82a48a18-873f-11e6-96bf-000f53315a41/snapshots"
Go
Using Godo, the official DigitalOcean API client for Go:
import (
"context"
"os"
"github.com/digitalocean/godo"
)
func main() {
token := os.Getenv("DIGITALOCEAN_TOKEN")
client := godo.NewFromToken(token)
ctx := context.TODO()
snapshot, _, err := client.Storage.CreateSnapshot(ctx, &godo.SnapshotCreateRequest{
VolumeID: "82a48a18-873f-11e6-96bf-000f53315a41",
Name: "my snapshot",
Description: "my description",
Tags: []string{"one", "two"},
})
}
Ruby
Using DropletKit, the official DigitalOcean API client for Ruby:
require 'droplet_kit'
token = ENV['DIGITALOCEAN_TOKEN']
client = DropletKit::Client.new(access_token: token)
client.volumes.create_snapshot(id: "82a48a18-873f-11e6-96bf-000f53315a41", name: "big-data-snapshot1475261774")
Python
Using PyDo, the official DigitalOcean API client for Python:
import os
from pydo import Client
client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
req = {
"name": "big-data-snapshot1475261774"
}
resp = client.volume_snapshots.create(volume_id="da3aa3a", body=req)