Creating a Windows Persistent Disk Snapshot

Compute Engine provides incremental snapshots that you can use to back up your persistent disk data. Because snapshots are incremental, you can create them with higher performance and a lower total storage charges compared to creating complete persistent disk images. Snapshots are intended for back up and archival purposes.

To learn how to configure Windows Server so you can use it to create customized Windows Server images for your instances or instance templates, read Creating a Windows Server image.

Before you begin

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 are intended for backup and recovery purposes on systems with VSS-aware applications. Use VSS snapshots only for backing up data from persistent disks. Creating VM instance boot disks from snapshots of running instances is not reliable.

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 are not intended to be used for copying or backing up the operating system on a persistent boot disk.
  • When you create a VSS snapshot, Windows Server marks the volume in the snapshot as read-only during the VSS process. Any disks that you create from the VSS snapshot will also be in read-only mode.
  • 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.

Create the snapshot

Console

  1. Go to the Create a new 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 to create the snapshot.

gcloud

When creating your snapshot, include the --guest-flush flag to indicate that you want to create a VSS snapshot. If your are creating a snapshot of a regional persistent disk, also include the --region flag.

  • To create a VSS snapshot of a zonal persistent disk, use the gcloud compute disks snapshot command:

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

    where [DISK_NAME] is the name of the zonal persistent disk from which you want to create a snapshot.

  • Alternatively, to create a VSS snapshot of a regional persistent disk, use the gcloud compute disks snapshot command:

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

    where:

    • [DISK_NAME] is the name of the regional persistent disk from which you want to create a snapshot.
    • [REGION] is 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://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 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://www.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.

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

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:\` orG:`.

Creating a snapshot

  1. Follow the steps for creating a snapshot of a persistent disk.

  2. After you create your snapshot, remount the persistent disk.

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:\` orG:`.

What's next

Var denne siden nyttig? Si fra hva du synes:

Send tilbakemelding om ...

Compute Engine Documentation