[ Web Proxy ]
URL:
Viewing: https://cloud.google.com/compute/docs/disks/creating-linux-application-consistent-pd-snapshots [Back]  [Original]

Create Linux application consistent disk snapshots  |  Compute Engine  |  Google Cloud Documentation Skip to main content
Google Cloud Documentation [Google Cloud Documentation]
Send feedback

Create Linux application consistent disk snapshots Stay organized with collections Save and categorize content based on your preferences.

You can create application consistent snapshots of Persistent Disk volumes attached to Linux virtual machine (VM) instances. In general, the quality of your disk snapshot depends on how well your applications can recover from snapshots that you create during heavy write workloads. 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.

To create snapshots that are application consistent, pause apps or operating system processes that write data to the disk, flush the disk buffers, and sync the file system before you create the snapshot. Depending on your application, these and other steps might be required to ensure that all application transactions are complete and captured in the backup.

To create an application consistent snapshot of your disks, use the following process:

  1. To prepare the guest environment for application consistency, create custom shell scripts to run before and after the snapshot is captured
  2. Configure snapshot settings on your VM instance.
  3. Create a snapshot with the guest-flush option enabled. The guest-flush option starts your pre- and post-snapshot scripts.

Before you begin

Required roles and permissions

To get the permissions that you need to create an application consistent snapshot, ask your administrator to grant you the following IAM roles on the project:

For more information about granting roles, see Manage access to projects, folders, and organizations.

These predefined roles contain the permissions required to create an application consistent snapshot. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to create an application consistent snapshot:

You might also be able to get these permissions with custom roles or other predefined roles.

Supported disk types

You can create application consistent snapshots for Persistent Disk volumes attached to Linux instances.

Hyperdisk volumes don't support guest-flush or the Volume Shadow Copy Service (VSS). To create application consistent snapshots for Hyperdisk volumes, you must manually pause the application before you create the snapshot. For more information, see Manually create application consistent snapshots.

Limitations

Creating application consistent snapshots on Linux has the following limitations:

Create pre- and post-snapshot scripts

Before you proceed, update the guest environment so that you are running the latest software on your Linux VM.

To facilitate application consistency, create pre- and post-snapshot shell scripts to run before and after the snapshot is captured. Use the pre and post scripts for operations such as:

The following code example shows a pre snapshot script. Note the leading #! characters.

Caution: Running fsfreeze -f blocks any running process that tries to access the file system, so use with caution if your application is latency-sensitive.
#!/bin/bash
sudo fsfreeze -f [example-disk-location]

The following code example shows a post snapshot script. Note the leading #! characters.

#!/bin/bash
sudo fsfreeze -u [example-disk-location]

You must save your scripts on your VM in the directory /etc/google/snapshots/. The full path of your pre script must be /etc/google/snapshots/pre.sh and the full path of your post script must be /etc/google/snapshots/post.sh.

Note: You must copy the scripts to every VM on which you want to enable Linux application consistent snapshots.

Referencing specific disks in your scripts

The first argument passed to your pre- and post-snapshot scripts is a list of disks for which you are creating snapshots. You can use this argument in your scripts for various checks. For example, if your VM has multiple disks attached but you only specified one disk in your snapshot request, you can check which disk the snapshot is being created for.

The argument is formatted as follows:

For example, your SCSI-attached boot disk might appear as 1/0 while an additional disk attached to the VM might appear as 2/0.

Edit your guest environment configuration file

Configure your application consistent snapshot settings by updating a specific configuration file on your VM.

  1. Open or create your guest environment configuration file.

    edit /etc/default/instance_configs.cfg
    
  2. Add the following section to the configuration file, then save your changes and exit the editor.

    [Snapshots]
    enabled = ENABLED
    timeout_in_seconds = TIMEOUT_SECONDS
    

    Replace the following:

    • ENABLED: Set to true to enable the application consistent snapshot feature. The default value is false.
    • TIMEOUT_SECONDS: The number of seconds the pre or post snapshot script can take to finish running before timing out. The integer value must be between 0 and 300. The default value is 60.

      Note: The number of seconds the entire snapshot operation can take to complete before a timeout error is 300 seconds per disk, and can't be changed.
  3. Restart the Guest Agent to use the new configuration settings.

    $ sudo systemctl restart google-guest-agent.service
    

Create a snapshot with guest-flush enabled

Using the Google Cloud console, the Google Cloud CLI, or REST, create a snapshot with the guest-flush option enabled. This starts running the pre- and post-snapshot scripts before and after the snapshot is captured.

Console

  1. Go to the Create a Snapshot page in the Google Cloud console.

    Go to the Create a Snapshot page
  2. Enter a snapshot Name.
  3. 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.

  4. Optional: Enter a Description of the snapshot.
  5. Under Source disk, select the existing disk that you want to create a snapshot of.
  6. 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:

    1. 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.
    2. 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.
  7. Check the Enable application consistent snapshot option.
  8. Click Create to create the snapshot.

gcloud

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.

Replace the following:

Note: Google recommends using the gcloud compute snapshots create command instead of the gcloud compute disks snapshot command because it supports more features, such as creating snapshots in a project different from the source disk project.

REST

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.

Replace the following:

Note: Google recommends using the snapshots.insert method instead of the disks.createSnapshot method because it supports more features, such as creating snapshots in a project different from the source disk project.

Create a snapshot schedule with guest-flush enabled

You can enable regular and automatic application consistent backups of your zonal and regional Persistent Disk volumes with snapshot schedules. To enable application consistent snapshots for your scheduled snapshots, use the --guest-flush option when you create the snapshot schedule so that the pre- and post-snapshot scripts execute before and after each scheduled snapshot.

For example, after configuring your guest environment configuration file and creating custom scripts, the following command creates hourly application consistent snapshots:

gcloud compute resource-policies create snapshot-schedule SCHEDULE_NAME \
  --description "MY HOURLY SNAPSHOT SCHEDULE" \
  --start-time 22:00 \
  --hourly-schedule 4 \
  --guest-flush \
  --max-retention-days SNAPSHOT_RETENTION_AGE

To learn more, see About snapshot schedules for disks.

Troubleshooting

Troubleshoot the snapshot schedule and creation process by reviewing reviewing logs and checking configurations.

Review the logs

  1. Go to the Logs Explorer page in the Google Cloud console:

    Go to Logs Explorer

  2. Paste the following query in the Log query pane:

    resource.type="gce_disk"
    jsonPayload.event_subtype="compute.disks.createSnapshot" OR
    protoPayload.methodName="ScheduledSnapshots"
    
  3. Run the query and investigate the logs:

    snapshot creation log query. [snapshot creation log query.]

Check configurations

What's next

Send feedback

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-08-12 UTC.

Need to tell us more? [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-08-12 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page