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:
- Confirm that your platform administrator has created the
dbs-backup-repositoryBackupRepositorycustom resource. For more information, see Create a backup repository for Database Service. - Configure the kubectl CLI with the kubeconfig file for the management API server.
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-adminrole includescreate,get,list,patch,update, andwatchpermissions forBackupcustom resources. You don't need any additional roles or permissions. - Versions earlier than 1.16.2 hotfix 1: The
project-db-adminrole gives read-only access (get,list, andwatch) toBackupcustom resources. To create an on-demandBackupcustom resource, you also need role-based access control (RBAC) permissions to createbackupsresources in the Database Service API group (postgresql.dbadmin.gdc.goog,oracle.dbadmin.gdc.goog, oralloydbomni.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 |
Kind: |
Name: 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 You can create only one user-managed |
Controller-managed internal BackupPlan custom resource |
Kind: |
Name: Namespace: Database Service shadow namespace (outside your project namespace) |
Has the dbadmin.goog/visibility: internal label. |
On supported single-zone deployments, the Because this plan resides in the Database Service shadow namespace, it doesn't appear in project-scoped |
The preceding table includes the following placeholder values:
ENGINE: the database engine API group prefix (postgresql,oracle, oralloydbomni)DBCLUSTER_NAME: the name of yourDBClustercustom 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
AlreadyExistserror, if you use the nameDBCLUSTER_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
BackupPlancustom resource in Terraform or GitOps: Pass the--no-backupflag when you run thegdcloud database clusters createcommand, or create theDBClustercustom resource by using the Kubernetes API. Then, apply your single user-managedBackupPlanmanifest 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-backupBackupPlancustom resource already exists. Import that custom resource into your Terraform state by using theterraform importcommand, or edit it instead of creating a secondBackupPlancustom 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, oralloydbomni).DBCLUSTER_NAME: the name of the targetDBClustercustom resource. If you use a custom name instead ofDBCLUSTER_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 from1to90. If you omit this field in the manifest, the value defaults to14. When you enable backups during database cluster creation in the GDC console or with the gdcloud CLI, the value defaults to30.
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, oralloydbomni)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, oralloydbomni)DBCLUSTER_NAME: the name of the targetDBClustercustom resourcePROJECT_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, oralloydbomni).MANUAL_BACKUP_NAME: a unique name for theBackupcustom resource, such asmanual-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-backupcustom resource in your project namespace. Don't edit or delete the controller-managed internalDBCLUSTER_NAME-intlbpBackupPlancustom resource (dbadmin.goog/visibility: internallabel) 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: internalandENGINE.dbadmin.goog/dbcluster). Removing these finalizers or labels can prevent GDC from cleanly deleting underlying snapshots and storage repositories.