Best Practices for Persistent Disk Snapshots

You can create persistent disk snapshots at any time, but you can create snapshots more quickly and with greater reliability if you use the following best practices.

Before you begin

Prepare your persistent disk for the best snapshot consistency

In most situations, you can create a snapshot from persistent disks even while your applications are writing data to those disks, and still expect the snapshot to have good consistency. The quality of the snapshot depends on the ability of your applications to recover from snapshots that you create during heavy write workloads.

If your applications require strict consistency, you can take additional steps to ensure that a snapshot is consistent with the desired state of the persistent disk.

Flushing your disk's buffers before a snapshot

You can create a snapshot of a persistent disk even while your applications write data to the disk. However, you can improve snapshot consistency if you flush the disk buffers and sync your file system before you create a snapshot.

Pause applications or operating system processes that write data to that persistent disk. Then flush the disk buffers before you create the snapshot.

To prepare your persistent disk before you take a snapshot do the following:

  1. Connect to your instance using SSH.
  2. Run an application flush to disk. For example, MySQL has a FLUSH statement. Use whichever tool is available for your application.
  3. Stop your applications from writing to your persistent disk.
  4. Run sudo sync.

If you skip this step, only data that is successfully flushed to disk by the application is included in the snapshot. The application experiences this scenario as if it was a sudden power outage.

Freeze and unmount your filesystem

An alternative option is to freeze or unmount the filesystem before you take a snapshot. This is the most reliable way to ensure that your disk buffers are cleared, but it is more time-consuming and not as convenient as simply flushing the disk buffers.

Unmount the persistent disk completely to ensure that no data is written to it while you create the snapshot. This is usually unnecessary, but it does improve the consistency of the snapshot.

  1. Connect to your instance using SSH.
  2. Stop any applications that are reading or writing data to the persistent disk.
  3. Either freeze the file system or unmount the file system.

    1. Freeze: sudo fsfreeze -f [example-disk_location]
    2. Unmount: sudo umount [example-disk_location]

    You can unfreeze or mount the file system after you complete your snapshot:

    1. Unfreeze: sudo fsfreeze -u [example-disk_location]
    2. Mount: sudo mount [example-disk_location mount_location]

Linux users

If your disk is connected to a Linux instance, unmount the disk from the instance by connecting to your instance and using the umount tool:

sudo umount /dev/disk/by-id/google-[DISK_NAME]

where [DISK_NAME] is the name of the persistent disk.

Windows users

If your disk is connected to a Windows instance, unmount the disk from the instance by connecting to your instance and using the Disk Management tool.

Remount the persistent disk

After you take a snapshot, you must remount the persistent disk. See Formatting and mounting a persistent disk for more information.

If your applications require consistency between multiple persistent disks, you must freeze or unmount all of the file systems on each disk and complete all of the snapshots for those disks before you resume your applications. Compute Engine does not guarantee consistency between simultaneous snapshots running on multiple persistent disks.

Use journaling file systems like ext4 to reduce the risk that data is cached without actually being written to the persistent disk.

Persistent disks using Windows Server instances

For persistent disks that are attached to Windows Server instances, use VSS Snapshots to help preserve data integrity.

Use existing snapshots as a baseline for subsequent snapshots

If you have existing snapshots on a persistent disk, the system automatically uses them as a baseline for any subsequent snapshots that you create from that same disk.

  • Create a new snapshot from a persistent disk before you delete the previous snapshot from that same persistent disk. The system can create the new snapshot more quickly if it can use the previous snapshot and reads only the new or changed data from the persistent disk.

  • Wait for new snapshots to finish before you take subsequent snapshots from the same persistent disk. If you run two snapshots simultaneously on the same persistent disk, they will both start from the same baseline and duplicate effort. If you wait for the new snapshot to finish, any subsequent snapshots will run more quickly because they need only to obtain the data that has changed since the last snapshot finished.

Schedule snapshots during off-peak hours

If you schedule regular snapshots for your persistent disks, you can reduce the time that it takes to complete each snapshot by creating them during off-peak hours when possible.

  • Schedule automated snapshots during the business day in the zone where your persistent disk is located. Snapshot creation typically peaks at the end of the business day.
  • Schedule automated snapshots early in the morning in the zone where your persistent disk is located rather than immediately at midnight. Snapshot creation typically peaks at midnight.

Organize your data on separate persistent disks

If you create a snapshot of a persistent disk, any data that you store on the disk will be included in the snapshot. Larger amounts of data create larger snapshots, which cost more and take longer to create. To ensure that you are snapshotting only the data that you need, organize your data on separate persistent disks.

  • Store critical data on a secondary persistent disk rather than your boot disk. This allows you to snapshot your boot disks only when necessary or on a less frequent schedule.
  • If you do create snapshots of your boot disks, store swap partitions, pagefiles, cache files, and non-critical logs on a separate persistent disk. These files and partitions change frequently and the snapshot process is likely to identify them as changed data that must be included in an incremental snapshot.
  • Reduce the number of snapshots that you need to create by keeping similar data together on one persistent disk. You do want to keep your operating system and volatile data separate from the data that you want to snapshot, but you do not need to distribute your critical data across multiple persistent disks like you would for a physical machine. One large persistent disk is able to achieve the same performance as multiple smaller persistent disks of the same total size.

Enable the discard option or run fstrim on your persistent disk

On Linux instances, if you did not format and mount your persistent disk with the discard option, run the fstrim command on the instance before you create a snapshot. The command removes blocks that the file system no longer needs so that the system can create the snapshot more quickly and with a smaller size. See formatting and mounting a persistent disk to learn how to configure the discard option on your persistent disks.

What's next

¿Te sirvió esta página? Envíanos tu opinión:

Enviar comentarios sobre…

Compute Engine Documentation