Skip to content

GCE Application Consistency Snapshot

Purpose

Using GCE Application consistency snapshot allows executing related scripts before and after creating snapshots.

Notes

  • If no settings are configured, an error will occur. Therefore, it cannot be mixed with VMs that do not use the Application consistency feature.

you have to config Application consistency

  • In the command gcloud compute disks snapshot disk name --guest-flush, the --guest-flush option is equivalent to checking the Application consistency box.

Operation Steps

  1. First, check if the operating system is supported, and install or update the agent. Then add the following configuration to /etc/default/instance_configs.cfg:
Terminal window
1
[Snapshots]
2
enabled = true
3
timeout_in_seconds = 60 # 0-300 sec
  1. Create configuration files

The filenames /etc/google/snapshots/pre.sh and /etc/google/snapshots/post.sh cannot be changed. They represent the commands and tasks to be executed before and after the snapshot, respectively. Generally, you can use commands like sync to synchronize disk writes.

Terminal window
1
mkdir -p /etc/google/snapshots/
2
echo '#!/bin/bash
3
DATE=`date`
4
echo "${DATE} start"' >> /tmp/snapshot.log' > /etc/google/snapshots/pre.sh
5
6
echo '#!/bin/bash
7
DATE=`date`
8
echo "${DATE} finish"' >> /tmp/snapshot.log' > /etc/google/snapshots/post.sh
  1. Set execution permissions. Without setting permissions, snapshots will not be possible.
Terminal window
1
chmod +x /etc/google/snapshots/pre.sh
2
chmod +x /etc/google/snapshots/post.sh

If the script is not given execution permissions, the following error will occur:

Without permission error

  1. Restart the service
Terminal window
1
sudo systemctl restart google-guest-agent.service
  1. After executing the snapshot, you can see the script execution status

Executed result