Stay organized with collections Save and categorize content based on your preferences.
Linux Windows
You create a snapshot schedule to regularly and automatically back up zonal and regional Persistent Disk and Google Cloud Hyperdisk volumes. Use snapshot schedules as a best practice to back up your Compute Engine workloads.
If you want to create a snapshot schedule that captures the state of the application data at the time of back up, also referred to as an application consistent, guest-flush, or VSS snapshot, see Create Linux application consistent disk snapshots or Create a Windows application consistent disk snapshot.
For more information about the snapshot schedule properties, see Snapshot schedule properties.
Before you beginSelect the tab for how you plan to use the samples on this page:
ConsoleWhen you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloudInstall the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.To use the Go samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
JavaTo use the Java samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
Node.jsTo use the Node.js samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
PythonTo use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
RESTTo 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.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
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:
roles/compute.instanceAdmin.v1
)roles/iam.serviceAccountUser
)For more information about granting roles, see Manage access to projects, folders, and organizations.
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 permissionsThe following permissions are required to create a snapshot schedule:
compute.resourcePolicies.create
on the project or organization compute.disks.addResourcePolicies
on the disk compute.resourcePolicies.use
on the resource policy compute.disks.create
on the project compute.resourcePolicies.create
on the project compute.disks.addResourcePolicies
on the diskYou might also be able to get these permissions with custom roles or other predefined roles.
Overview of creating snapshot schedulesWhen you create a snapshot schedule, you create a resource policy that you can apply to one or more Persistent Disk or Hyperdisk volumes.
You can create snapshot schedules in the following ways:
If a disk uses a customer-managed encryption key (CMEK), when you use a snapshot schedule to create snapshots of that disk, all the created snapshots are automatically encrypted with the same key.
You can't use snapshot schedules with disks that use a customer-supplied encryption key (CSEK).
Create a snapshot scheduleYou can create a snapshot schedule for your disks using the Google Cloud console, Google Cloud CLI, or REST. You must create your snapshot schedule in the same region where your disk resides. For example, if your disk resides in zone us-west1-a
, you must create the snapshot schedule in the us-west1
region. However, you can choose to store the snapshots generated by the snapshot schedule in a different location.
In the Google Cloud console, go to the VM instances page.
Go to VM instances
school The remaining steps will appear automatically in the Google Cloud console.
boot-disk-snapshot-schedule
attached-persistent-disk-snapshot-schedule
In the Location section, choose your snapshot storage location. The predefined or customized default location defined in your snapshot settings is automatically selected. Optionally, you can override the snapshot settings and store your snapshots in a custom storage location by doing the following:
Choose the type of storage location that you want for your snapshot.
In the Select location field, select the specific region or multi-region that you want to use. To use the region or multi-region that is closest to your source disk, select Based on disk's location.
To schedule globally scoped snapshots for a disk, use the gcloud compute resource-policies create snapshot-schedule
command. Set your schedule frequency to hourly, daily, or weekly.
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 or --weekly-schedule-from-file FILE_NAME \
--on-source-disk-delete DELETION_OPTION \
--storage-location=STORAGE_LOCATION
(Preview) To schedule regionally scoped snapshots for a disk, use the gcloud compute resource-policies create snapshot-schedule
command and specify the snapshot region.
gcloud beta 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 or --weekly-schedule-from-file FILE_NAME \
--on-source-disk-delete DELETION_OPTION \
--storage-location=STORAGE_LOCATION \
--region REGION \
--snapshot-region SNAPSHOT_REGION
Replace the following:
SCHEDULE_NAME
: the name of the snapshot schedule.SCHEDULE_DESCRIPTION
: a description of the snapshot schedule. Use quotes around your description.REGION
: the location of the snapshot schedule resource policy.SNAPSHOT_REGION
: the region that the scheduled snapshot is scoped to.MAX_RETENTION_DAYS
: the number of days to retain the snapshot.
For example, a value of 3
means that the snapshots are retained for 3 days before being deleted. You must use a value of 1
or higher.
START_TIME
: the start time in the UTC time zone. The time must start on the hour.
For example:
22:00
.22:13
, you receive an error.If you use the --weekly-schedule-from-file
flag and specify a start time within the file, you don't need to include this flag.
SNAPSHOT_INTERVAL
: the interval between creating successive snapshots. 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.
--daily-schedule
flag without any value.--hourly-schedule
flag set to an integer value between 1 and 23. To generate snapshots at the same time every day, choose an hourly number that is evenly divided into 24. For example, setting --hourly-schedule
to 12
, means a snapshot is created every 12 hours.--weekly-schedule
flag set to the day of the week on which you want the snapshot to be created. You must spell out the week day; the values are not case-sensitive. For example, to back up your disk every Friday, your command would include --weekly-schedule=friday
.Set an advanced weekly schedule, specifying different days of the week and with different start times by including the --weekly-schedule-from-file
flag. Replace FILE_NAME
with the filename that contains the weekly snapshot schedule. While you can specify different days of the week and different start times using a file, you can't specify multiple weekly schedules directly on the command-line. For example, your file might specify two weekly schedules, on Monday and Wednesday, but you can't duplicate this setting on the command line:
[
{"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 on the command line. The schedule uses the UTC time zone.
DELETION_OPTION
: determines what happens to your snapshots if the source disk is deleted. If you want to keep all generated snapshots, you can omit this flag. Otherwise, specify apply-retention-policy
to use the settings in a retention policy.
STORAGE_LOCATION
: Optional: the storage location. If you omit this flag, the default storage location is used.
Examples
In all the following examples:
--on-source-disk-delete
flag is set to the default of keep-auto-snapshots
to permanently keep all auto-generated snapshots. The alternative is to set this flag to apply-retention-policy
to use your snapshot retention policy.US
, so all generated snapshots are stored in the US multi-region.env=dev
and media=images
are applied to all generated snapshots.Hourly schedule: In this example, the snapshot schedule starts at 22:00 UTC (14:00 PST) and occurs every 4 hours.
gcloud compute resource-policies create snapshot-schedule hourly-schedule1 \
--description "MY HOURLY SNAPSHOT SCHEDULE" \
--max-retention-days 10 \
--start-time 22:00 \
--hourly-schedule 4 \
--region us-west1 \
--on-source-disk-delete keep-auto-snapshots \
--snapshot-labels env=dev,media=images \
--storage-location US
Daily schedule: In this example, the snapshot schedule starts at 22:00 UTC (14:00 PST) and occurs every day at the same time. The --daily-schedule
flag must be present, but without an associated value.
gcloud compute resource-policies create snapshot-schedule daily-schedule2 \
--description "MY DAILY SNAPSHOT SCHEDULE" \
--max-retention-days 10 \
--start-time 22:00 \
--daily-schedule \
--region us-west1 \
--on-source-disk-delete keep-auto-snapshots \
--snapshot-labels env=dev,media=images \
--storage-location US
Weekly schedule: In this example, the snapshot schedule starts at 22:00 UTC (14:00 PST) and occurs every week on Tuesday.
gcloud compute resource-policies create snapshot-schedule weekly-schedule3 \
--description "MY WEEKLY SNAPSHOT SCHEDULE" \
--max-retention-days 10 \
--start-time 22:00 \
--weekly-schedule tuesday \
--region us-west1 \
--on-source-disk-delete keep-auto-snapshots \
--snapshot-labels env=dev,media=images \
--storage-location US
Go Java Node.js Python REST
To create a snapshot schedule for globally scoped snapshots, construct a POST
request to resourcePolicies.insert
. You must include the snapshot schedule name and snapshot frequency.
You can also manually specify a snapshot storage location and add resource labels in your request.
By default, the onSourceDiskDelete
parameter is set to keepAutoSnapshots
. This means that if the source disk is deleted, the auto-generated snapshot for that disk is retained indefinitely. Alternatively, you can set the flag to applyRetentionPolicy
to apply your retention policy.
The following example sets a daily snapshot schedule that starts at 12:00 UTC (04:00 PST) and repeats every day. The example also sets a retention policy of 5 days; after 5 days, snapshots are automatically removed.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/resourcePolicies
{
"name": "SCHEDULE_NAME",
"description": "SCHEDULE_DESCRIPTION",
"snapshotSchedulePolicy": {
"schedule": {
"dailySchedule": {
"startTime": "12:00",
"daysInCycle": "1"
}
},
"retentionPolicy": {
"maxRetentionDays": "5"
},
"snapshotProperties": {
"guestFlush": "False",
"labels": {
"env": "dev",
"media": "images"
},
"storageLocations": "STORAGE_LOCATION"
}
}
}
(Preview) To create a snapshot schedule for regionally scoped snapshots, construct a POST
request to resourcePolicies.insert
and specify the snapshot region.
POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/regions/REGION/resourcePolicies
{
"name": "SCHEDULE_NAME",
"description": "SCHEDULE_DESCRIPTION",
"snapshotSchedulePolicy": {
"schedule": {
"dailySchedule": {
"startTime": "12:00",
"daysInCycle": "1"
}
},
"retentionPolicy": {
"maxRetentionDays": "5"
},
"snapshotProperties": {
"guestFlush": "False",
"region": "SNAPSHOT_REGION"
}
}
}
Replace the following:
PROJECT_ID
: the project nameREGION
: the location of the snapshot schedule resource policySNAPSHOT_REGION
: the region that the scheduled snapshot is scoped toSCHEDULE_DESCRIPTION
: the description of the snapshot scheduleSCHEDULE_NAME
: the name of the snapshot scheduleSTORAGE_LOCATION
: Optional: the storage location. If you omit this flag, the default storage location is used.Similarly, you can create a weekly or monthly schedule. Review the resourcePolicies.insert
method for details specific to setting a weekly or monthly schedule.
For example, the following request creates a weekly schedule that runs on Tuesday at 9:00 UTC.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/resourcePolicies
{
"name": "SCHEDULE_NAME",
"description": "SCHEDULE_DESCRIPTION",
"snapshotSchedulePolicy": {
"schedule": {
"weeklySchedule": {
"dayOfWeeks": [
{
"day": "Tuesday",
"startTime": "9:00"
}
]
}
},
"retentionPolicy": {
"maxRetentionDays": "5"
},
"snapshotProperties": {
"guestFlush": "False",
"labels": {
"production": "webserver"
},
"storageLocations": "US"
}
}
}
Attach a snapshot schedule to a disk
After you create a schedule, attach it to an existing disk. Use the console, gcloud CLI, or the Compute Engine API.
ConsoleAttach a snapshot schedule to an existing disk.
In the Google Cloud console, go to the Disks page.
Select the name of the disk to which you want to attach a snapshot schedule. This opens the Manage disk page.
On the Manage disk page, click editEdit. You might need to click the more_vertMore actions menu first.
Use the Snapshot schedule drop-down menu to add the schedule to the disk. Or create a new schedule.
If you created a new schedule, click Create.
Click Save to complete the task.
To attach a snapshot schedule to a disk, use the gcloud disks add-resource-policies
command.
gcloud compute disks add-resource-policies DISK_NAME \
--resource-policies SCHEDULE_NAME \
--zone ZONE
Replace the following:
DISK_NAME
: the name of the existing diskSCHEDULE_NAME
: the name of the snapshot scheduleZONE
: the location of your diskConstruct a POST
request to disks.addResourcePolicies
to attach a snapshot schedule to an existing disk.
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 nameZONE
: the zone where the disk is locatedREGION
: the region where the snapshot schedule was createdDISK_NAME
: the name of the diskSCHEDULE_NAME
: the name of the snapshot schedule that you are applying to this diskYou can use the Google Cloud console or gcloud CLI to create a disk and a snapshot schedule at the same time.
ConsoleIn the Google Cloud console, go to the Disks page.
Click Create Disk.
Complete the required fields to create a zonal or regional disk.
Create your disk in the same region as your snapshot schedule.
Populate the fields for your Snapshot schedule.
Use the drop-down menu and complete the fields to create the schedule.
Click Create to create the schedule.
Click Create to create the disk.
Use the gcloud disks create
command to create a zonal or regional Persistent Disk or Hyperdisk and attach a snapshot schedule to it.
gcloud compute disks create DISK_NAME \
--resource-policies SCHEDULE_NAME \
--zone ZONE
Replace the following:
DISK_NAME
: the name of the new diskSCHEDULE_NAME
: the name of the snapshot scheduleZONE
: the location where you are creating the disk. The disk must be in a zone that is in the same region as the snapshot schedule.Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["Snapshot schedules allow you to automatically and regularly back up your zonal and regional Persistent Disk and Google Cloud Hyperdisk volumes."],["You can create snapshot schedules that capture application data at the time of backup, known as application-consistent, guest-flush, or VSS snapshots, for both Linux and Windows systems."],["To use the code samples in a local development environment, you need to install and initialize the gcloud CLI and set up Application Default Credentials."],["You can create a snapshot schedule and attach it to an existing disk or create a new disk with an attached snapshot schedule."],["When creating a snapshot schedule, it must reside in the same region as the disk, and when using gcloud CLI or Google Cloud Console you must set a retention policy."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4