Creating a Windows Persistent Disk Snapshot

This page explains how to create snapshots of a Windows persistent disk. To learn more about persistent disks, read the Persistent Disk documentation.

Compute Engine uses differential snapshots, which allow for better performance and lower storage charges for users. If you just want to configure your operating system and apply those same configurations to other instances, create images instead.

Create a Windows VSS snapshot

For most situations, taking snapshots with the Volume Shadow Copy Service (VSS) is the most simple way to make snapshots of persistent disks that are attached to Windows instances. You can create VSS snapshots without having to stop the instance or detach the persistent disk. VSS snapshots work both on boot persistent disks and on secondary persistent disks.

VSS snapshots are the same price as normal persistent disk snapshots, and charge only for the total size of the snapshot.

Restrictions

  • VSS snapshots work only on Windows instances with image version v20160810 and newer. For instances with older images, create a regular snapshot.
  • The persistent disk must use an NTFS, exFAT, or ReFS file system.
  • When you take a VSS snapshot, Windows marks the volume as read-only during the VSS proccess. If you want to create an instance from a VSS enabled snapshot you must clear the read-only flag on the volume.

Create the snapshot

Console


  1. Go to the Create a new snapshot page.
  2. Enter a snapshot name and select an existing disk from which you want to make a snapshot.
  3. Check the Enable VSS option to specify that this snapshot should use the Volume Shadow Copy Service.
  4. Click Create to create the snapshot.

gcloud


To create your snapshot, use the gcloud compute disks snapshot command with the --guest-flush flag to indicate that you want to create a VSS snapshot:

gcloud compute disks snapshot [DISK_NAME] --guest-flush

gcloud 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


Make a POST request to the [createSnapshot](/compute/docs/reference/latest/disks/createSnapshot) method and include the ?guestFlush=true parameter to indicate that you want to create a VSS snapshot:

POST  https://www.googleapis.com/compute/v1/projects/[PROJECT_ID]/zones/[ZONE]/disks/[DISK_NAME]/createSnapshot?guestFlush=true

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.

You now have a persistent disk snapshot that you can use to create new persistent disks.

Create a regular snapshot

In some situations, you might want to use the standard snapshot system to create snapshots of disks that are attached to Windows instances.

To create a snapshot:

  1. Unmount the filesystem
  2. Create a snapshot
  3. Remount your disk

Before you begin

Unmounting the filesystem

Before you create a persistent disk snapshot, make sure that you are taking a snapshot that is consistent with the desired state of your persistent disk. If you take a snapshot of your persistent disk in an "unclean" state, it may force a disk check and possibly lead to data loss. Follow these instructions to clear your disk buffers for your Windows instance.

  1. Log in to your Windows instance.

  2. Open a PowerShell command prompt and run the diskpart tool:

    PS C:\> diskpart
    

  3. Identify the disk that you want to unmount and snapshot:

    PS C:\> list disk
    

  4. Next, select the disk using the disk number you just found:

    DISKPART> select disk [DISK_NUMBER]
    

    where: [DISK_NUMBER] is the disk that you want to remount.

  5. Finally, unmount the disk:

    DISKPART> offline disk
    

If unmounting your persistent disk is not an option, such as in scenarios where an application might be writing data to the disk, you can sync your file system to flush the disk buffers. To sync your file system:

  1. Log in to your Windows instance.
  2. Download and install the Sync tool.
  3. Stop your applications from writing to your persistent disk.
  4. Run a command prompt as Administrator by right-clicking on the command prompt icon and selecting Run as administrator.
  5. In the command line terminal, run:

    PS C:\> sync [DRIVE_LETTER]
    

    where: [DRIVE_LETTER] is the drive letter for the volume that you want to sync. For example, F:\ or G:\.

Creating a snapshot

Console


  1. Go to the Create a new snapshot page in the Cloud Platform Console.

    Create a new snapshot

  2. If prompted, select a Cloud Platform Console project.
  3. Provide a name and description for the snapshot, select a source disk, and select an encryption option.
  4. Click Create to create the snapshot.

gcloud


Use the gcloud compute disks snapshot command:

gcloud compute disks snapshot [DISK_NAME]

where [DISK_NAME] is the name of the disk you want to make a snapshot of.

gcloud 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


Make a POST request to the createSnapshot method:

    POST https://www.googleapis.com/compute/v1/projects/[PROJECT_ID]/zones/us-central1-f/disks/[DISK_NAME]/createSnapshot
  • [PROJECT_ID] is the project ID for this request.
  • [DISK_NAME] is the name of the disk from which to create a snapshot.

Remounting your disk

Remount your disk and mark it as available for read-write.

  1. Log in to your Windows instance.

  2. Open a PowerShell command prompt and run the diskpart tool:

    PS C:\> diskpart
    

  3. Identify the disk that you want to remount:

    DISKPART> list disk
    

  4. Use the select disk command to re-select the disk:

    DISKPART> select disk [DISK_NUMBER]
    

    where: [DISK_NUMBER] is the disk that you want to remount.

  5. Remount the disk:

    DISKPART> online disk
    

After you remount the disk, remove read-only flag from the disk:

  1. On your Windows instance, use the diskpart command-line tool to select the offline disk:

    DISKPART> select disk [DISK_NUMBER]
    

    where: [DISK_NUMBER] is the disk that you want to remount.

  2. Bring the disk online:

    DISKPART> online disk
    

  3. List all the volumes in the disk:

    DISKPART> list volume
    

  4. Select the new volume:

    DISKPART> select volume [VOLUME_NUMBER]
    

    where: [VOLUME_NUMBER] is the volume that you need to configure for read-write.

  5. Check the volume attributes:

    DISKPART> attr volume clear readonly hidden nodefaultdriveletter shadowcopy
    

  6. Exit the diskpart tool:

    DISKPART> exit
    

  7. If the disk is a boot disk for another instance, sync the boot disk files with the new disk signature.

    PS C:\> bcdboot [DRIVE_LETTER]Windows /s [DRIVE_LETTER]
    

    where: [DRIVE_LETTER] is the drive letter for the volume that you want to sync. For example, F:\ or G:\.

What's next

Send feedback about...

Compute Engine Documentation