Export a database cluster

Database Service in Google Distributed Cloud (GDC) air-gapped lets you export a database cluster to a data dump file in an object storage bucket. Saving a copy of your database data helps you preserve records for disaster recovery, long-term archival, upgrades, or workload migration. You can run the operation by using the GDC console, the gdcloud CLI, or the API.

Before you begin

Grant the Database Service export service account write access to the destination object storage bucket. Create this role binding in the same namespace as the database cluster. For more information, see Grant and obtain storage access.

Database Service automatically creates this service account when you create the database cluster. To retrieve the name and namespace of the export service account, run the following command:

kubectl get dbclusters.postgresql DATABASE_CLUSTER_NAME \
    -n PROJECT_NAMESPACE \
    -o jsonpath='{.status.serviceAccounts.export}'

Replace the following:

  • DATABASE_CLUSTER_NAME: the name of the database cluster that you want to export.
  • PROJECT_NAMESPACE: the name of the project namespace that contains the database cluster.

The command returns the service account's name (postgresql-export-DATABASE_CLUSTER_NAME) and namespace.

Export a database cluster

To export a database cluster to a data dump file, use the GDC console, the gdcloud CLI, or the API:

Console

  1. From the main menu, choose Database Service.
  2. Select the database cluster you want to export. This takes you to the Database cluster overview page for that cluster.
  3. Click EXPORT. The Export data panel opens.
  4. In the Export data panel, specify the storage location to export to.
  5. Click EXPORT. On screen messages indicate the status of the export process.

gdcloud

  1. Before using the gdcloud CLI, install and initialize it. Then, authenticate with your organization.
  2. Run the following command to export a database file to a dump file:

    gdcloud database export sql DATABASE_CLUSTER \
         BUCKET_NAME/SAMPLE.dmp --project=PROJECT_NAME
    

    Replace the following:

    • DATABASE_CLUSTER with the name of the database cluster to export.
    • BUCKET_NAME/SAMPLE.dmp with the destination for the exported dump file.
    • PROJECT_NAME with the name of the project that the database cluster is in.

API

apiVersion: postgresql.dbadmin.gdc.goog/v1
kind: Export
metadata:
  name: EXPORT_NAME
  namespace: USER_PROJECT
spec:
  dbclusterRef: DBCLUSTER_NAME
  exportLocation:
    s3Options:
      bucket: BUCKET_NAME
      key: dbs-export
    type: S3

Replace the following variables:

  • EXPORT_NAME: the name of the export operation.
  • USER_PROJECT: the name of the user project where the database cluster to be exported is created.
  • DBCLUSTER_NAME: the name of the database cluster.
  • BUCKET_NAME: the name of the object storage bucket to store the exported files.