How to Create GCP Disk Snapshots and Snapshot Schedules

Snapshots in GCP are an important tool for backing up data and ensuring resilience. In this guide, we outline the steps for creating snapshots and snapshot schedules for GCP disks.

Patrick Londa
Sep 26, 2022
 min read
Share this post

Google Cloud Platform (GCP) disk snapshots are copies of data contained on persistent disks connected to your instances. Snapshots house information about data held on that disk during a specific period. 

While the first snapshot includes all data on a disk, subsequent copies only contain information relevant to subsequent changes. It’s essential that you learn to carefully manage your GCP disk snapshots to keep your instances functioning correctly.

Understanding GCP Disk Snapshots

You can use snapshots to restore a version of an instance, within or across projects. Compared to creating a full image, GCP disk snapshots are easier to create on a persistent disk and cost less.

Snapshots are created based on the last successful snapshot. Subsequent copies refer to the previous snapshot for any data that did not change, and the incremental nature of GCP disk snapshots helps organizations avoid getting billed for redundant information.

To consistently create snapshots, you can create snapshot schedules that automate snapshot creation at a certain interval. We’ll show the steps for creating schedules later in this post.

First, let's show how you can create a snapshot manually.

Blink Automation: Create a GCP Compute Disk Snapshot and Send to Slack
GCP + Slack
Try This Automation

Creating GCP Disk Snapshots

You can take GCP disk snapshots using gCloud CLI or the Google Cloud Console.

Creating a Snapshot Using the Google Cloud Console

1. Open the Google Cloud console, then go to the Create a Snapshot page.

2. Add a name for your snapshot.

3. Use the drop-down menu to pick the correct Source disk.

4. Decide which snapshot storage location to use. Go to Location and pick Regional or Multi-regional.

5. Select the correct region or multi-region to use for your snapshot. You can pick Based on disk’s location to use the default location closest to your area.

6. Click the Create button.

Creating a Snapshot Using the CLI

Open the CLI and enter the following command. Substitute your information for the parameters in brackets.

gcloud compute snapshots create [new-snap] -source-disk= [new-source-disk] 

As you can see, creating snapshots with the gCloud CLI is pretty simple, but you likely won't want to rely on a manual process. That's where snapshot schedules come in.

Creating Scheduled Snapshots for GCP Disks

By scheduling the creation of GCP disk snapshots, you can maintain a regular or automatic backup for Compute Engine workloads. 

When should you schedule snapshots?

As a best practice, you should schedule snapshots to be created early in the morning or at another low-traffic time of day, as they can be taken more quickly during these off-peak hours. Avoid scheduling the snapshots at the end of a business day or at midnight. These are the times when snapshot activity is at its peak.

It’s also important to set a retention policy for your snapshot schedules. Otherwise, snapshots will be kept indefinitely which can add to your data storage costs.

Where should you create snapshots?

Scheduled GCP disk snapshots must be created in the same zone as your GCP disk. For instance, if the GCP disk region is in us-west1-a, your snapshot schedule must be in the us-west1 location.

Blink Automation: Create a GCP Snapshot Schedule
Blink + GCP
Try This Automation

Creating a Snapshot Schedule Using the Google Cloud Console

These are the steps for creating a snapshot schedule using the console:

1. Go to the VM instances page in the Google Cloud console.

2. Click the name of the VM with a persistent disk that you want to create a snapshot schedule for. If you want to create a snapshot schedule for a Boot disk or Additional disk instead, you can select it under Storage.

3. Click edit, and choose Create a schedule under Snapshot schedule.

4. In Name, you can enter one of the following names:

  • boot-disk-snapshot-schedule
  • attached-persistent-disk-snapshot-schedule

5. You can then select Location. Regional snapshots offer more control of where your data is located at a lower cost, but the default is Multi-regional which are higher availability and higher cost. Select whichever best maps to your needs.

6. Click Create and click Save to attach the schedule to the persistent disk.

Once you have created the snapshot schedule, you can attach it to other disks by selecting it from the dropdown menu in the Snapshot schedule section while editing the Disk Details page.

Creating a Snapshot Schedule Using the gCloud CLI

1. Create a snapshot schedule using the gCloud command “compute resource-policies create snapshot-schedule”. Set an hourly, weekly, or daily snapshot schedule by including the related parameters.

 gcloud compute resource-policies create snapshot-schedule [SCHEDULE_NAME] \
    --description "[SCHEDULE_DESCRIPTION]" \      
    --max-retention-days [MAX_RETENTION_DAYS] \
    --start-time [START_TIME] \
    --hourly-schedule [SNAPSHOT_INTERVAL] \
    --daily-schedule \
    --weekly-schedule [SNAPSHOT_INTERVAL] \
    --weekly-schedule-from-file [FILE_NAME] \
    --on-source-disk-delete [DELETION_OPTION]
  • [SCHEDULE_DESCRIPTION] - snapshot schedule name.
  • [SCHEDULE_DESCRIPTION] - description of snapshot schedule. Use quotes around the description.
  • [MAX_RETENTION_DAYS] - the number of days snapshots remain before they are deleted.
  • [START_TIME] - Startup time. It must start on the hour, such as 22:00. Setting it to 22:13 will give an error.
  • [SNAPSHOT_INTERVAL] - the time during which you want snapshotting to occur. You can set it to an hourly, daily, or weekly schedule.
  • [FILE_NAME] - the file's name that contains the snapshot schedule.
  • [DELETION_OPTION] - this option decides what will happen to the snapshots if the source disk is deleted. You can choose default keep-auto-snapshots or apply-retention-policy to retain snapshots for ten days.

2. To validate that the schedule has been created, you can run this command:

gcloud compute resource-policies describe [SCHEDULE_NAME]

3. Next, you need to attach the schedule policy to a disk with this command:

gcloud compute disks add-resource-policies [DISK_NAME] \
    --resource-policies [SCHEDULE_NAME] \
    --zone [ZONE]

4. If you want to create a new disk that uses this schedule, you can use this command

gcloud compute disks create [DISK_NAME] \
    --resource-policies [SCHEDULE_NAME] \
    --zone [ZONE]

With these steps, you can create and implement snapshots schedules. By collecting snapshots regularly, you’ll reduce your risk of losing data if a disaster hits and ensure a certain level of resilience.

Automating GCP Snapshot Management with Blink

You can create snapshot schedules and attach them to disks manually, but it might be hard to develop and scale a consistent strategy. 

With Blink, you can easily attach snapshot schedules to disks based on certain parameters, check retention policies, and remove old snapshots. By using no-code automation steps, you have the ability to develop the kind of snapshot strategy that can help ensure consistent recoverability at an efficient cost.

Blink Automation: Create Compute Disk Snapshot with GCP and Send Results via Slack
Blink Automation: Create Compute Disk Snapshot with GCP and Send Results via Slack

This GCP automation in the Blink library relies on a few input parameters like which disk, project, and region is relevant to the snapshot.

With this information, the automation runs the following steps:

  1. Creates a snapshot of the specified compute disk.
  2. Sends a confirmation via Slack to a specified Slack group.

This is a simple automation, which makes it easy to customize based on your organization’s needs. For example, you can drag-and-drop new actions into the canvas or set up conditional logic.

You can build your own automation from scratch or use one of our 5K pre-built automations today.

Get started with Blink today and see how easy automation can be.

Automate your security operations everywhere.

Blink is secure, decentralized, and cloud-native. 
Get modern cloud and security operations today.

Get a Demo