Creating a Windows persistent disk snapshot


In Compute Engine, you can use snapshots to back up your persistent disk data. Because snapshots are incremental, you can create them with higher performance and lower total storage charges compared to creating complete persistent disk images.

Before you begin

Creating a Windows VSS snapshot

You can create VSS snapshots without having to stop the instance or detach the persistent disk. VSS snapshots are intended for backup and recovery purposes on systems with VSS-aware apps.

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.
  • VSS snapshots help to preserve your data only if you are running VSS-aware applications that can coordinate to create a consistent backup of your data.
  • If the VSS snapshot operation does not complete within 300 seconds, the snapshot fails with a timeout error.

Create the snapshot

Console

  1. 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. Skip this step to use the default snapshot storage location. Otherwise, to use a nondefault 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. Check the Enable VSS option to specify that this snapshot should use the Volume Shadow Copy Service.

  7. Click Create.

gcloud

To create a VSS snapshot, use the gcloud compute disks snapshot command and include the --guest-flush flag.

gcloud compute disks snapshot [DISK_NAME] --guest-flush
  • Replace [DISK_NAME] with the name of the zonal persistent disk from which you want to create a snapshot.

To create a VSS snapshot of a regional persistent disk, append --region [REGION] to the above command, replacing [REGION] with the region where your regional persistent disk is located.

The gcloud command-line tool 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

When creating a snapshot, include the ?guestFlush=true parameter to indicate that you want to create a VSS snapshot.

  • To create a VSS snapshot of a zonal persistent disk, make a POST request to the compute.disks.createSnapshot method:

    POST  https://compute.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 zonal persistent disk is located.
    • [DISK_NAME] is the name of the zonal persistent disk from which you want to create a VSS snapshot.
  • Alternatively, to create a VSS snapshot of a regional persistent disk, make a POST request to the compute.regionDisk.createSnapshot method:

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

    where:

    • [PROJECT_ID] is your project ID.
    • [REGION] is the region where your regional persistent disk is located.
    • [DISK_NAME] is the name of the regional persistent disk from which you want to create a VSS snapshot.

Optional: Mark your disk as available for read and write

When you create a VSS snapshot, Windows Server marks the volume in the snapshot as read-only. When you create a new persistent disk from the VSS snapshot, that disk is also set to read-only mode.

This might cause issues. For example, if you create a VM instance with a new boot disk from a VSS snapshot of an existing boot disk, the read-only flag on the new boot disk prevents the VM instance from booting correctly.

To work around this, remove the read-only flag from any new disk that you create from a VSS snapshot using the following steps:

  1. Make sure the disk is attached to a VM instance.

    • If the disk you created from the VSS snapshot is a non-boot data disk, you can attach the disk to any new or existing VM instance.
    • If the disk you created from the VSS snapshot is a boot disk and you want to use it to boot a VM instance, you must temporarily attach the disk to a separate, existing VM instance. Once you complete the following steps, you can detach the disk from that existing VM instance and use it to boot a new VM instance.
  2. Log in to the Windows VM instance attached to the disk.

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

    PS C:\\> diskpart
    
  4. Identify the disk that you want to mount:

    DISKPART> list disk
    
  5. Use the select disk command to select the disk:

    DISKPART> select disk [DISK_NUMBER]
    

    Replace [DISK_NUMBER] with the disk that you want to mount.

  6. Mount the disk:

    DISKPART> online disk
    
  7. List all the volumes in the disk:

    DISKPART> list volume
    
  8. Select the new volume:

    DISKPART> select volume [VOLUME_NUMBER]
    

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

  9. Clear the read-only flag:

    DISKPART> attr volume clear readonly hidden nodefaultdriveletter shadowcopy
    
  10. Exit the diskpart tool:

    DISKPART> exit
    
  11. 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]
    

    Replace [DRIVE_LETTER] with the drive letter for the volume that you want to sync. For example, `F:`.

Creating a snapshot without using VSS

In some situations, you might want to create snapshots of disks that are attached to Windows instances without using VSS.

To create a Windows snapshot without using VSS, do the following:

  1. Prepare your system for a clean snapshot.
  2. Create the snapshot.
  3. Remount your disk
  4. Mark the disk as available for read/write

Prepare your system for a clean snapshot

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. Consider syncing and unmounting your file system.

Sync the file system

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]
    

    Replace [DRIVE_LETTER] with the drive letter for the volume that you want to sync. For example, F:\.

Unmount the disk

  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:

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

    DISKPART> select disk [DISK_NUMBER]
    

    Replace [DISK_NUMBER] with the disk that you want to remount.

  5. Finally, unmount the disk:

    DISKPART> offline disk
    

Create a snapshot

Remount your disk

  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 mount:

    DISKPART> list disk
    
  4. Use the select disk command to select the disk:

    DISKPART> select disk [DISK_NUMBER]
    

    Replace [DISK_NUMBER] with the disk that you want to mount.

  5. Mount the disk:

    DISKPART> online disk
    

Remove the read-only flag from the disk

  1. List all the volumes in the disk:

    DISKPART> list volume
    
  2. Select the new volume:

    DISKPART> select volume [VOLUME_NUMBER]
    

    Replace [VOLUME_NUMBER] with the volume that you need to configure for read/write.

  3. Clear the read-only flag:

    DISKPART> attr volume clear readonly hidden nodefaultdriveletter shadowcopy
    
  4. Exit the diskpart tool:

    DISKPART> exit
    
  5. 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]
    

    Replace [DRIVE_LETTER] with the drive letter for the volume that you want to sync. For example, F:\.

What's next