How to Create or Restore Droplets 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 snapshot created from a Droplet to create new Droplets in any region where the snapshot is available.

You can also use snapshots to restore a Droplet to the point in time when the snapshot was taken. This can be useful for restoring files that were accidentally deleted or to revert to a known-good Droplet to recover from accidental configuration changes.

If you create a snapshot and then resize a Droplet, you can still restore that Droplet with the snapshot as long as the snapshot’s size is equal to or less than the Droplet’s new storage size.

Snapshots do not preserve a Droplet’s metadata, such as its settings and IP, only the contents of its disk. That metadata remains on that specific Droplet.

Create New Droplets from a Snapshot

Using the Control Panel

To create a Droplet from a snapshot, click the Create menu and select Droplets. On the Droplet creation page, in the Choose an image section, click Snapshots, and then click the snapshot you want to use.

Choosing snapshots during Droplet creation

Continue creating the Droplet normally by selecting the Droplet size, region, and any additional options.

Note
You must select a disk size equal to or larger than the Droplet used to create the snapshot.

Finally, click Create to create a Droplet based on the selected snapshot.

Using Automation

You can create new Droplets from snapshots using the Droplet creation doctl command or API endpoint, and setting the image field to the snapshot’s image ID.

How to Create a New 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 droplet create. Basic usage looks like this, but you can read the usage docs for more details:

                doctl compute droplet create <droplet-name>... [flags]
              

    The following example creates a Droplet named example-droplet with a two vCPUs, two GiB of RAM, and 20 GBs of disk space. The Droplet is created in the nyc1 region and is based on the ubuntu-20-04-x64 image. Additionally, the command uses the --user-data flag to run a Bash script the first time the Droplet boots up:

                  doctl compute droplet create example-droplet --size s-2vcpu-2gb --image ubuntu-20-04-x64 --region nyc1 --user-data $'#!/bin/bash\n touch /root/example.txt; sudo apt update;sudo snap install doctl'
                
How to Create a New 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/droplets

    cURL

    Using cURL:

                    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"name":"example.com","region":"nyc3","size":"s-1vcpu-1gb","image":"ubuntu-20-04-x64","ssh_keys":[289794,"3b:16:e4:bf:8b:00:8b:b8:59:8c:a9:d3:f0:19:fa:45"],"backups":true,"ipv6":true,"monitoring":true,"tags":["env:prod","web"],"user_data":"#cloud-config\nruncmd:\n  - touch /test.txt\n","vpc_uuid":"760e09ef-dc84-11e8-981e-3cfdfeaae000"}' \
      "https://api.digitalocean.com/v2/droplets"
                  

    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()
    
        createRequest := &godo.DropletCreateRequest{
            Name:   "example.com",
            Region: "nyc3",
            Size:   "s-1vcpu-1gb",
            Image: godo.DropletCreateImage{
                Slug: "ubuntu-20-04-x64",
            },
            SSHKeys: []godo.DropletCreateSSHKey{
                godo.DropletCreateSSHKey{ID: 289794},
                godo.DropletCreateSSHKey{Fingerprint: "3b:16:e4:bf:8b:00:8b:b8:59:8c:a9:d3:f0:19:fa:45"}
            },
            Backups: true,
            IPv6: true,
            Monitoring: true,
            Tags: []string{"env:prod","web"},
            UserData: "#cloud-config\nruncmd:\n  - touch /test.txt\n",
            VPCUUID: "760e09ef-dc84-11e8-981e-3cfdfeaae000",
        }
                  

    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)
    
    droplet = DropletKit::Droplet.new(
      name: 'example.com',
      region: 'nyc3',
      size: 's-1vcpu-1gb',
      image: 'ubuntu-20-04-x64',
      ssh_keys: [289794,"3b:16:e4:bf:8b:00:8b:b8:59:8c:a9:d3:f0:19:fa:45"],
      backups: true,
      ipv6: true,
      monitoring: true,
      tags: ["env:prod","web"],
      user_data: "#cloud-config\nruncmd:\n  - touch /test.txt\n",
      vpc_uuid: "760e09ef-dc84-11e8-981e-3cfdfeaae000",
    )
    client.droplets.create(droplet)
                  

    Python

                    import os
    from pydo import Client
    
    client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
    
    req = {
      "name": "example.com",
      "region": "nyc3",
      "size": "s-1vcpu-1gb",
      "image": "ubuntu-20-04-x64",
      "ssh_keys": [
        289794,
        "3b:16:e4:bf:8b:00:8b:b8:59:8c:a9:d3:f0:19:fa:45"
      ],
      "backups": True,
      "ipv6": True,
      "monitoring": True,
      "tags": [
        "env:prod",
        "web"
      ],
      "user_data": "#cloud-config\nruncmd:\n  - touch /test.txt\n",
      "vpc_uuid": "760e09ef-dc84-11e8-981e-3cfdfeaae000"
    }
    
    resp = client.droplets.create(body=req)
                  

Restore a Snapshot on an Existing Droplet

Using the Control Panel

To replace all the data on an existing Droplet with the image of one of its snapshots, in the control panel’s left menu, click Backups & Snapshots. This takes you to a list of all the snapshots available on your team.

Find the snapshot you want to restore the Droplet from and open its More menu, then select Restore Droplet. A Restore Droplet window confirms the action.

Restore Droplet window

Click Restore Droplet to restore the Droplet from the selected snapshot.

Using Automation

You can restore a Droplet from a snapshot using the following command, or by sending a request to the Droplet action endpoint and setting the restore field to a snapshot’s image ID.

How to Restore a Droplet From a Snapshot 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 droplet-action restore. Basic usage looks like this, but you can read the usage docs for more details:

                doctl compute droplet-action restore <droplet-id> [flags]
              

    The following example restores a Droplet with the ID 386734086 from a backup image with the ID 146288445:

                  doctl compute droplet-action restore 386734086 --image-id 146288445
                
How to Restore a Droplet From a Snapshot 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/droplets/{droplet_id}/actions

    cURL

    Using cURL:

                    # Enable Backups
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"enable_backups"}' \
      "https://api.digitalocean.com/v2/droplets/3164450/actions"
    
    # Disable Backups
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"disable_backups"}' \
      "https://api.digitalocean.com/v2/droplets/3164450/actions"
    
    # Reboot a Droplet
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"reboot"}' \
      "https://api.digitalocean.com/v2/droplets/3164450/actions"
    
    # Power cycle a Droplet
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"power_cycle"}' \
      "https://api.digitalocean.com/v2/droplets/3164450/actions"
    
    # Shutdown and Droplet
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"shutdown"}' \
      "https://api.digitalocean.com/v2/droplets/3067649/actions"
    
    # Power off a Droplet
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"power_off"}' \
      "https://api.digitalocean.com/v2/droplets/3164450/actions"
    
    # Power on a Droplet
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"power_on"}' \
      "https://api.digitalocean.com/v2/droplets/3164450/actions"
    
    # Restore a Droplet
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"restore", "image": 12389723 }' \
      "https://api.digitalocean.com/v2/droplets/3067649/actions"
    
    # Password Reset a Droplet
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"password_reset"}' \
      "https://api.digitalocean.com/v2/droplets/3164450/actions"
    
    # Resize a Droplet
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"resize","size":"1gb"}' \
      "https://api.digitalocean.com/v2/droplets/3164450/actions"
    
    # Rebuild a Droplet
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"rebuild","image":"ubuntu-16-04-x64"}' \
      "https://api.digitalocean.com/v2/droplets/3164450/actions"
    
    # Rename a Droplet
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"rename","name":"nifty-new-name"}' \
      "https://api.digitalocean.com/v2/droplets/3164450/actions"
    
    # Change the Kernel
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"change_kernel","kernel":991}' \
      "https://api.digitalocean.com/v2/droplets/3164450/actions"
    
    # Enable IPv6
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"enable_ipv6"}' \
      "https://api.digitalocean.com/v2/droplets/3164450/actions"
    
    # Enable Private Networking
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"enable_private_networking"}' \
      "https://api.digitalocean.com/v2/droplets/3164450/actions"
    
    # Snapshot a Droplet
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"snapshot","name":"Nifty New Snapshot"}' \
      "https://api.digitalocean.com/v2/droplets/3164450/actions"
    
    # Acting on Tagged Droplets
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"enable_backups"}' \
      "https://api.digitalocean.com/v2/droplets/actions?tag_name=awesome"
    
    # Retrieve a Droplet Action
    curl -X GET \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      "https://api.digitalocean.com/v2/droplets/3164444/actions/36804807"
                  

    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()
    // Enable Backups
        action, _, err := client.DropletActions.EnableBackups(ctx, 3164450)
    
    // Disable Backups
    //  action, _, err := client.DropletActions.DisableBackups(ctx, 3164450)
    
    // Reboot a Droplet
    //  action, _, err := client.DropletActions.Reboot(ctx, 3164450)
    
    // Power Cycle a Droplet
    //  action, _, err := client.DropletActions.PowerCycle(ctx, 3164450)
    
    // Shutdown a Droplet
    //  action, _, err := client.DropletActions.Shutdown(ctx, 3067649)
    
    // Power Off a Droplet
    //  action, _, err := client.DropletActions.PowerOff(ctx, 3164450)
    
    // Power On a Droplet
    //  action, _, err := client.DropletActions.PowerOn(ctx, 3164450)
    
    // Restore a Droplet
    //  action, _, err := client.DropletActions.Restore(ctx, 3164449, 12389723)
    
    // Password Reset a Droplet
    //  action, _, err := client.DropletActions.PasswordReset(ctx, 3164450)
    
    // Resize a Droplet
    //  action, _, err := client.DropletActions.Resize(ctx, 3164450, "1gb", true)
    
    // Rebuild a Droplet
    //  action, _, err := client.DropletActions.RebuildByImageSlug(ctx, 3164450, "ubuntu-16-04-x64")
    
    // Rename a Droplet
    //  action, _, err := client.DropletActions.Rename(ctx, 3164450, "nifty-new-name")
    
    // Change the Kernel
    //  action, _, err := client.DropletActions.ChangeKernel(ctx, 3164450, 991)
    
    // Enable IPv6
    //  action, _, err := client.DropletActions.EnableIPv6(ctx, 3164450)
    
    // Enable Private Networking
    //  action, _, err := client.DropletActions.EnablePrivateNetworking(ctx, 3164450)
    
    // Snapshot a Droplet
    //  action, _, err := client.DropletActions.Snapshot(ctx, 3164450, "Nifty New Snapshot")
    
    // Retrieve a Droplet Action
    //  action, _, err := client.DropletActions.Get(ctx, 3164450, 36804807)
    
    }
                  

    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)
    
    # Enable Backups
    client.droplet_actions.enable_backups(droplet_id: 3164450)
    
    # Disable Backups
    # client.droplet_actions.disable_backups(droplet_id: 3164450)
    
    # Reboot a Droplet
    # client.droplet_actions.reboot(droplet_id: 3164450)
    
    # Power Cycle a Droplet
    # client.droplet_actions.power_cycle(droplet_id: 3164450)
    
    # Shutdown a Droplet
    # client.droplet_actions.shutdown(droplet_id: 3067649)
    
    # Power Off a Droplet
    # client.droplet_actions.power_off(droplet_id: 3164450)
    
    # Power On a Droplet
    # client.droplet_actions.power_on(droplet_id: 3164450)
    
    # Restore a Droplet
    # client.droplet_actions.restore(droplet_id: 3067649, image: 12389723)
    
    # Password Reset a Droplet
    # client.droplet_actions.password_reset(droplet_id: 3164450)
    
    # Resize a Droplet
    # client.droplet_actions.resize(droplet_id: 3164450, size: '1gb')
    
    # Rebuild a Droplet
    # client.droplet_actions.rebuild(droplet_id: 3164450, image: 'ubuntu-16-04-x64')
    
    # Rename a Droplet
    # client.droplet_actions.rename(droplet_id: 3164450, name: 'nifty-new-name')
    
    # Change the Kernel
    # client.droplet_actions.change_kernel(droplet_id: 3164450, kernel: 991)
    
    # Enable IPv6
    # client.droplet_actions.enable_ipv6(droplet_id: 3164450)
    
    # Enable Private Networking
    # client.droplet_actions.enable_private_networking(droplet_id: 3164450)
    
    # Snapshot a Droplet
    # client.droplet_actions.snapshot(droplet_id: 3164450, name: 'Nifty New Snapshot')
                  

    Python

                    import os
    from pydo import Client
    
    client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
    
    # enable back ups example
    req = {
      "type": "enable_backups"
    }
    
    resp = client.droplet_actions.post(droplet_id=346652, body=req)