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
- If you want to use the command-line examples in this guide:
- Install or update to the latest version of the gcloud command-line tool.
- Set a default region and zone.
- If you want to use the API examples in this guide, set up API access.
- Create a Windows instance.
- Review the best practices for creating snapshots.
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
- Go to the Create a snapshot page.
- Enter a snapshot Name.
- Optionally, enter a Description of the snapshot.
- Under Source disk, select an existing disk from which you want to create a snapshot.
Skip this step to use the default snapshot storage location. Otherwise, to use a nondefault storage location:
- Under Location, select whether you want to store your snapshot in a Multi-regional location or a Regional location.
- 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.
Check the Enable VSS option to specify that this snapshot should use the Volume Shadow Copy Service.
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:
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.
Log in to the Windows VM instance attached to the disk.
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 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]
where:
[VOLUME_NUMBER]
is the volume that you need to configure for read/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 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:
- 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 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:
- Log in to your Windows instance.
- Download and install the Sync tool.
- Stop your applications from writing to your persistent disk.
- Run a command prompt as Administrator by right-clicking on the command prompt icon and selecting Run as administrator.
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
Log in to your Windows instance.
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 you just found:
DISKPART> select disk [DISK_NUMBER]
Replace
[DISK_NUMBER]
with the disk that you want to remount.Finally, unmount the disk:
DISKPART> offline disk
Create a snapshot
- If your persistent disk is located in a single zone, follow the steps in Creating a snapshot of a zonal persistent disk.
- Alternatively, if your persistent disk is located in a multiple zones, follow the steps in Creating a snapshot of a regional persistent disk.
Remount your disk
Log in to your Windows instance.
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 disk that you want to mount.Mount the disk:
DISKPART> online disk
Remove the read-only flag from the 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 volume that you need to configure for read/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 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
- If you took a snapshot of a boot disk, you can create an instance from the snapshot.
- To learn how to configure Windows Server so that you can use it to create customized Windows Server images for your instances or instance templates, read Creating a Windows Server image.