Before exporting data, you must:
Grant the Database Service export service account write access to the destination object storage bucket. This role binding must be created within the same namespace as the subject database cluster. See Grant and obtain storage access.
To find the namespace that contains the controller-maintained service account, use the following commands:
kubectl get dbclusters.postgresql <var>DATABASE_CLUSTER_NAME</var> -n <var>PROJECT_NAMESPACE</var> -o jsonpath='{.status.serviceAccounts.export}'
kubectl get dbclusters.postgresql <var>DATABASE_CLUSTER_NAME</var> -n <var>PROJECT_NAMESPACE</var> -o jsonpath='{.status.serviceAccounts.import}'
Once you have the namespace, the service account you're looking for is named
postgresql-export-DATABASE_CLUSTER_NAME.
Replace DATABASE_CLUSTER_NAME with the name of the
database cluster where you are exporting data.
You can export a database cluster to a data dump file using either the GDC console or the Distributed Cloud CLI:
Console
- From the main menu, choose Database Service.
- Select the database cluster you want to export. This takes you to the Database cluster overview page for that cluster.
- Click EXPORT. The Export data panel opens.
- In the Export data panel, specify the storage location to export to.
- Click EXPORT. On screen messages indicate the status of the export process.
gdcloud CLI
- Before using Distributed Cloud CLI, install and initialize it. Then, authenticate with your organization.
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_NAMEReplace 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.