Enable backup for Database Service

Database Service in Google Distributed Cloud (GDC) air-gapped lets you automate daily backups and run on-demand backups for your database clusters to help protect against data loss and support point-in-time recovery. You can configure retention periods and manage scheduled backups by using a user-managed BackupPlan custom resource. For more information, see Back up and restore overview.

This document is for developers in the platform administrator or application operator group who manage database backup operations. For more information, see Audiences for GDC air-gapped documentation.

Before you begin

Complete the following prerequisites before you manage database backup plans:

Required roles

To get the permissions that you need to manage database backup plans and backups, ask your IAM Project Admin to grant you the Database Project Admin (project-db-admin) role.

Permissions for Backup custom resources depend on your GDC version:

  • Version 1.16.2 hotfix 1 and later: The project-db-admin role includes create, get, list, patch, update, and watch permissions for Backup custom resources. You don't need any additional roles or permissions.
  • Versions earlier than 1.16.2 hotfix 1: The project-db-admin role gives read-only access (get, list, and watch) to Backup custom resources. To create an on-demand Backup custom resource, you also need role-based access control (RBAC) permissions to create backups resources in the Database Service API group (postgresql.dbadmin.gdc.goog, oracle.dbadmin.gdc.goog, or alloydbomni.dbadmin.gdc.goog).

User-managed and controller-managed backup plans

When you create a DBCluster custom resource for PostgreSQL, Oracle, or AlloyDB Omni, Database Service uses two categories of BackupPlan custom resources (ENGINE.dbadmin.gdc.goog/v1). These categories are a user-managed backup plan in your project namespace and an internal controller-managed backup plan in the Database Service shadow namespace.

Knowing how these custom resources differ helps you avoid AlreadyExists and duplicate BackupPlan admission errors in Terraform or GitOps and helps prevent manual edits that conflict with controller updates.

The following table compares user-managed and controller-managed BackupPlan custom resources:

Resource role API group and kind Name and namespace How to identify Purpose and management
User-managed BackupPlan custom resource

ENGINE.dbadmin.gdc.goog/v1

Kind: BackupPlan

Name: DBCLUSTER_NAME-backup, or a custom name up to 47 characters if you create it manually

Namespace: your project namespace

Has the ENGINE.dbadmin.goog/dbcluster: DBCLUSTER_NAME label without the dbadmin.goog/visibility: internal label.

By default, GDC creates this custom resource when you create a database cluster in the GDC console or with the gdcloud database clusters create command. To skip creating it with the gdcloud CLI, pass the --no-backup flag. Use this custom resource to pause or resume daily backups (paused: true or false) and set backup retention (backupRetainDays from 1 to 90). The backupRetainDays field defaults to 30 when the GDC console or the gdcloud CLI creates the plan, or 14 if you omit it from a manifest.

You can create only one user-managed BackupPlan custom resource for each DBCluster custom resource.

Controller-managed internal BackupPlan custom resource

ENGINE.dbadmin.gdc.goog/v1

Kind: BackupPlan

Name: DBCLUSTER_NAME-intlbp

Namespace: Database Service shadow namespace (outside your project namespace)

Has the dbadmin.goog/visibility: internal label.

On supported single-zone deployments, the DBCluster controller creates this internal plan even when you pass the --no-backup flag. The -intlbp plan (backupRetainDays: 7, paused: true) supports upgrade and rollback operations. The controller skips this internal plan on multi-zone deployments.

Because this plan resides in the Database Service shadow namespace, it doesn't appear in project-scoped kubectl get output. It also doesn't conflict with user-managed plans in your project namespace. Don't edit or delete this custom resource.

The preceding table includes the following placeholder values:

  • ENGINE: the database engine API group prefix (postgresql, oracle, or alloydbomni)
  • DBCLUSTER_NAME: the name of your DBCluster custom resource

Avoid AlreadyExists errors during database creation

By default, creating a database cluster in the GDC console or with the gdcloud database clusters create command automatically creates the user-managed DBCLUSTER_NAME-backup BackupPlan custom resource in your project namespace. If you then try to create another BackupPlan custom resource for the same DBCluster custom resource by using Terraform, GitOps, or the kubectl CLI, the request fails with one of these errors:

  • An AlreadyExists error, if you use the name DBCLUSTER_NAME-backup.
  • An admission webhook rejection (Spec.DBClusterRef: Invalid value: "DBCLUSTER_NAME": a backupplan already exists for this dbclsuter), if you use a different name for the same database cluster.

To avoid conflicts in Terraform and automation workflows, choose one of these approaches:

  • Create the BackupPlan custom resource in Terraform or GitOps: Pass the --no-backup flag when you run the gdcloud database clusters create command, or create the DBCluster custom resource by using the Kubernetes API. Then, apply your single user-managed BackupPlan manifest by using Terraform, GitOps, or the kubectl CLI.
  • Use the default backup plan: If you created the database cluster with default backups enabled, the DBCLUSTER_NAME-backup BackupPlan custom resource already exists. Import that custom resource into your Terraform state by using the terraform import command, or edit it instead of creating a second BackupPlan custom resource.

Create a user-managed BackupPlan custom resource

If you created your DBCluster custom resource by using the Kubernetes API or passed the --no-backup flag to the gdcloud database clusters create command, no user-managed BackupPlan custom resource exists. On supported single-zone deployments, only the controller-managed DBCLUSTER_NAME-intlbp BackupPlan custom resource exists in the Database Service shadow namespace.

To enable daily automated backups, save the following manifest and apply it to your project namespace by using the kubectl apply command:

apiVersion: ENGINE.dbadmin.gdc.goog/v1
kind: BackupPlan
metadata:
  name: DBCLUSTER_NAME-backup
  namespace: PROJECT_NAME
spec:
  dbclusterRef: DBCLUSTER_NAME
  backupRetainDays: RETENTION_DAYS
  paused: false

Replace the following:

  • ENGINE: the database engine API group prefix (postgresql, oracle, or alloydbomni).
  • DBCLUSTER_NAME: the name of the target DBCluster custom resource. If you use a custom name instead of DBCLUSTER_NAME-backup, keep the name at 47 characters or fewer.
  • PROJECT_NAME: the name of your project namespace.
  • RETENTION_DAYS: the number of days to keep automated backups before deletion. Specify an integer from 1 to 90. If you omit this field in the manifest, the value defaults to 14. When you enable backups during database cluster creation in the GDC console or with the gdcloud CLI, the value defaults to 30.

After you create the user-managed BackupPlan custom resource, Database Service runs automatic backups once each day. You can check the available recovery window in the status.recoveryWindow field of the BackupPlan custom resource.

View database backup plans

Specify the Database Service API group explicitly so that the command doesn't match backup.gdc.goog backup plans. List the user-managed BackupPlan custom resources in your project namespace by using the kubectl CLI:

kubectl get backupplans.ENGINE.dbadmin.gdc.goog \
    --namespace PROJECT_NAME \
    --label-columns ENGINE.dbadmin.goog/dbcluster

Replace the following:

  • ENGINE: the database engine API group prefix (postgresql, oracle, or alloydbomni)
  • PROJECT_NAME: the name of your project namespace

The internal controller-managed DBCLUSTER_NAME-intlbp BackupPlan custom resource resides in the Database Service shadow namespace outside your project namespace and doesn't appear in project-scoped kubectl get output.

Pause or resume scheduled backups

To pause scheduled backups during maintenance without losing existing backups or point-in-time recovery (PITR) logs, pause your user-managed BackupPlan custom resource instead of deleting it.

To pause scheduled backups, set the spec.paused field to true on your user-managed BackupPlan custom resource by using the kubectl CLI:

kubectl patch backupplans.ENGINE.dbadmin.gdc.goog \
    DBCLUSTER_NAME-backup \
    --namespace PROJECT_NAME \
    --type=merge \
    --patch '{"spec":{"paused":true}}'

Replace the following:

  • ENGINE: the database engine API group prefix (postgresql, oracle, or alloydbomni)
  • DBCLUSTER_NAME: the name of the target DBCluster custom resource
  • PROJECT_NAME: the name of your project namespace

To resume scheduled backups, set the spec.paused field to false.

Run an on-demand backup

To run an on-demand backup, don't edit the backup schedule. Instead, save the following Backup manifest with the spec.manual field set to true and apply it by using the kubectl apply command:

apiVersion: ENGINE.dbadmin.gdc.goog/v1
kind: Backup
metadata:
  name: MANUAL_BACKUP_NAME
  namespace: PROJECT_NAME
spec:
  dbclusterRef: DBCLUSTER_NAME
  backupPlanRef: DBCLUSTER_NAME-backup
  manual: true

Replace the following:

  • ENGINE: the database engine API group prefix (postgresql, oracle, or alloydbomni).
  • MANUAL_BACKUP_NAME: a unique name for the Backup custom resource, such as manual-db-backup-01.
  • PROJECT_NAME: the name of your project namespace.
  • DBCLUSTER_NAME: the name of the database cluster to back up.

Best practices for managing database backup plans

Follow these guidelines so that your changes don't conflict with the Database Service controller:

  • Edit only user-managed resources: Update only your user-managed DBCLUSTER_NAME-backup custom resource in your project namespace. Don't edit or delete the controller-managed internal DBCLUSTER_NAME-intlbp BackupPlan custom resource (dbadmin.goog/visibility: internal label) in the Database Service shadow namespace.
  • Keep controller finalizers and labels: Don't remove controller finalizers (backupplans.dbadmin.goog/finalizer) or controller-managed labels (dbadmin.goog/visibility: internal and ENGINE.dbadmin.goog/dbcluster). Removing these finalizers or labels can prevent GDC from cleanly deleting underlying snapshots and storage repositories.

What's next