Manage snapshot schedules for disks


This document describes how to manage snapshot schedules for your zonal and regional Persistent Disk and and Google Cloud Hyperdisk.

You can manage snapshot schedules as follows:

  • View snapshot schedules
  • Change snapshot schedules
  • Delete snapshot schedules

You can also configure alerts for scheduled snapshots.

Before you begin

  • If you haven't already, set up authentication. Authentication is the process by which your identity is verified for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine as follows.

    Select the tab for how you plan to use the samples on this page:

    Console

    When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

    gcloud

    1. Install the Google Cloud CLI, then initialize it by running the following command:

      gcloud init
    2. Set a default region and zone.

    REST

    To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.

      Install the Google Cloud CLI, then initialize it by running the following command:

      gcloud init

Required roles and permissions

To get the permissions that you need to create a snapshot schedule, ask your administrator to grant you the following IAM roles on the project:

For more information about granting roles, see Manage access.

These predefined roles contain the permissions required to create a snapshot schedule. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to create a snapshot schedule:

  • To view snapshot schedules: compute.resourcePolicies.list on the project or organization
  • To update a snapshot schedule:
    • compute.resourcePolicies.update on the resource policy
    • compute.resourcePolicies.get on the resource policy
  • To replace a snapshot schedule:
    • compute.resourcePolicies.use on the resource policy
    • compute.disks.addResourcePolicies on the disk
    • compute.disks.removeResourcePolicies on the disk
  • To delete a snapshot schedule:
    • compute.resourcePolicies.delete on the resource policy
    • compute.disks.removeResourcePolicies on the disk

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

View snapshot schedules

To get a list of snapshot schedules, use the console, gcloud command, or the Compute Engine API method. This request displays the name, description, and region of all snapshot schedules within a project.

Console

  1. In the Google Cloud console, go to the Snapshots page.

    Go to the Snapshots page

  2. Select the Snapshot schedules tab.
  3. Use the Filter field to narrow the list of snapshot schedules.
  4. Click the name of a snapshot schedule to see its details.

gcloud

To see a list of your snapshot schedules, use the resource-policies list command.

 gcloud compute resource-policies list

To see the description of a specific snapshot schedule, use the resource-policies describe command.

gcloud compute resource-policies describe SCHEDULE_NAME

Replace SCHEDULE_NAME with the name of the snapshot schedule.

REST

Make a GET a request to resourcePolicies.aggregatedList to return a list of the snapshot schedules for a project.

GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/aggregated/resourcePolicies

Replace PROJECT_ID with the project name.

View snapshot schedules by region

To view the snapshot schedules for a project within a particular region, use the Google Cloud console, gcloud CLI, or REST.

Console

  1. In the Google Cloud console, go to the Snapshots page.

    Go to the Snapshots page

  2. Select the Snapshot schedules tab.
  3. Use the Filter field to list snapshot schedules for a specific region.

gcloud

To view the snapshot schedules for a project within a specific region, use the resource-policies list command.

gcloud compute resource-policies list PROJECT_ID --filter REGION

Replace the following:

  • PROJECT_ID: the project name
  • REGION: the region, for example us-west1

REST

Make a GET request to resourcePolicies.list method to retrieve the snapshot schedules created within in a region.

GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/resourcePolicies

Replace the following:

  • PROJECT_ID: the project name
  • REGION: the region, for example us-west1

Change a snapshot schedule

After you create a snapshot schedule, you can modify the following fields dynamically, using the Update a snapshot schedule procedure:

  • Description
  • Snapshot schedule
  • Labels applied to the generated snapshots
  • Source disk deletion policy for handling auto-generated snapshots if the source disk is deleted
  • Retention policy to define how long to keep snapshots that are generated from the snapshot schedule

To update other values for a snapshot schedule, you must delete the snapshot schedule and create a new one, as described in Replace a snapshot schedule.

The snapshot schedule updates take effect in the first snapshot after the updates. If a snapshot is running while you update the snapshot schedule, the changes take effect in the following snapshot.

Update a snapshot schedule

You can use Google Cloud CLI or the Compute Engine API to change some of the properties of your snapshot schedule, as described in Change a snapshot schedule.

To change other properties of your snapshot schedule, use the method described in Replace a snapshot schedule.

Console

  1. In the Google Cloud console, go to the Snapshots page.

    Go to the Snapshots page

  2. Select Snapshot schedules to see a list of your schedules.
  3. Click the name of the snapshot schedule that you want to modify.
  4. On the snapshot schedule detail page, click the Edit schedule button.

gcloud

Use the compute resource-policies update command to update a snapshot schedule's description, schedule, retention policy, or labels.

gcloud compute resource-policies update snapshot-schedule SCHEDULE_NAME \
   --region=REGION \
   --description="DESCRIPTION" \
   --snapshot-labels="KEY=VALUE" \
   --max-retention-days=DAYS \
   --on-source-disk-delete=DELETE_OPTION \
   --start-time=START_TIME \
   SCHEDULE_FLAG

Replace the following:

  • SCHEDULE_NAME: the name of the snapshot schedule.
  • REGION: the region where your snapshot schedule resides.
  • DESCRIPTION: a description of the snapshot schedule. Use quotes around your description.
  • KEY and VALUE: a key-value pair that can be used to group related or associated resources.
  • DAYS: Maximum number of days snapshot is retained before being deleted.
  • DELETE_OPTION: Retention behavior of automatic snapshots after the original disk is deleted. The value must be one of:
    • apply-retention-policy: When the source disk is deleted, continue to apply the retention window for any snapshots created by the snapshot schedule.
    • keep-auto-snapshots: (Default) If the source disk is deleted, keep any snapshots created by the snapshot schedule, regardless of the retention window.
  • START_TIME: the UTC start time. The time must start on the hour. For example:
    • 2:00 PM PST is 22:00.
    • If you set a start time of 22:13, you will receive an error.
  • SCHEDULE_FLAG: one of the following flags:

    • --hourly-schedule=HOURLY_INTERVAL: the number of hours between every snapshot. The HOURLY_INTERVAL must be an integer between 1 and 23. For example, setting --hourly-schedule to 12, means the snapshot is generated every 12 hours.
    • --daily-schedule: performs a snapshot daily, at the START_TIME
    • --weekly-schedule=WEEKLY_INTERVAL: defines the day you want the snapshotting to occur. You must spell out the week day; the values are not case-sensitive.

    • --weekly-schedule-from-file=FILE_NAME: specifies a file that contains the weekly snapshot schedule. You can specify weekly schedules on different days of the week and at different times using a file. For example, your file might specify a snapshot schedule on Monday and Wednesday: none [{"day": "MONDAY", "startTime": "04:00"}, {"day": "WEDNESDAY", "startTime": "02:00"}] If you include a start time in your file, you don't need to set the --start-time flag. The schedule uses the UTC time zone. The time must start on the hour. For example:

      • 2:00 PM PST is 22:00.
      • If you set a start time of 22:13, you will receive an error.

    The snapshot frequency flags hourly-schedule, daily-schedule, weekly-schedule, and weekly-schedule-from-file are mutually-exclusive. You can use only one for your snapshot schedule.

Examples:

To change a snapshot schedule to a daily schedule:

gcloud compute resource-policies update snapshot-schedule SCHEDULE_NAME \
    --region=REGION --daily-schedule --start-time=START_TIME

To change a snapshot to an hourly schedule, and also update the description and snapshot label:

gcloud compute resource-policies update snapshot-schedule SCHEDULE_NAME \
    --region=REGION --description="DESCRIPTION" \
    --hourly-schedule=HOURLY_INTERVAL --start-time=START_TIME \
    --snapshot-labels="KEY=VALUE"

To change a snapshot retention and source disk deletion policies for a snapshot schedule:

gcloud compute resource-policies update snapshot-schedule SCHEDULE_NAME \
    --region=REGION --max-retention-days=DAYS \
    --on-source-disk-delete=DELETE_OPTION

REST

Construct a PATCH request to the resourcePolicies method to update a snapshot schedule's description, schedule, retention policy, source disk deletion policy, or labels. In the request body, you only need to specify the name and the fields you want to update.

  • Change the description and label:

    PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/resourcePolicies/SCHEDULE_NAME
    {
        "name": "SCHEDULE_NAME",
        "description": "DESCRIPTION",
        "snapshotProperties": {
            "labels": {"KEY": "VALUE"}
        }
    }
    
  • Change the snapshot schedule to hourly:

    PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/resourcePolicies/SCHEDULE_NAME
    {
        "name": "SCHEDULE_NAME",
        "snapshotSchedulePolicy": {
            "schedule": {
              "hourlySchedule": {
                  "hoursInCycle": HOURLY_INTERVAL,
                  "startTime": START_TIME
               }
            }
        }
    }
    
  • Change the snapshot schedule to daily:

    PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/resourcePolicies/SCHEDULE_NAME
    {
        "name": "SCHEDULE_NAME",
        "snapshotSchedulePolicy": {
            "schedule": {
              "dailySchedule": {
                  "daysInCycle": DAILY_INTERVAL,
                  "startTime": START_TIME
               }
            }
        }
    }
    
  • Change the snapshot schedule to weekly:

    PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/resourcePolicies/SCHEDULE_NAME
    {
        "name": "SCHEDULE_NAME",
        "snapshotSchedulePolicy": {
            "schedule": {
               "weeklySchedule": {
                  "dayOfWeeks": [
                     {
                        "day": WEEKLY_INTERVAL,
                        "startTime": START_TIME
                     }
                  ]
               }
            }
        }
    }
    
  • Change the snapshot retention policy:

    PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/resourcePolicies/SCHEDULE_NAME
    {
        "name": "SCHEDULE_NAME",
        "snapshotSchedulePolicy": {
            "retentionPolicy": {
                "maxRetentionDays": DAYS,
                "onSourceDiskDelete":"DELETE_OPTION"
            }
       }
    }
    

Replace the following:

  • PROJECT_ID: the project name.
  • REGION: the region where the snapshot schedule is located.
  • SCHEDULE_NAME: the name of the snapshot schedule.
  • DESCRIPTION: a description of the snapshot schedule. Use quotes around your description.
  • KEY and VALUE: a key- value pair that can be used to group related or associated resources.
  • HOURLY_INTERVAL: defines the interval at which you want snapshotting to occur. Set the hourly schedule using an integer between 1 and 23. To have the snapshots created at the same time every day, choose a number that divides evenly into 24 (1, 2, 3, 4, 6, 8, or 12). For example, setting --hourly-schedule to 12, means the snapshot is generated every 12 hours.
  • DAILY_INTERVAL: defines the number of days between each snapshot. To create a snapshot every day, use the value 1.
  • WEEKLY_INTERVAL: defines a schedule that runs on specific days of the week. Specify one or more days. The following options are available: MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, and SUNDAY. You must spell out the week days; they are not case-sensitive. You can define up to 7 intervals for dayOfWeeks, one for each day of the week.
  • START_TIME: the UTC start time. The time must start on the hour. For example:
    • 2:00 PM PST is 22:00 UTC.
    • If you set a start time of 22:13, you will receive an error.
  • DAYS: Maximum number of days snapshot is retained before being deleted.
  • DELETE_OPTION: Retention behavior of automatic snapshots after the original disk is deleted. The value must be one of:
    • APPLY_RETENTION_POLICY: When the source disk is deleted, continue to apply the retention window for any snapshots created by the snapshot schedule.
    • KEEP_AUTO_SNAPSHOTS: (Default) If the source disk is deleted, keep any snapshots created by the snapshot schedule, regardless of the retention window.

Replace a snapshot schedule

Follow these steps to delete the snapshot schedule and create a new one. Use this method to modify snapshot schedule properties that can't be changed by using the update a snapshot schedule procedure.

If you are replacing a snapshot schedule that is already attached to a disk, you must first detach the schedule from the disk and delete it. Then you can create a new schedule, and attach it to the disk.

Snapshots that are generated from the detached snapshot schedule won't be managed by the new policy. Those snapshots will be retained indefinitely until you delete them.

Use the Google Cloud console, gcloud CLI, or REST to remove and replace your snapshot schedule.

Console

  1. In the Google Cloud console, go to the Disks page.

    Go to the Disks page

  2. Select the disk that has the schedule you want to detach.
  3. On the Manage disk page, click Edit. You might need to click the More actions menu first.
  4. Open the Snapshot schedule drop-down menu.
  5. Click No schedule to detach the schedule from the disk.
  6. You can create a new schedule, or swap the schedule while you are editing the disk options.
  7. Click Save to complete the task.

gcloud

  1. Use the gcloud disks remove-resource-policies command to detach the snapshot schedule from the disk with the schedule that you want to change.

    gcloud compute disks remove-resource-policies DISK_NAME \
        --resource-policies SCHEDULE_NAME \
        --region REGION \
        --zone ZONE
    

    Replace the following:

    • DISK_NAME: the name of the disk with the snapshot schedule attached to it
    • SCHEDULE_NAME: the name of the snapshot schedule that you want to detach from this disk
    • REGION: the region where your snapshot schedule resides
    • ZONE: the zone where your zonal disk resides
  2. Use the gcloud disks add-resource-policies command to add the new snapshot schedule to the disk.

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

    Replace the following:

    • DISK_NAME: the name of the disk with the snapshot schedule resource policy
    • SCHEDULE_NAME: the name of the snapshot schedule that you want to add to this disk
    • ZONE: the zone where your disk resides

REST

  1. Detach the current snapshot schedule from a disk by constructing a POST request to disks.removeResourcePolicies.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks/DISK_NAME/removeResourcePolicies
    
    {
      "resourcePolicies": [
         "regions/REGION/resourcePolicies/SCHEDULE_NAME"
      ]
    }
    

    Replace the following:

    • PROJECT_ID: the project name
    • ZONE: the zone where the disk resides
    • DISK_NAME: the name of the disk with the associated snapshot schedule
    • REGION: the location of the snapshot schedule
    • SCHEDULE_NAME: the name of the snapshot schedule that you are removing from this disk
  2. Attach the new snapshot schedule to the disk by constructing a POST request to the disks.addResourcePolicies method.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks/DISK_NAME/addResourcePolicies
    
    {
      "resourcePolicies": [
        "regions/REGION/resourcePolicies/SCHEDULE_NAME"
      ]
    }
    

    Replace the following:

    • PROJECT_ID: the project name
    • ZONE: the location of the disk
    • DISK_NAME: the name of the disk
    • REGION: the location of the snapshot schedule
    • SCHEDULE_NAME: the name of the snapshot schedule that you are applying to this disk

Delete a snapshot schedule

If you delete a snapshot schedule, all auto-generated snapshots associated with the snapshot schedule are kept permanently. However, after the schedule is deleted, it can no longer generate snapshots.

Your retention policy is part of your snapshot schedule. After the schedule is deleted, your retention policy no longer applies. Snapshots that have already been generated are kept permanently until you manually delete them.

To delete an existing snapshot schedule, use the Google Cloud console, Google Cloud CLI, or the Compute Engine API method. If the schedule is already attached to a disk, detach the schedule from the disk first, then delete the schedule. You cannot delete a snapshot schedule that is attached to a disk.

Console

  1. In the Google Cloud console, go to the Snapshots page.

    Go to the Snapshots page

  2. Select Snapshot schedules to see a list of your schedules.
  3. Select any schedule not associated with a disk.
  4. Click Delete.

gcloud

To delete a snapshot schedule, use the resource-policies delete command.

gcloud compute resource-policies delete SCHEDULE_NAME \
    --region REGION

Replace the following:

  • SCHEDULE_NAME: the name of the snapshot schedule
  • REGION: the location of the snapshot schedule

REST

To delete a snapshot schedule, make a DELETE request to resourcePolicies.delete method. If the snapshot schedule is already attached to a disk, you will receive an error.

DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/resourcePolicies/SCHEDULE_NAME

Replace the following:

  • PROJECT_ID: the project name
  • REGION: the location of the snapshot schedule
  • SCHEDULE_NAME: the name of the snapshot schedule

Logging and monitoring

Every scheduled snapshot associated with a disk is continuously creating a system event, which is monitored and logged at all times. The system event audit logs are always enabled.

These logs provide behavioral information about your scheduled snapshots for each associated disk. You can view your logs from the Logging menu in the Google Cloud console.

For more information about using the Logs Explorer, see View logs by using the Logs Explorer.

Console

  1. In the Google Cloud console, go to the Logs Explorer page.

    Go to the Logs Explorer page

  2. In the Audited resource drop-down list, point to Disk and select All disk_id.

  3. In the All logs drop-down list, select cloudaudit.googleapis.com/system_event and click OK.

  4. In the Any log level drop-down list, select the log type.

What's next