How to Create Volumes from Snapshots

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 use any volume snapshot to create new volumes in the same region.

Create a Volume from a Snapshot using Automation

To create a new volume from a snapshot, use the following volume creation doctl command or API endpoint, and set the snapshot field the snapshot’s image ID.

How to create a volume from a snapshot using the DigitalOcean CLI

To create a volume from a snapshot 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, create a volume from a snapshot with doctl compute volume create. The basic usage looks like this, but you'll want to read the usage docs for more details:

                  doctl compute volume create <volume-name> [flags]
                

    The following example creates a 4TiB volume named example-volume in the nyc1 region. The command also applies two tags to the volume

                       doctl compute volume create example-volume --region nyc1 --size 4TiB --tag frontend,backend
                    
How to create a volume from a snapshot using the DigitalOcean API

To create a volume from a snapshot 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

    cURL

    To create a volume from a snapshot with cURL, call:

    
                    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"size_gigabytes":10, "name": "example", "description": "Block store for examples", "region": "nyc1", "filesystem_type": "ext4", "filesystem_label": "example"}' \
      "https://api.digitalocean.com/v2/volumes"

    Go

    Go developers can use Godo, the official DigitalOcean V2 API client for Go. To create a volume from a snapshot 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()
    
        createRequest := &VolumeCreateRequest{
            Region:        "nyc1",
            Name:          "example",
            Description:   "Block store for examples",
            SizeGigaBytes: 10,
        }
    
        volume, _, err := client.Storage.CreateVolume(ctx, createRequest)
    }

    Ruby

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

    
                    require 'droplet_kit'
    token = ENV['DIGITALOCEAN_TOKEN']
    client = DropletKit::Client.new(access_token: token)
    
    volume = DropletKit::Volume.new(
      size_gigabytes: 10,
      name: 'Example',
      description: 'Block store for examples',
      region: 'nyc1'
    )
    client.volumes.create(volume)

    Python

    
                    import os
    from pydo import Client
    
    client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
    
    req = {
      "size_gigabytes": 10,
      "name": "ext4-example",
      "description": "Block store for examples",
      "region": "nyc1",
      "filesystem_type": "ext4",
      "filesystem_label": "ext4_volume_01"
    }
    
    resp = client.volumes.create(body=req)

Create a Volume from a Snapshot using the Control Panel

In the control panel, click Images in the main navigation, then click the Snapshots tab. In the Snapshots section, click the Volumes tab to view all volume snapshots in your account.

From there, open the More menu of the snapshot you want to use and click Create Volume to create a new volume based on it. In the window that opens, you can choose options for the new volume.

Create volume window

Choose a preset volume size or enter a custom volume size, either of which must be at least as big as the original volume used to create the snapshot. Next, select a Droplet to attach the volume to. The Droplet must be in a region which supports block storage. Finally, enter a name for the volume, and click Create Volume to create a new volume from the snapshot.