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, create disk images of them, and resize them at any time.


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
  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, run doctl compute volume-action attach. Basic usage looks like this, but you can 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
  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

    Using cURL:

                    # 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

    Using Godo, the official DigitalOcean V2 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()
    
      // 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

    Using DropletKit, the official DigitalOcean V2 API client for Ruby:

                    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.