You can clone a database cluster to create a new database cluster that contains
the same data as the original cluster. Cloning is a good way to make database
clusters for testing purposes.

## Before you begin

Make sure the source database cluster to clone from has the backup service enabled.

After the recovery window is available for the source database cluster, you can
specify a point in time within the recovery window to base the clone on. You aren't
limited to cloning the present state of a database cluster. The database service
clones a new database cluster at the exact point in time you specify.

## Clone database cluster

You can clone a database cluster by using the GDC console,
the gdcloud CLI, or the API:

### Console

1. From the main menu of the GDC console, choose **Database Service**.
2. Select the database cluster to clone.
3. Click add_box **CLONE**.
4. In the *Create a clone* dialog, specify the point in time to clone from and specify an ID for the new database cluster.
5. Click **CLONE**. This takes you to the Database cluster overview page for the new cluster where you can monitor its status.

### gdcloud

Use the following command to clone a database cluster:

```bash
gdcloud database clusters clone SOURCE \
   DESTINATION --point-in-time POINT_IN_TIME
```

Replace the following:

- `<var>SOURCE</var>`: the name of the database cluster to create a clone from.
- `<var>DESTINATION</var>`: the name of the new database cluster to create.
- `<var>POINT_IN_TIME</var>`: the timestamp of the point in time to use as the basis of the clone. Use the [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) timestamp format (`yyyy-MM-dd'T'HH:mm:ss'Z'`). The timestamp must be within the recovery window of the source database cluster; otherwise, the clone request is rejected.

### API

To clone a database cluster, create a Restore resource:

```yaml
apiVersion: postgresql.dbadmin.gdc.goog/v1
kind: Restore
metadata:
  name: NEW_DBCLUSTER_NAME_restore
  namespace: NAMESPACE
spec:
  sourceDBCluster: DBCLUSTER_NAME
  pointInTime: "POINT_IN_TIME"
  clonedDBClusterConfig:
    dbclusterName: NEW_DBCLUSTER_NAME
```

Replace the following:

- `NEW_DBCLUSTER_NAME`: the name of the new database cluster to create.
- `NAMESPACE`: the namespace to create the new database cluster in.
- `POINT_IN_TIME`: the timestamp of the point in time to use as the basis of the clone. Use the [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) timestamp format (`yyyy-MM-dd'T'HH:mm:ss'Z'`). Set a timestamp within the recovery window of the source database cluster; otherwise, the system rejects the clone request. Run `kubectl get backupplan.o -n NAMESPACE` to determine the recovery window.

> [!NOTE]
> **Note:** The Restore resource must be created in the same namespace as the source database cluster.