# 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](https://docs.digitalocean.com/products/volumes/index.html.md). 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. Volume snapshots are instant, regardless of the volume’s size. The storage system freezes writes at a specific point in time and captures all data that has been written to disk at that moment. This makes volume snapshots **crash-consistent**: the snapshot contains the same data the volume would have after an unexpected system crash or power loss. However, volume snapshots do not guarantee **filesystem consistency**. The snapshot process does not coordinate with the operating system or running applications to flush in-memory caches or complete pending writes. This means a volume snapshot: - Includes all data already written to disk. - May include partially written files. - Excludes data still held in memory or application-level caches. The same general guidelines for [creating Droplet snapshots](https://docs.digitalocean.com/products/snapshots/how-to/snapshot-droplets/index.html.md) also apply to volume snapshots. If applications are actively writing to a volume, you should power off the Droplet attached to the volume before taking a snapshot to ensure data consistency. If powering off is not practical, run `sync` on the Droplet to flush pending writes to disk, or stop any database services before taking the snapshot. **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`](https://www.digitalocean.com/community/tutorials/how-to-configure-periodic-trim-for-ssd-storage-on-linux-servers) 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 the Control Panel To create a snapshot of a volume from the control panel, in the left menu, click **Droplets**, then click the **Volumes** tab. Open the **More** menu for the volume you want to snapshot, then click **Take Snapshot**. 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. ## Snapshot a Volume using Automation ## How to Create a Block Storage Volume Snapshot Using the DigitalOcean CLI 1. [Install `doctl`](https://docs.digitalocean.com/reference/doctl/how-to/install/index.html.md), the official DigitalOcean CLI. 2. [Create a personal access token](https://docs.digitalocean.com/reference/api/create-personal-access-token/index.html.md) and save it for use with `doctl`. 3. Use the token to grant `doctl` access to your DigitalOcean account. ```shell doctl auth init ``` 4. Finally, run `doctl compute volume snapshot`. Basic usage looks like this, but you can [read the usage docs](https://docs.digitalocean.com/reference/doctl/reference/compute/volume/snapshot/index.html.md) for more details: ```shell doctl compute volume snapshot [flags] ``` The following example creates a snapshot of a volume with the UUID `f81d4fae-7dec-11d0-a765-00a0c91e6bf6`: ```shell doctl compute volume snapshot f81d4fae-7dec-11d0-a765-00a0c91e6bf6 --snapshot-name example-snapshot --tag frontend,backend ``` ## How to Create Snapshot From a Volume Using the DigitalOcean API 1. [Create a personal access token](https://docs.digitalocean.com/reference/api/create-personal-access-token/index.html.md) and save it for use with the API. 2. Send a POST request to [`https://api.digitalocean.com/v2/volumes/{volume_id}/snapshots`](https://docs.digitalocean.com/reference/api/digitalocean//index.html.md#operation/volumeSnapshots_create). ### cURL Using cURL: ```shell 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 Using [Godo](https://github.com/digitalocean/godo), the official DigitalOcean API client for Go: ```go 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 Using [DropletKit](https://github.com/digitalocean/droplet_kit), the official DigitalOcean API client for Ruby: ```ruby 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 Using [PyDo](https://github.com/digitalocean/pydo), the official DigitalOcean API client for Python: ```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) ```