Create and manage disk snapshots

Create snapshots to periodically back up data from your zonal persistent disks or regional persistent disks.

You can create snapshots from disks even while they are attached to running instances. Snapshots are global resources, so you can use them to restore data to a new disk or instance within the same project. You can also share snapshots across projects.

Before you begin

Prepare for creating snapshots

To prepare for creating persistent disk snapshots, do the following:

Create a snapshot of a zonal persistent disk

Console

  1. In the console, go to the VM instances page.

    Go to VM instances
    The remaining steps will appear automatically in the console.

  2. In the Name column, click the name of the VM that has the persistent disk to back up.
  3. In Storage:
    • To back up the boot disk, in the Boot disk section, click the Name of the boot disk.
    • To back up an attached persistent disk, in Additional disks, click the Name of the attached persistent disk.
  4. Click Create snapshot.
  5. In Name, enter a unique name to help identify the purpose of the snapshot, for example:
    • boot-disk-snapshot
    • attached-persistent-disk-snapshot
  6. In Location, the default is Multi-regional, which provides higher availability at a higher cost.

    Choose Regional snapshots for more control over the physical location of your data at a lower cost.

  7. To create a manual snapshot, click Create.

gcloud

Create your snapshot in the default storage location or in a selected storage location. You must specify a snapshot name. The name must be 1-63 characters long, and comply with RFC 1035.

  • To create a snapshot of a persistent disk in the default storage location, use the gcloud compute snapshots create command.

    gcloud compute snapshots create SNAPSHOT_NAME \
        --source-disk SOURCE_DISK \
        --source-disk-zone SOURCE_DISK_ZONE
    

    Replace the following:

    • SNAPSHOT_NAME: A name for the snapshot.
    • SOURCE_DISK: The name of the persistent disk from which you want to create a snapshot.
    • SOURCE_DISK_ZONE: The zone of the persistent disk from which you want to create a snapshot.
  • Alternatively, to create a snapshot in a custom storage location, use the --storage-location flag to indicate where to store your snapshot:

    gcloud compute snapshots create SNAPSHOT_NAME \
        --source-disk SOURCE_DISK \
        --source-disk-zone SOURCE_DISK_ZONE \
        --storage-location STORAGE_LOCATION
    

    Replace the following:

    • SNAPSHOT_NAME: A name for the snapshot.
    • SOURCE_DISK: The name of the persistent disk from which you want to create a snapshot.
    • SOURCE_DISK_ZONE: The zone of the persistent disk from which you want to create a snapshot.
    • STORAGE_LOCATION: The Cloud Storage multi-region or the Cloud Storage region where you want to store your snapshot. You can specify only one storage location.

The gcloud CLI waits until the operation returns a status of READY or FAILED, or reaches the maximum timeout and returns the last known details of the snapshot.

API

Create your snapshot in the default storage location or in a selected storage location.

  • To create your snapshot in the default storage location, make a POST request to the snapshots.insert method:

    POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/global/snapshots
    
    {
      "name": SNAPSHOT_NAME
      "sourceDisk": "projects/SOURCE_PROJECT_ID/zones/SOURCE_ZONE/disks/SOURCE_DISK_NAME
    }
    

    Replace the following:

    • DESTINATION_PROJECT_ID: The ID of project in which you want to create the snapshot.
    • SNAPSHOT_NAME: A name for the snapshot.
    • SOURCE_PROJECT_ID: The ID of the source disk project.
    • SOURCE_ZONE: The zone of the source disk.
    • SOURCE_DISK_NAME: The name of the persistent disk from which you want to create a snapshot.
  • Alternatively, to create a snapshot in a custom storage location, make a POST request to the snapshots.insert method and specify the storage location:

    POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/global/snapshots
    
    {
      "name": SNAPSHOT_NAME
      "sourceDisk": "projects/SOURCE_PROJECT_ID/zones/SOURCE_ZONE/disks/SOURCE_DISK_NAME
      "storageLocations": STORAGE_LOCATION
    }
    

    Replace the following:

    • DESTINATION_PROJECT_ID: The ID of project in which you want to create the snapshot.
    • SNAPSHOT_NAME: A name for the snapshot.
    • SOURCE_PROJECT_ID: The ID of the source disk project.
    • SOURCE_ZONE: The zone of the source disk.
    • SOURCE_DISK_NAME: The name of the persistent disk from which you want to create a snapshot.
    • STORAGE_LOCATION: The Cloud Storage multi-region or the Cloud Storage region where you want to store your snapshot. You can specify only one storage location.

Create a snapshot of a regional persistent disk

After you have prepared the disk, you can create a snapshot. When creating a snapshot of a regional persistent disk, you must indicate the region where the disk is located.

Console

  1. Go to the Create a Snapshot page in the Google Cloud console.
    Go to the Create a Snapshot page
  2. Enter a snapshot Name.
  3. Optionally, enter a Description of the snapshot.
  4. Under Source disk, select an existing disk from which you want to create a snapshot.
  5. Optionally, you can specify a custom storage location:

    1. Under Location, select whether you want to store your snapshot in a Multi-regional location or a Regional location.
    2. Select which specific region or multi-region that you want to use. To use the region or multi-region that is closest to your source disk, select Based on disk's location.
  6. Click Create to create the snapshot.

gcloud

Create your snapshot in the default storage location or in a selected storage location.

  • To create a snapshot of a regional persistent disk in the default storage location, use the gcloud compute snapshots create command.

    gcloud compute snapshots create SNAPSHOT_NAME \
        --source-disk SOURCE_DISK \
        --source-disk-region=SOURCE_DISK_REGION
    

    Replace the following:

    • SNAPSHOT_NAME: A name for the snapshot.
    • SOURCE_DISK: The name of the persistent disk from which you want to create a snapshot.
    • SOURCE_DISK_REGION: The region of the regional persistent disk from which you want to create a snapshot.
  • Optionally, you can specify a custom storage location.

    gcloud compute snapshots create SNAPSHOT_NAME \
        --source-disk SOURCE_DISK \
        --source-disk-region=SOURCE_DISK_REGION
        --storage-location STORAGE_LOCATION
    

    Replace the following:

    • SNAPSHOT_NAME: A name for the snapshot.
    • SOURCE_DISK: The name of the persistent disk from which you want to create a snapshot.
    • SOURCE_DISK_REGION: The region of the regional persistent disk from which you want to create a snapshot.
    • STORAGE_LOCATION: The Cloud Storage multi-region or the Cloud Storage region where you want to store your snapshot. You can specify only one storage location.

    The Google Cloud CLI waits until the operation returns a status of READY, FAILED, or reaches the maximum timeout and returns the last known details of the snapshot.

API

  • To create a snapshot in the default storage location, make a POST request to the snapshots.insert method:

    POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/global/snapshots
    {
      "name": SNAPSHOT_NAME
      "sourceDisk": "projects/SOURCE_PROJECT_ID/regions/SOURCE_REGION/disks/SOURCE_DISK_NAME
    }
    

    Replace the following:

    • DESTINATION_PROJECT_ID: The ID of project in which you want to create the snapshot.
    • SNAPSHOT_NAME: A name for the snapshot.
    • SOURCE_PROJECT_ID: The ID of the source disk project.
    • SOURCE_REGION: The region of the source disk.
    • SOURCE_DISK_NAME: The name of the persistent disk from which you want to create a snapshot.
  • Alternatively, to create a snapshot in a custom storage location, make a POST request to thesnapshots.insert method and specify the storage location:

    POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/global/snapshots
    {
      "name": SNAPSHOT_NAME
      "sourceDisk": "projects/SOURCE_PROJECT_ID/regions/SOURCE_REGION/disks/SOURCE_DISK_NAME
      "storageLocations": STORAGE_LOCATION
    }
    

    Replace the following:

    • DESTINATION_PROJECT_ID: The ID of project in which you want to create the snapshot.
    • SNAPSHOT_NAME: A name for the snapshot.
    • SOURCE_PROJECT_ID: The ID of the source disk project.
    • SOURCE_REGION: The region of the source disk.
    • SOURCE_DISK_NAME: The name of the persistent disk from which you want to create a snapshot.
    • STORAGE_LOCATION: The Cloud Storage multi-region or the Cloud Storage region where you want to store your snapshot. You can specify only one storage location.

Delete a snapshot

Compute Engine uses differential snapshots so that each snapshot contains only the data that has changed since the previous snapshot. 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. To learn more about snapshot deletion, see Snapshot deletion.

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 method 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.

Delete multiple snapshots based on a filter

Compute Engine uses differential snapshots so that each snapshot contains only the data that has changed since the previous snapshot. Because subsequent snapshots might require information stored in a previous snapshot, deleting a snapshot does not necessarily delete all the data on the snapshot. To learn more about snapshot deletion, see Snapshot deletion.

The following sections describe how to delete a number of snapshots based on a given filter. For more information on gcloud CLI filters, see gcloud CLI topic filters.

To delete the snapshots, use a combination of the gcloud compute snapshots list command with a given filter, and the gcloud compute snapshots delete command with xargs:

gcloud compute snapshots list --filter="EXPRESSION" --uri |
   xargs gcloud compute snapshots delete

Replace EXPRESSION with a gcloud topic filter.

For example, --filter="creationTimestamp>'2021-01-01'" deletes all snapshots created after 2021-01-01.

List snapshots

gcloud

To see a list of snapshots available to you in a particular project, use the gcloud compute snapshots list command.

gcloud compute snapshots list --project PROJECT_ID

where PROJECT_ID is the ID of the project.

API

To see a list of snapshot available to you in a particular project, make a GET request to the snapshots.list method:

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

where PROJECT_ID is the ID of the project.

View information about a snapshot

To list information about a particular snapshot, such as the creation time, size, and source disk, use the gcloud compute snapshots describe command:

gcloud compute snapshots describe SNAPSHOT_NAME

where SNAPSHOT_NAME is the name of the snapshot.

Share snapshot data across projects

To move data from a disk in one project to a disk in a different project, use the following process:

gcloud

  1. Create a disk snapshot in the destination project by using the gcloud compute snapshots create command. For example, to create a snapshot of a zonal persistent disk, use the following command:

    gcloud compute snapshots create SNAPSHOT_NAME \
        --source-disk https://www.googleapis.com/compute/v1/projects/SOURCE_PROJECT_ID/zones/ZONE/disks/SOURCE_DISK_NAME \
        --project DESTINATION_PROJECT_ID
    

    Replace the following:

    • SNAPSHOT_NAME: A name for the snapshot.
    • SOURCE_PROJECT_ID: The ID of the source disk project.
    • ZONE: The zone of the source disk.
    • SOURCE_DISK_NAME: The name of the source disk.
    • DESTINATION_PROJECT_ID: The ID of the destination project for the new snapshot.
  2. In the destination project, create a zonal or regional disk that's based on the snapshot by using the gcloud compute disks create command:

    gcloud compute disks create DISK_NAME \
        --source-snapshot SNAPSHOT_NAME \
        --project DESTINATION_PROJECT_ID
    

    Replace the following:

    • DISK_NAME: A name for the new disk.
    • SNAPSHOT_NAME: The name of the snapshot.
    • DESTINATION_PROJECT_ID: The ID of the destination project for the new disk.

API

  1. Create a disk snapshot in the destination project by calling the snapshots.insert method. For example, to take a snapshot of a zonal persistent disk, make the following request:

    POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/global/snapshots
    
    {
      "name": SNAPSHOT_NAME
      "sourceDisk": "projects/SOURCE_PROJECT_ID/zones/SOURCE_ZONE/disks/SOURCE_DISK_NAME
    }
    

    Replace the following:

    • DESTINATION_PROJECT_ID: The ID of the destination project for the new snapshot.
    • SNAPSHOT_NAME: A name for the snapshot.
    • SOURCE_PROJECT_ID: The ID of the source disk project.
    • SOURCE_ZONE: The zone of the source disk.
    • SOURCE_DISK_NAME: The name of the source disk.
  2. In the destination project, create a zonal or regional disk that's based on the snapshot by using the zonal disks.insert method or the regional regionDisks.insert method. For example, to create a zonal disk, make the following request:

    POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/zones/DESTINATION_ZONE/disks
    
    {
      "name": DISK_NAME
      "sourceSnapshot": SNAPSHOT_NAME
    }
    

    Replace the following:

    • DESTINATION_PROJECT_ID: The ID of the destination project for the new disk.
    • DISK_NAME: A name for the new disk.
    • SNAPSHOT_NAME: The name of the snapshot.

To get a list of snapshots available to you, see Listing snapshots.

What's next