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.

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

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.

Before you begin

Creating a new VM instance boot disk from a snapshot

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. When you create that instance, you can restore a boot-disk snapshot to the boot disk, restore non-boot snapshots to new additional disks, or both.

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

Creating a new persistent disk from a non-boot snapshot

You can restore a snapshot of a non-boot persistent disk to a new 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.

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.

To restore a snapshot of a non-boot persistent disk to a new disk on an existing instance:

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 VM instances page.

    Go to the VM instances page

  4. Click the name of the instance where you want to restore your non-boot disk.
  5. At the top of the instance details page, click Edit.
  6. Under Additional disks, click Add new disk.
  7. Specify the following configuration parameters:
    • A name for the disk.
    • A type for the disk.
  8. Under Source type, click Snapshot.
  9. Select the name of the snapshot to restore.
  10. (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.
  11. Click Done to create the disk.
  12. At the bottom of the instance details page, click Save to apply your changes to the instance and attach the new 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 non-boot 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.
  4. 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

Use a snapshot to restore a non-boot persistent disk.

  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.
  3. Construct a POST request to the instances.attachDisk method, and include the URL to the zonal persistent disk that you just created.

    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 format and 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.

You can now use the instance to access the restored data and use the extra persistent disk space to store new data.

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

Czy ta strona była pomocna? Podziel się z nami swoją opinią:

Wyślij opinię na temat...

Compute Engine Documentation