Restoring and deleting persistent disk snapshots

Use snapshots to incrementally back up data from your persistent disks. To learn how to create snapshots, see Creating persistent disk snapshots. After you create a snapshot, you can use it to restore your boot or non-boot persistent disk to a previous state captured by a point-in-time snapshot.

Backing up your data with a snapshot schedule is an effective best practice to manage workloads and minimize the effects of data loss.

You can create new disks from snapshots and images. Images are most useful for creating managed instance groups (MIGs) and creating many homogenous boot disks for new instances. Snapshots are most useful for backing up and restoring your persistent disks.

If you no longer need a specific snapshot, you can reduce storage costs by deleting the snapshot.

Before you begin

Listing snapshots

To see a list of snapshots available to a project, use the gcloud compute snapshots list command:

gcloud compute snapshots list

To list information about a particular snapshot, use the gcloud compute snapshots describe command:

gcloud compute snapshots describe [SNAPSHOT_NAME]

where [SNAPSHOT_NAME] is the name of the snapshot you want described.

Creating a new persistent disk from a snapshot

You can restore the contents of a snapshot to a persistent disk.

The new persistent disk must be at least the same size as the original source disk for the snapshot. If you create a persistent disk that is larger than the original source disk for the snapshot, you must run some additional commands in the instance so that the partitions can use the extra space.

You can create a new zonal persistent disk from a given snapshot at most once every ten minutes. If you want to issue a burst of requests to snapshot your disks, you can issue at most 6 requests in 60 minutes. This limit does not apply when creating regional persistent disks from a snapshot. For more information, see Snapshot frequency limits.

Depending on your operating system and file system type, you might need to use a different filesystem resizing tool. Refer to your operating system documentation for more information.

Restore a snapshot of a persistent disk to a new disk

Console

  1. Go to the Snapshots page in the Google Cloud Console.

    Go to the Snapshots page

  2. Find the name of the snapshot that you want to restore.
  3. Go to the Disks page in the Google Cloud Console.

    Go to the Disks page

  4. Click Create new disk.
  5. Specify the following configuration parameters:
    • A name for the disk.
    • A type for the disk.
    • Optionally, you can override the default region and zone selection. You can select any region and zone, regardless of the storage location of the source snapshot.
  6. Under Source type, click Snapshot.
  7. Select the name of the snapshot to restore.
  8. (Optional) Select a size for the disk in GB. This number must be equal to or larger than the original source disk for the snapshot. If you do not specify this value, the new disk will be the same size as the original source disk for the snapshot.
  9. Click Create to create the disk.

gcloud

  1. Use the gcloud compute snapshots list command to find the name of the snapshot you want to restore:

    gcloud compute snapshots list
    
  2. Use the gcloud compute snapshots describe command to find the size of the snapshot you want to restore:

    gcloud compute snapshots describe [SNAPSHOT_NAME]
    

    where [SNAPSHOT_NAME] is the name of the snapshot being restored.

  3. Use the gcloud compute disks create command to create a new regional or zonal persistent disk from your snapshot. If you need an SSD persistent disk for additional throughput or IOPS, include the --type flag and specify pd-ssd.

    gcloud compute disks create [DISK_NAME] \
        --size [DISK_SIZE] \
        --source-snapshot [SNAPSHOT_NAME] \
        --type [DISK_TYPE]
    

    where:

    • [DISK_NAME] is the name of the new disk.
    • [DISK_SIZE] is the size of the new disk in GB. This number must be equal to or larger than the original source disk for the snapshot.
    • [SNAPSHOT_NAME] is the name of the snapshot being restored.
    • [DISK_TYPE] is the type of persistent disk, either pd-standard or pd-ssd.

API

  1. Construct a GET request to snapshots.list to display the list of snapshots in your project.

    GET https://compute.googleapis.com/compute/v1/projects/[PROJECT_ID]/global/snapshots
    

    where [PROJECT_ID] is your project ID.

  2. Construct a POST request to create a zonal persistent disk using the disks.insert method. Include the name, sizeGb, and type properties. To restore a disk using a snapshot, you must include the sourceSnapshot property.

    POST https://compute.googleapis.com/compute/v1/projects/[PROJECT_ID]/zones/[ZONE]/disks
    
    {
     "name": "[DISK_NAME]",
     "sizeGb": "[DISK_SIZE]",
     "type": "zones/[ZONE]/diskTypes/[DISK_TYPE]"
     "sourceSnapshot": "[SNAPSHOT_NAME]"
    }
    

    where:

    • [PROJECT_ID] is your project ID.
    • [ZONE] is the zone where your instance and new disk are located.
    • [DISK_NAME] is the name of the new disk.
    • [DISK_SIZE] is the size of the new disk in GB.
    • [DISK_TYPE] is the type of persistent disk. Either pd-standard or pd-ssd.
    • [SNAPSHOT_NAME] is the source snapshot for the disk you are restoring.

Attach the new disk to an existing instance [optional]

Console

  1. Go to the VM instances page.

    Go to the VM instances page

  2. Click the name of the instance where you want to restore your non-boot disk.
  3. At the top of the instance details page, click Edit.
  4. Under Additional disks, click Attach existing disk.
  5. Select the name of the new disk made from your snapshot.
  6. Click Done to attach the disk.
  7. At the bottom of the instance details page, click Save to apply your changes to the instance.

gcloud

  1. Use the gcloud compute instances attach-disk command to attach your persistent disk to an instance:

    gcloud compute instances attach-disk [INSTANCE_NAME] \
        --disk [DISK_NAME]
    

    where:

    • [INSTANCE_NAME] is the name of the instance.
    • [DISK_NAME] is the name of the disk made from your snapshot.

API

  1. Construct a POST request to the instances.attachDisk method, and include the URL to the zonal persistent disk that you just created from your snapshot.

    POST https://compute.googleapis.com/compute/v1/projects/[PROJECT_ID]/zones/[ZONE]/instances/[INSTANCE_NAME]/attachDisk
    
    {
     "source": "/compute/v1/projects/[PROJECT_ID]/zones/[ZONE]/disks/[DISK_NAME]"
    }
    

    where:

    • [PROJECT_ID] is your project ID.
    • [ZONE] is the zone where your instance and new disk are located.
    • [INSTANCE_NAME] is the name of the instance where you are adding the new persistent disk.
    • [DISK_NAME] is the name of the new disk.

After you create and attach a new disk to an instance, you must mount the disk so that the operating system can use the available storage space.

If your disk is larger than the snapshot size, you need to resize the file system on that persistent disk to include the additional disk space.

Creating a new VM instance disk from a snapshot

When you create a new instance, you can use snapshots to create boot disks and data disks for that instance. In the event of an outage, you can quickly recover your data by restoring one or more persistent disk snapshots to the new persistent disks on a new instance.

For more information, see Creating an instance from persistent-disk snapshots.

Deleting a snapshot

Compute Engine uses incremental snapshots so that each snapshot contains only the data that has changed since the previous snapshot. For unchanged data, snapshots reference the data in previous snapshots. Storage costs for persistent disk snapshots charge only for the total size of the snapshot.

When you delete a snapshot, Compute Engine immediately marks the snapshot as DELETED in the system. If the snapshot has no dependent snapshots, it is deleted outright. However, if the snapshot does have dependent snapshots:

  1. Any data that is required for restoring other snapshots is moved into the next snapshot, increasing its size.
  2. Any data that is not required for restoring other snapshots is deleted. This lowers the total size of all your snapshots.
  3. The next snapshot no longer references the snapshot marked for deletion, and instead references the snapshot before it.

Because subsequent snapshots might require information stored in a previous snapshot, keep in mind that deleting a snapshot does not necessarily delete all the data on the snapshot. If any data on a snapshot that is marked for deletion is needed for restoring subsequent snapshots, that data is moved into the next corresponding snapshot. To definitively delete data from your snapshots, you should delete all snapshots.

If your disk has a snapshot schedule, you must detach the snapshot schedule from the disk before you can delete the schedule. Removing the snapshot schedule from the disk prevents further snapshot activity from occurring. You cannot delete a schedule that is attached to a disk. You have the option to manually delete snapshots at any time.

The following diagram shows the process described earlier:

The
  process for deleting a snapshot.

To delete a snapshot:

Console

  1. Go to the Snapshots page in the Google Cloud Console.

    Go to the Snapshots page

  2. Select one or more snapshots that you want to delete.
  3. At the top of the Snapshots page, click Delete.

gcloud

To delete a snapshot, use the gcloud compute snapshots delete command:

gcloud compute snapshots delete [SNAPSHOT_NAME]

where [SNAPSHOT_NAME] is the name of the snapshot being deleted.

API

Make a DELETE request to compute.snapshots.delete to delete snapshots.

DELETE https://compute.googleapis.com/compute/v1/projects/[PROJECT_ID]/global/snapshots/[SNAPSHOT_NAME]

where:

  • [PROJECT_ID] is the name of your project.
  • [SNAPSHOT_NAME] is the name of the snapshot to delete.

What's next