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

The following steps are provided as an example to assist you. Write your own script as per your applications requirement:

Steps

  1. Connect to your GCP Linux virtual machine.
  2. Ensure that the following folder is present on your virtual machine. Create it if not present.
    /etc/google/snapshots/
  3. 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>
  4. 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>
  5. 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.
  6. Edit your guest environment configuration file.
    1. Open a guest environment configuration file. Create a new file if not present.
      /etc/default/instance_configs.cfg
    2. Add the following attributes to the file.
      [Snapshots]
      enabled = false
      timeout_in_seconds = 60
    3. 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.