In Compute Engine, you can use snapshots to back up your disk data. Because snapshots are incremental, you can create them with higher performance and lower total storage charges compared to creating complete disk images.
Application consistent snapshots capture the state of application data at the time of backup with all application transactions completed and all pending writes flushed to the disk. On Windows VMs, you use the Volume Shadow Copy Service (VSS) to create application consistent snapshots without first stopping the instance or detaching the disk from your VM.
Before you begin
- Create a Windows instance.
- Review the best practices for creating snapshots.
-
If you haven't already, then set up authentication.
Authentication is
the process by which your identity is verified for access to Google Cloud services and APIs.
To run code or samples from a local development environment, you can authenticate to
Compute Engine by selecting one of the following options:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- Set a default region and zone.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
Limitations
Disk snapshots on Windows have the following limitations:
- VSS snapshots work only on Windows instances with image
version
v20160810
and newer. For instances with older images, create a snapshot without using VSS. - The attached 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 a Windows VSS snapshot
You can create Volume Shadow Copy Service (VSS) snapshots without having to stop the instance or detach the disk from your VM. 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 or Hyperdisk snapshots, and charge only for the total size of the snapshot.
Create the snapshot
Console
Go to the Create a Snapshot page in the Google Cloud console.
Go to the Create a Snapshot page- Enter a snapshot Name.
-
Select a Snapshot type. The default is a
STANDARD
snapshot, which is the best option for long-term back up and disaster recovery.Choose Archive snapshot for more cost-efficient data retention.
- Optional: Enter a Description of the snapshot.
- Under Source disk, select the existing disk that you want to create a snapshot of.
In the Location section, choose your snapshot storage location.
The predefined or customized default location defined in your snapshot settings is automatically selected. Optionally, you can override the snapshot settings and store your snapshots in a custom storage location by doing the following:
Choose the type of storage location that you want for your snapshot.
- Choose Multi-regional for higher availability at a higher cost.
- Choose Regional snapshots for more control over the physical location of your data at a lower cost.
- In the Select location field, select the 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.
- Check the Enable application consistent snapshot option.
- Click Create to create the snapshot.
gcloud
To create a VSS snapshot, use the
gcloud compute snapshots create
command
and include the --guest-flush
flag.
You can create your snapshot in the storage location policy defined by your snapshot settings or using an alternative storage location of your choice. For more information, see Choose your snapshot storage location.
To create a snapshot in the predefined or customized default location configured in your snapshot settings, use the
gcloud compute snapshots create
command.gcloud compute snapshots create SNAPSHOT_NAME \ --source-disk-zone=SOURCE_ZONE \ --source-disk=SOURCE_DISK_NAME \ --snapshot-type=SNAPSHOT_TYPE \ --guest-flush
-
Alternatively, to override the snapshot settings and create a snapshot in a custom storage location, include the
--storage-location
flag to indicate where to store your snapshot.gcloud compute snapshots create SNAPSHOT_NAME \ --source-disk-zone=SOURCE_ZONE \ --source-disk=SOURCE_DISK_NAME \ --snapshot-type=SNAPSHOT_TYPE \ --storage-location=STORAGE_LOCATION \ --guest-flush
Replace the following:
- SNAPSHOT_NAME: A name for the snapshot.
- SOURCE_ZONE: The zone of the source disk.
- SOURCE_DISK_NAME: The name of the disk volume from which you want to create a snapshot.
- SNAPSHOT_TYPE: The snapshot type, either STANDARD or ARCHIVE.
If a snapshot type is not specified, a
STANDARD
snapshot is created. -
STORAGE_LOCATION: Optional: The Cloud Storage multi-region or the Cloud Storage region where you want to store your snapshot. You can specify only one storage location.
Use the
--storage-location
parameter only when you want to override the predefined or customized default storage location configured in your snapshot settings.
To create a VSS snapshot of a regional Persistent Disk, in the previous examples replace
--source-disk-zone=
with--source-disk-region=
, and specify the region where your regional Persistent Disk is located.The Google Cloud CLI waits until the operation returns a status of
READY
,FAILED
, or reaches the maximum timeout and returns the last known details of the snapshot.
REST
When creating a snapshot, to indicate that you want to create a VSS
snapshot, include the guestFlush
property in the
request body for your POST
request to the
compute.snapshots.insert
method.
You can create your snapshot in the storage location policy defined by your snapshot settings or using an alternative storage location of your choice. For more information, see Choose your snapshot storage location.
-
To create a snapshot in the predefined or customized default location configured in your snapshot settings, make a
POST
request to thesnapshots.insert
method:POST https://compute.googleapis.com/compute/beta/projects/DESTINATION_PROJECT_ID/global/snapshots { "name": "SNAPSHOT_NAME", "sourceDisk": "projects/SOURCE_PROJECT_ID/zones/SOURCE_ZONE/disks/SOURCE_DISK_NAME", "snapshotType": "SNAPSHOT_TYPE", "guestFlush": true, }
-
Alternatively, to override the snapshot settings and create a snapshot in a custom storage location, make a
POST
request to thesnapshots.insert
method and include thestorageLocations
property in your request:POST https://compute.googleapis.com/compute/beta/projects/DESTINATION_PROJECT_ID/global/snapshots { "name": "SNAPSHOT_NAME", "sourceDisk": "projects/SOURCE_PROJECT_ID/zones/SOURCE_ZONE/disks/SOURCE_DISK_NAME", "snapshotType": "SNAPSHOT_TYPE", "storageLocations": [ "STORAGE_LOCATION" ], "guestFlush": true, }
Replace the following:
- DESTINATION_PROJECT_ID: The ID of project in which you want to create the snapshot.
- SNAPSHOT_NAME: A name for the snapshot.
- SOURCE_PROJECT_ID: The ID of the source disk project.
- SOURCE_ZONE: The zone of the source disk.
- SOURCE_DISK_NAME: The name of the disk from which you want to create a snapshot.
- SNAPSHOT_TYPE: The snapshot type, either STANDARD or ARCHIVE.
If a snapshot type is not specified, a
STANDARD
snapshot is created. -
STORAGE_LOCATION: Optional: The Cloud Storage multi-region or the Cloud Storage region where you want to store your snapshot. You can specify only one storage location.
Use the
storageLocations
parameter only when you want to override the predefined or customized default storage location configured in your snapshot settings.
To create a VSS snapshot of a regional Persistent Disk, in the POST
requests
shown previously, replace the following line:
"sourceDisk": "projects/SOURCE_PROJECT_ID/zones/SOURCE_ZONE/disks/SOURCE_DISK_NAME",
"sourceDisk": "projects/SOURCE_PROJECT_ID/regions/SOURCE_REGION/disks/SOURCE_DISK_NAME",
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 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 from booting correctly.
To work around this issue, remove the read-only flag from any new disk that you create from a VSS snapshot using the following steps:
Make sure the disk is attached to a VM:
- If the disk that you created from the VSS snapshot is a non-boot data disk, you can attach the disk to any new or existing VM.
- If the disk that you created from the VSS snapshot is a boot disk and you want to use it to boot a VM, then you must temporarily attach the disk to a separate, existing VM. After you complete the following steps, you can detach the disk from that VM and use it to boot a new VM instance.
Sign in to the Windows VM that the disk is attached to.
Open a PowerShell command prompt and run the
diskpart
tool.PS C:\> diskpart
Identify the disk that you want to mount.
DISKPART> list disk
Use the
select disk
command to select the disk.DISKPART> select disk DISK_NUMBER
Replace
DISK_NUMBER
with the number of the disk that you want to mount.Mount the disk.
DISKPART> online disk
List all the volumes in the disk.
DISKPART> list volume
Select the new volume.
DISKPART> select volume VOLUME_NUMBER
Replace
VOLUME_NUMBER
with the number of the volume to configure as read and write.Clear the read-only flag.
DISKPART> attr volume clear readonly hidden nodefaultdriveletter shadowcopy
Exit the
diskpart
tool.DISKPART> exit
If the disk is a boot disk for another VM, sync the boot disk files with the new disk signature.
PS C:\> bcdboot DRIVE_LETTERWindows /s DRIVE_LETTER
Replace
DRIVE_LETTER
with the drive letter for the volume that you want to sync. For example,F
forF:\
.
Create a snapshot without using VSS
In some situations, you might want to create snapshots of disks that are attached to Windows VMs without using VSS.
To create a disk snapshot on a Windows VM without using VSS, do the following:
- Prepare your system for a clean snapshot.
- Create the snapshot.
- Remount your disk
- Mark the disk as available for read/write
Prepare your system for a clean snapshot
Before you create a disk snapshot, make sure that you are taking a snapshot that is consistent with the state that you want for the disk. If you take a snapshot of your 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 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:
- Sign in to your Windows VM.
- Download and install the Sync tool from Microsoft.
- Stop your applications from writing to the disk.
- Open an elevated command prompt window.
In the command line window, run:
PS C:\> sync DRIVE_LETTER
Replace
DRIVE_LETTER
with the drive letter for the volume that you want to sync. For example,F
forF:\
.
Unmount the disk
Sign in to your Windows VM.
Open a PowerShell command prompt and run the
diskpart
tool.PS C:\> diskpart
Identify the disk that you want to unmount and snapshot.
DISKPART> list disk
Next, select the disk using the disk number that you just found.
DISKPART> select disk DISK_NUMBER
Replace
DISK_NUMBER
with the number of the disk that you want to remount.Unmount the disk.
DISKPART> offline disk
Create a snapshot
- If your disk is located in a single zone (zonal Persistent Disk or Hyperdisk), follow the steps in Create a snapshot of a zonal Persistent Disk volume.
- Alternatively, if your Persistent Disk is located in a multiple zones, follow the steps in Create a snapshot of a regional Persistent Disk volume.
Remount your disk
Sign in to your Windows VM.
Open a PowerShell command prompt and run the
diskpart
tool.PS C:\> diskpart
Identify the disk that you want to mount.
DISKPART> list disk
Use the
select disk
command to select the disk.DISKPART> select disk DISK_NUMBER
Replace
DISK_NUMBER
with the number of the disk that you want to mount.Mount the disk.
DISKPART> online disk
Remove the read-only flag from the disk
If needed, complete these steps:
Sign in to your Windows VM.
Open a PowerShell command prompt and run the
diskpart
tool.PS C:\> diskpart
List all the volumes in the disk.
DISKPART> list volume
Select the new volume.
DISKPART> select volume VOLUME_NUMBER
Replace
VOLUME_NUMBER
with the number of the volume that you want to configure for read and write.Clear the read-only flag.
DISKPART> attr volume clear readonly hidden nodefaultdriveletter shadowcopy
Exit the
diskpart
tool.DISKPART> exit
If the disk is a boot disk for another VM instance, at the PowerShell command prompt, 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
forF:\
.
What's next
- If you took a snapshot of a boot disk, you can create a VM from a snapshot.
- To learn how to configure Windows Server so that you can use it to create customized Windows Server images for your VMs or instance templates, read Create custom Windows Server images.