This tutorial shows you how to use auto-protection policies and resource labels to automatically protect Compute Engine instances and disks at scale in Backup and DR.
Instead of manually selecting individual resources to protect, auto-protection policies evaluate user-defined resource labels to identify qualifying resources across projects and automatically assign a specified backup plan to them.
Objectives
- Configure required Identity and Access Management roles and permissions.
- Prepare your environment with resource labels.
- Create an auto-protection policy.
- View auto-protection policies and protected resources.
- View applied auto-protection policies in a workload project.
- Update resource projects associated with an auto-protection policy.
- Delete an auto-protection policy.
Costs
This tutorial uses the following billable components of Google Cloud:
- Backup and DR
- Compute Engine instances and disks
To generate a cost estimate based on your projected usage, use the pricing calculator.
Before you begin
Select or create a Google Cloud project for your backup vault resources and workload resources:
Backup vault project: The project that contains your backup vaults, backup plans, and auto-protection policies.
Workload project: The project that contains the Compute Engine instances or disks to protect.
Enable billing for your projects.
Enable the Backup and DR API and Compute Engine API in both your backup vault project and workload projects:
Create a backup vault in your backup vault project to store your backups.
Create a backup plan in your backup vault project for the resource type (Compute Engine instances or disks) and region that you want to protect.
Ensure that you have the required IAM roles and permissions.
Required roles and permissions
To get the permissions that you need to create, manage, and view auto-protection policies and policy bindings, ask your administrator to grant you the following IAM roles on the specified projects:
- Backup vault project:
- To create, edit, and delete auto-protection policies and policy bindings:
Backup and DR Admin (
roles/backupdr.admin) or Backup and DR Editor (roles/backupdr.editor) - To view auto-protection policies, policy bindings, and matching resources:
Backup and DR Viewer (
roles/backupdr.viewer)
- To create, edit, and delete auto-protection policies and policy bindings:
Backup and DR Admin (
- Workload projects:
- To authorize auto-protection policies to be applied to the project and manage bindings:
Backup and DR Admin (
roles/backupdr.admin) or Backup and DR Editor (roles/backupdr.editor) - To view applied auto-protection policies and matching resources:
Backup and DR Viewer (
roles/backupdr.viewer)
- To authorize auto-protection policies to be applied to the project and manage bindings:
Backup and DR Admin (
Service agent roles for cross-project protection
If your workload resources (Compute Engine instances or disks) reside in a different project from your backup vault project, you must grant the appropriate operator role to the backup vault service agent in each target workload project:
- For Compute Engine instances: Backup and DR Compute Engine Operator
(
roles/backupdr.computeEngineOperator) - For disks: Backup and DR Disk Operator
(
roles/backupdr.diskOperator)
These roles grant the backup vault service agent the necessary permissions to perform backup operations on workload resources in the workload project. For more information, see Grant a role to the service agent.
Note: In both same-project and cross-project configurations, the workload
project's Backup and DR service agent is automatically granted the
Backup and DR Service Agent (roles/backupdr.serviceAgent) role to manage
backup plan associations within the project.
Granular permissions for custom roles
If you prefer to use custom roles instead of predefined roles, ensure that your custom roles include the granular permissions listed in the following table:
| Action or operation | Granular permissions | Project where permission is required |
|---|---|---|
| Create auto-protection policy | backupdr.autoProtectionPolicies.createbackupdr.backupPlans.useForComputeInstance (for VM instances) orbackupdr.backupPlans.useForComputeDisk (for disks) |
Backup vault project |
| Update auto-protection policy | backupdr.autoProtectionPolicies.updatebackupdr.backupPlans.useForComputeInstance (for VM instances) orbackupdr.backupPlans.useForComputeDisk (disks) |
Backup vault project |
| Delete auto-protection policy | backupdr.autoProtectionPolicies.delete |
Backup vault project |
| View auto-protection policies | backupdr.autoProtectionPolicies.getbackupdr.autoProtectionPolicies.list |
Backup vault project |
| Create policy binding (Add project to policy) |
backupdr.autoProtectionPolicyBindings.createbackupdr.appliedAutoProtectionPolicies.authorize |
Backup vault project Workload project |
| Delete policy binding (Remove project from policy) |
backupdr.autoProtectionPolicyBindings.delete |
Backup vault project |
| View policy bindings | backupdr.autoProtectionPolicyBindings.getbackupdr.autoProtectionPolicyBindings.list |
Backup vault project |
| View matching resources | backupdr.bindingMatchingResources.listbackupdr.appliedAutoProtectionPolicies.viewMatchingResources |
Backup vault project Workload project |
| View applied policies | backupdr.appliedAutoProtectionPolicies.list |
Workload project |
Limitations
Keep the following preview limitations in mind:
Supported resources: Auto-protection policies support Compute Engine instances and disks only.
Scale recommendations: Do not use production resources. Protect up to 100 projects per policy.
Label key constraint: When you apply multiple auto-protection policies to a specific project, all policies applied to that project must share the same label key (for example,
env=prodandenv=test). You cannot use different label keys (such asenv=prodandtier=gold) for multiple policies applied to the same project. However, different projects can use policies with different label keys.Management interfaces: Auto-protection policies can be managed using the Google Cloud console and API. Support for gcloud CLI and Terraform will be added in future releases.
Single-region support: An auto-protection policy protects resources located in a single region. To protect resources across multiple regions, create separate policies for each region.
Prepare your environment
Before creating an auto-protection policy, apply resource labels (key-value pairs) to the Compute Engine resources you want to protect.
In the Google Cloud console, go to the VM instances page or Disks page.
Select the resource you want to label.
Add a label key and value (for example, key
envand valueprod).Click Save.
Create an auto-protection policy
To create an auto-protection policy that automatically assigns a backup plan to labeled resources:
In the Google Cloud console, go to the Backup and DR page.
In the navigation menu, select Auto-protection policies.
Click Create Auto-protection policy.
In the Name your auto-protection policy section enter the following details:
In the Auto-protection policy name field, enter a name for the policy.
In the Policy description field, enter an optional description.
Click Continue.
In the Choose the region where your resources are located and select a backup plan section, enter the following details:
From the Region drop-down list, select the region where your resources are located.
In the This policy is for section:
Select the resource type to protect, either Compute Engine or disks.
In the Backup plan field, click Select to choose the backup plan to apply to qualifying resources.
From the Select a backup plan pane, select the backup plan you want to associate with the auto-protection policy.
Click Select.
Click Continue.
In the Choose projects where your resources are section, select one or multiple projects in the same organization to protect.
In the Choose resources to protect section, enter key-value pairs associated with the resources you want to protect. For example,
env=prod.Click Create policy.
Once created, the policy automatically identifies matching resources and schedules backup plan associations. Initial configuration and protection scheduling typically takes up to 2 hours, but in some cases can take up to 8 hours.
View auto-protection policies
As a backup administrator, you can view auto-protection policies created in your backup vault project and monitor the workload projects and resources they protect.
To view auto-protection policies and their protected resources:
In the Google Cloud console, select your backup vault project.
Go to the Backup and DR page.
In the navigation menu, select Auto-protection policies.
On the Policies created in this project tab, select the Auto-protection policies view.
Click the policy you want to view.
The Auto-protection policy details page appears.
To view the workload projects associated with the policy and their matching, protected, and failed resource counts, select the Protected resources tab.
View applied auto-protection policies
As a workload administrator, you can view auto-protection policies applied to resources in your workload project. These policies are created and managed within their respective backup vault projects.
To view applied auto-protection policies in a workload project:
In the Google Cloud console, select your workload project.
Go to the Backup and DR page.
In the navigation menu, select Auto-protection policies.
Select the Policies applied on this project tab.
The Applied auto-protection policies table displays the policies applied to resources in the project, along with the following information:
- Policy name: The name of the auto-protection policy. Click the policy name to view policy details in the backup vault project.
- Resource type: The resource type protected by the policy (Compute Engine instances or disks).
- Criteria: The resource labels (key-value pairs) used to match resources in the project.
- Backup vault project: The backup vault project where the policy and backup vault are managed.
- Status: The status of the policy binding (for example,
Active). - Region: The region where the policy and protected resources reside.
- Backup plan: The backup plan assigned to matching resources. Click the backup plan name to view its details in the backup vault project.
- Matching resources: The number of resources in the workload project that match the label criteria.
- Protected resources: The number of matching resources successfully protected by the backup plan.
- Resources failed to protect: The number of matching resources that failed protection.
Edit an auto-protection policy
To edit auto-protection policies and their protected resources:
In the Google Cloud console, go to the Backup and DR page.
In the navigation menu, select Auto-protection policies.
The Auto-protection policies page appears.
Click the auto-protection policy you want to edit.
In the Auto-protection policy details page, click Edit policy.
Make the necessary changes to the auto-protection policy.
Click Save changes.
Update resource projects in an auto-protection policy
You can modify the scope of an existing auto-protection policy by adding or removing workload projects.
Add projects to a policy
In the Google Cloud console, go to the Backup and DR page.
In the navigation menu, select Auto-protection policies.
Click the policy you want to update.
Click Add projects.
The Add projects to policy page appears.
Click Select projects.
In the Search projects field, enter the name of the project you want to add to the policy.
Check the box next to the name of the project you want to add to the policy.
Click Select.
Click Add.
A confirmation message appears.
Remove projects from a policy
In the Google Cloud console, go to the Backup and DR page.
In the navigation menu, select Auto-protection policies.
Click the policy you want to update.
Select the Protected resources tab.
Select the projects you want to remove from the policy scope.
Click Remove projects.
To confirm that you want to remove the auto-protection policy from the project, enter
confirm.Click Remove.
A confirmation notification appears.
Unprotecting resources and removing projects typically takes up to 2 hours, but in some cases can take up to 8 hours.
Delete an auto-protection policy
Before deleting an auto-protection policy, you must remove all workload projects from the policy's scope. For instructions, see Remove projects from a policy.
To delete an auto-protection policy:
In the Google Cloud console, go to the Backup and DR page.
In the navigation menu, select Auto-protection policies.
Click the policy you want to delete.
Click Delete policy.
In the confirmation dialog, click Delete.
Clean up
To avoid incurring charges to your Google Cloud account for resources used in this tutorial:
Delete any auto-protection policies created during this tutorial.
Remove resource labels from test Compute Engine VMs and disks if you no longer want them protected.
If you created a dedicated Google Cloud project for this tutorial, delete the project:
In the Google Cloud console, go to the Manage resources page.
Select the project and click Delete.
Enter the project ID and click Shut down.
What's next
- Learn more about Backup plans in Google Cloud console.
- Learn how to Back up Compute Engine instances.
- Learn about Customer-managed encryption keys (CMEK) with Backup and DR.
- For questions or feedback regarding the preview, contact backupdr-autoprot-preview-feedback@google.com.
- Try out other Google Cloud features for yourself. Have a look at our tutorials.