A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cloud.google.com/compute/docs/disks/creating-linux-application-consistent-pd-snapshots below:

Create Linux application consistent disk snapshots | Compute Engine Documentation

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 disks 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 virtual machine (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 manage standard snapshots, 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 manage standard snapshots. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to manage standard snapshots:

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

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:

  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

Use scheduled snapshots to regularly and automatically backup your zonal and regional Persistent Disk and Google Cloud Hyperdisk. If you want to schedule application consistent snapshots for your backup, 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:

Check configurations What's next

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 2025-08-07 UTC.

[[["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 2025-08-07 UTC."],[[["Application-consistent snapshots of Linux VM disks capture application data with all transactions completed and pending writes flushed, crucial for data integrity during backups."],["Creating application-consistent snapshots involves pausing applications, flushing disk buffers, syncing the file system, and utilizing custom pre and post snapshot scripts."],["The `guest-flush` option must be enabled when creating a snapshot to trigger custom scripts that prepare the guest environment for application consistency."],["Proper configuration of the guest environment and the creation of custom pre and post snapshot scripts, saved in the `/etc/google/snapshots/` directory, are essential for successful application-consistent snapshots."],["Snapshots can be created manually or scheduled, with the option to define a storage location for them, and troubleshooting involves checking logs and ensuring correct script configuration and timeouts."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4