Create pre and post custom scripts
Prerequisites
Update all the Linux environments that you want to protect before you start to ensure that your virtual machine is using the most recent software.
About this task
Steps
- Connect to your GCP Linux virtual machine.
-
Ensure that the following folder is present on your virtual machine. Create it if not present.
/etc/google/snapshots/
-
Create a pre.sh file and save it on the
/etc/google/snapshots/ location.
The following example shows simple pre snapshot script.#!/bin/bash<Write the script that you want to execute after snapshot operation>
-
Create a post.sh file and save it on the
/etc/google/snapshots/ location.
The following example shows a simple postscript.#!/bin/bash<Write the script that you want to execute after snapshot operation>
-
Copy the scripts to every Linux VM on which you want to take application consistent snapshots.
NOTE: Ensure that the Pre and Post Script have the correct permissions for execution. Utilize the chmod command to grant execute permissions to the script files.
-
Edit your guest environment configuration file.
-
Open a guest environment configuration file. Create a new file if not present.
/etc/default/instance_configs.cfg
-
Add the following attributes to the file.
[Snapshots]enabled = falsetimeout_in_seconds = 60
-
Save the changes.
sudo systemctl restart google-guest-agent.service
Table 1. Description of attributes in Step 6 b Key Value Default Description enabled true or false false Whether the application consistent snapshot feature is enabled. timeout_in_seconds Integer [0, 300] 60 Number of seconds the pre or post snapshot script can take to finish running before a timeout error. Note that the number of seconds the entire snapshot operation can take to complete before a timeout error is 300 s per disk, and this is not configurable.
-
Open a guest environment configuration file. Create a new file if not present.