How to Move Volumes between Droplets

Volumes are network-based block devices that provide additional data storage for Droplets. You can move them between Droplets and resize them at any time. Learn more about volumes.


To move a volume between Droplets in the same region, you need to unmount and detach it from its current Droplet, then attach and mount it to the new Droplet.

Between Droplets in Same Region Using Automation

How to attach a volume to a Droplet using the DigitalOcean CLI

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

                  doctl compute volume-action attach <volume-id> <droplet-id> [flags]
                

    The following example attaches a volume with the UUID f81d4fae-7dec-11d0-a765-00a0c91e6bf6 to a Droplet with the ID 386734086

                   doctl compute volume-action attach f81d4fae-7dec-11d0-a765-00a0c91e6bf6 386734086
                

To detach a volume using the API, use the volume actions endpoints and set the type field to attach.

How to attach a volume to a Droplet using the DigitalOcean API

To attach a volume to a Droplet 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}/actions

    cURL

    To attach a volume to a Droplet with cURL, call:

    
                    # Attach a Volume to a Droplet by ID
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type": "attach", "droplet_id": 11612190, "region": "nyc1", "tags":["aninterestingtag"]}' \
      "https://api.digitalocean.com/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51/actions"
    
    # Remove a Volume from a Droplet by ID
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type": "detach", "droplet_id": "11612190", "region": "nyc1"}' \
      "https://api.digitalocean.com/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51/actions"
    
    # Resize a Volume
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"resize","size_gigabytes": 100, "region":"nyc1"}' \
      "https://api.digitalocean.com/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51/actions"

    Go

    Go developers can use Godo, the official DigitalOcean V2 API client for Go. To attach a volume to a Droplet 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()
    
      // Attach a Volume to a Droplet by ID
        action, _, err := client.StorageActions.Attach(ctx, "7724db7c-e098-11e5-b522-000f53304e51", 11612190)
    
      // Remove a Volume from a Droplet by ID
      // action, _, err := client.StorageActions.Detach(ctx, "7724db7c-e098-11e5-b522-000f53304e51")
    
      // Resize a Volume
      // action, _, err := client.StorageActions.Resize(ctx, "7724db7c-e098-11e5-b522-000f53304e51", 100, "nyc1")
    }

    Ruby

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

    
                    require 'droplet_kit'
    token = ENV['DIGITALOCEAN_TOKEN']
    client = DropletKit::Client.new(access_token: token)
    
    # Attach a Volume to a Droplet by ID
    client.volume_actions.attach(volume_id:'7724db7c-e098-11e5-b522-000f53304e51', droplet_id: 11612190, region: 'nyc1'
    
    
    # Remove a Volume from a Droplet by ID
    # client.volume_actions.detach(volume_id:'7724db7c-e098-11e5-b522-000f53304e51', droplet_id: 11612190, region: 'nyc1'

    Python

    
                    import os
    from pydo import Client
    
    client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
    
    req = {
      "type": "attach",
      "droplet_id": 11612190,
      "region": "nyc1",
      "tags": [
        "aninterestingtag"
      ]
    }
    
    resp = client.volume_actions.post_by_id(volume_id="7724db7c", body=req)

Between Droplets in the Same Region Using the Control Panel

  1. Unmount the volume from the current Droplet using the command line, or power down the Droplet. This makes sure the Droplet is not writing to the volume when you move it.

  2. Detach the volume from the current Droplet using the control panel. In the volume’s More menu, choose Detach from Droplet.

    One attached volume on the Volumes page, with the more menu open
  3. Attach the volume to a different Droplet using the control panel. In the volume’s More menu, choose Attach to Droplet., then select the Droplet you want to use.

    You can choose any Droplet in the same region. Droplets in other datacenters are visible but cannot be selected.

  4. Mount the volume to make it accessible to the new Droplet’s filesystem. The mount directions are also in the volume’s More menu, under Config instructions.

Between Droplets in Different Regions

Volumes are region-specific resources, meaning you can’t use them with Droplets in different regions. You currently can’t transfer volumes or snapshots of volumes to different regions.

As a workaround, you can create a new volume in the desired region, attach it to a Droplet, and use rsync or similar tools to copy the data from the original volume to the new one. Once you’ve confirmed the data transfer and no longer need the original volume, you can detach and destroy it.