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

Using a snapshot to restore a persistent disk

Restore a snapshot to a boot persistent disk, or a non-boot persistent disk.

Restoring a boot disk snapshot

Use the Compute Engine console, gcloud, or API to restore a boot persistent disk snapshot.

Console

  1. Go to the Snapshots page in the Google Cloud Platform 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 boot disk.
  5. Stop the instance by clicking Stop. It can take several seconds for the instance to stop.
  6. Once the instance is stopped, click on it to make changes.
  7. At the top of the VM instance details page, click Edit.
  8. Under Boot Disk, click X to detach the existing boot disk.
  9. Under Boot Disk, click Add item.
  10. In the Name drop-down menu, click Create disk.
  11. Specify the following configuration parameters:
    • A name for the disk.
    • A type for the disk. The type selected must match the type used for the snapshot.
  12. Under Source type, click Snapshot.
  13. Select the name of the snapshot that you want to restore to the boot disk.
  14. (Optional) Select a size for the disk in GB. This number must be equal to or larger than the snapshot size. If not specified, the size is set to that of the snapshot.
  15. Click Create to create the disk.
  16. At the bottom of the instance details page, click Save to apply your changes to the instance and attach the new boot 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 instances stop command to stop the instance.

    gcloud compute instances stop [INSTANCE_NAME] \
        --zone [INSTANCE_ZONE]
    

    where:

    • [INSTANCE_NAME] is the name of the instance you want to stop.
    • [INSTANCE_ZONE] is the zone of the instance you want to stop.
  4. Use the gcloud compute instances detach-disk command to detach the boot disk from an instance.

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

    where:

    • [INSTANCE_NAME] is the name of the instance.
    • [DISK_NAME] is the name of the boot disk.
  5. Use the gcloud compute disks create command to create a new 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 snapshot size.
    • [SNAPSHOT_NAME] is the name of the snapshot being restored.
    • [DISK_TYPE] is the type of persistent disk, either pd-standard or pd-ssd.
  6. Use the gcloud compute instances attach-disk command to attach your persistent disk to the instance. You must add the --boot flag to attach this disk as a boot disk.

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

    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 boot persistent disk.

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

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

    where [PROJECT_ID] is your project ID.

  2. Construct a POST request to instances.stop to stop your VM instance.

    POST https://www.googleapis.com/compute/v1/projects/[PROJECT_ID]/zones/[ZONE]/instances/[INSTANCE_NAME]/stop
    

    where:

    • [PROJECT_ID] is your project ID.
    • [ZONE] is the zone where your instance is located.
    • [INSTANCE_NAME] is the name of your instance.
  3. Construct a POST request to instances.detachDisk to detach the boot disk from your VM instance.

    POST https://www.googleapis.com/compute/v1/projects/[PROJECT_ID]/zones/[ZONE]/instances/[INSTANCE_NAME]/detachDisk/[DISK_NAME]
    

    where:

    • [PROJECT_ID] is your project ID.
    • [ZONE] is the zone where your instance is located.
    • [INSTANCE_NAME] is the name of your instance.
    • [DISK_NAME] is the name of your boot disk.
  4. 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://www.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.
  5. Construct a POST request to the instances.attachDisk method, and include the URL to the zonal persistent disk that you just created. This is a boot disk, so set the boot parameter to true.

    POST https://www.googleapis.com/compute/v1/projects/[PROJECT_ID]/zones/[ZONE]/instances/[INSTANCE_NAME]/attachDisk
    
    {
     "boot": true,
     "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.
    • boot:true

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.

Alternatively, you can use a snapshot of a boot persistent disk to create a new VM instance. See Creating an instance from a snapshot.

Restoring a non-boot disk snapshot

You can restore a non-boot persistent disk snapshot to a persistent disk that is a larger size than the original snapshot, but you must run some additional commands in the instance for the additional space to be recognized.

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

To restore a non-boot persistent disk snapshot:

Console

  1. Go to the Snapshots page in the Google Cloud Platform 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. The type selected should match the type used for the snapshot.
  8. Under Source type, click Snapshot.
  9. Select the name of the snapshot that you want to restore.
  10. (Optional) Select a size for the disk in GB. This number must be equal to or larger than the snapshot size. If not specified, the size is set to that of 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 snapshot size.
    • [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://www.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://www.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://www.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 diagram below illustrates the process described above:

Diagram describing the
  process for deleting a snapshot

To delete a snapshot:

Console

  1. Go to the Snapshots page in the Google Cloud Platform 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://www.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

Σας βοήθησε αυτή η σελίδα; Πείτε μας τη γνώμη σας:

Αποστολή σχολίων σχετικά με…

Αυτή η σελίδα
Compute Engine Documentation