---
title: "Copying a database into a Cloud Platform CD environment"
date: "2024-02-14T06:18:38+00:00"
summary: "Learn how to copy databases into your Cloud Platform CD environment for testing. Follow our step-by-step guide to sync databases during deployment, ensuring efficient and accurate test environments for your applications."
image:
type: "page"
url: "/acquia-cloud-platform/copying-database-cloud-platform-cd-environment"
id: "1689909d-ce06-4e8c-926d-c1d9cf7360c7"
---

When running tests in your Cloud Platform CD environment, you may want to copy a database from another Cloud Platform environment into your Cloud Platform CD environment. 

To sync a database as part of a deployment:

1.  Ensure your YAML file uses a [version key of 1.2.0 or later](yaml.html#pipelines-version-key).
2.  Add a SSH key as described in [Creating and managing your build definition file](yaml.html#ssh-keys).
3.  Add a `cde-databases` key to your YAML file as described in [Creating and managing your build definition file](/acquia-cloud-platform/features/pipelines/yaml#cde-databases). Any databases you want to copy must be explicitly specified in the `cde-databases` key.
4.  [Select the source database](#pipelines-select-source-db).
5.  [Add deployment steps to your YAML file](#pipelines-add-deploy-steps).

Database operations in Pipelines

Database operations in the Pipelines container must be performed as part of the build steps.

For more information about the Cloud Platform CD user interface and example build definition files, see [Managing your Pipelines in the Cloud Platform interface](/acquia-cloud-platform/features/pipelines/ui) and [Example Pipelines build definition files](yaml/examples.html) respectively.

Selecting the source database
-----------------------------

To select a source database for database syncing:

1.  [Sign in to the Cloud Platform user interface](/node/55875) with an account that has the [Execute pipelines](/node/56065#permissions-list) permission.
2.  Select the application you want to use.
3.  In the left menu, click **Pipelines**.
4.  Click the **Settings** tab.
    
    ![pipelines_settings](https://acquia.widen.net/content/10676ed3-f742-4352-aa07-d7a3ee7cb651/web/d0b4b_pipelines_settings_0.png?w=720&itok=nMDJkIEJ)
    
5.  In the **DB Sync source environment**, section, select the environment to copy the database from, and your selection will be saved.
    
    ![pipelines_selecting-database.png](https://acquia.widen.net/content/915ee1f9-1be5-4587-80e4-a205df0f1fe5/web/pipelines_selecting-database.png?w=720&itok=OmSoCUCc)
    

Adding deployment steps to your YAML file
-----------------------------------------

After selecting a source database for syncing and adding a `cde-databases` key to your YAML file, add a `post-deploy` step to your [events key](yaml.html#events-key) as displayed in the following example, replacing `db1` and `db2` with databases listed as parameters in the `cde-databases` key:

    version: 1.2.0
    
    cde-databases:
      - db1
      - db2
    
    events:
    
      post-deploy:
        steps:
          # Deploy the build artifact to an on-demand environment,
          # and sync the specified databases.
          - deploy:
              script:
                - pipelines-deploy
                - pipelines-sync-dbs db1 db2

In the previous example, the `pipelines-deploy` command creates the environment and deploys the build result. The `pipelines-sync-dbs` command syncs the databases provided as parameters, provided they are also listed as parameters in the `cde-databases` key.

Important

Before performing testing, you should scrub the copy of the database in your Cloud Platform CD environment of any sensitive or personal identifying user information to prevent unintended user notifications or data leaks.