How to Create Snapshots of Volumes

Snapshots are on-demand disk images of DigitalOcean Droplets and volumes saved to your account. Use them to create new Droplets and volumes with the same contents.


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.

Note

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 Automation

How to snapshot a volume using the DigitalOcean CLI

To snapshot a volume via the command-line, follow these steps:

  1. Install doctl, the DigitalOcean command-line tool.

  2. Create a personal access token, and save it for use with doctl.

  3. Use the token to grant doctl access to your DigitalOcean account.

                  doctl auth init
                
  4. Finally, snapshot a volume with doctl compute volume snapshot. The basic usage looks like this, but you'll want to 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 snapshot a volume using the DigitalOcean API

To snapshot a volume using the DigitalOcean API, follow these steps:

  1. Create a personal access token, and save it for use with the API.

  2. Send a POST request to https://api.digitalocean.com/v2/volumes/{volume_id}/snapshots

    cURL

    To snapshot a volume with cURL, call:

    
                    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

    Go developers can use Godo, the official DigitalOcean V2 API client for Go. To snapshot a volume with Godo, use the following code:

    
                    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

    Ruby developers can use DropletKit, the official DigitalOcean V2 API client for Ruby. To snapshot a volume with DropletKit, use the following code:

    
                    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

    
                    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)

Snapshot a Volume using the Control Panel

To create a snapshot of a volume from the control panel, click Droplets in the main navigation, then click the Volumes tab. Open the More menu for the volume you want to snapshot, then click Take Snapshot.

Volumes more menu

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.