This page explains cloning, and describes how to clone an instance.
Overview
Cloning a Cloud SQL instance creates a new instance that is a copy of the source instance. The new instance is completely independent from the source instance.
Frequently asked questions
Question | Answer |
---|---|
Does cloning impact performance? | No. Cloning has no performance impact on the source instance. |
Are backups copied to the new instance? | No. The new instance creates new automated backups. Manual backups are not copied over from the source instance. |
Does the new instance have the same IP address or addresses? | No. The new instance has a new IP address or addresses. |
Does the new instance have the same configuration settings? | Yes. The new instance will have the same settings such as database flags, connectivity options, machine type, and storage and memory settings. |
Are replicas copied to the new instance? | No. You need to create new replicas for the new instance. |
Can you clone a replica? | No. You can't clone a replica. |
Can you make a clone from an earlier point in time? | Yes. Point-in-time recovery uses cloning to restore an instance from an earlier point in time. This helps you recover your database from a destructive event. |
Can you clone a database to another project? | No. You can't clone a database to another project. |
Can you clone an instance that was once a clone? | Yes. You can clone and instance that was cloned from another instance. |
Are database users copied to the new instance? | Yes, but database user passwords are not copied, and need to be re-created. |
Cloning an instance
Console
-
In the Google Cloud console, go to the Cloud SQL Instances page.
- Find the row of the instance to clone. At the right end of the row, click the More Actions menu.
- Click Create clone.
- On the Create a clone page, update the instance ID if needed, and
click Create clone.
You are returned to the instance listing page while the clone initializes.
gcloud
Clone the instance:
gcloud sql instances clone SOURCE_INSTANCE_NAME TARGET_INSTANCE_NAME
Terraform
To clone the instance, use a Terraform resource
Apply the changes
To apply your Terraform configuration in a Google Cloud project, complete the following steps:
- Launch Cloud Shell.
-
Set the Google Cloud project where you want to apply the Terraform configuration:
export GOOGLE_CLOUD_PROJECT=PROJECT_ID
-
Create a directory and open a new file in that directory. The filename must have the
.tf
extension, for examplemain.tf
:mkdir DIRECTORY && cd DIRECTORY && nano main.tf
- Copy the sample into
main.tf
. - Review and modify the sample parameters to apply to your environment.
- Save your changes by pressing
Ctrl-x
and theny
. -
Initialize Terraform:
terraform init
-
Review the configuration and verify that the resources that Terraform is going to create or
update match your expectations:
terraform plan
Make corrections to the configuration as necessary.
-
Apply the Terraform configuration by running the following command and entering
yes
at the prompt:terraform apply
Wait until Terraform displays the "Apply complete!" message.
- Open your Google Cloud project to view the results. In the Google Cloud console, navigate to your resources in the UI to make sure that Terraform has created or updated them.
Delete the changes
To delete your changes, do the following:
- To disable deletion protection, in your Terraform configuration file set the
deletion_protection
argument tofalse
.deletion_protection = "false"
- Apply the updated Terraform configuration by running the following command and
entering
yes
at the prompt:terraform apply
-
Remove resources previously applied with your Terraform configuration by running the following command and entering
yes
at the prompt:terraform destroy
REST v1
Clone the instance.
Before using any of the request data, make the following replacements:
- project-id: The project ID
- source-instance-id: The source instance ID
- target-instance-id: The target instance ID
HTTP method and URL:
POST https://sqladmin.googleapis.com/v1/projects/project-id/instances/source-instance-id/clone
Request JSON body:
{ "cloneContext": { "destinationInstanceName": "target-instance-id" } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
REST v1beta4
Clone the instance.
Before using any of the request data, make the following replacements:
- project-id: The project ID
- source-instance-id: The source instance ID
- target-instance-id: The target instance ID
HTTP method and URL:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/source-instance-id/clone
Request JSON body:
{ "cloneContext": { "destinationInstanceName": "target-instance-id" } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
Cloning an instance with a private IP
If your Cloud SQL instance uses a private IP, you can optionally specify
an
allocated IP range
for the clone's new IP address. For example, google-managed-services-default
.
gcloud
Clone the instance, optionally specifying the allocated IP range you want to use:
gcloud sql instances clone SOURCE_INSTANCE_NAME TARGET_INSTANCE_NAME \ --allocated-ip-range-name ALLOCATED_IP_RANGE_NAME
REST v1
Clone the instance, optionally specifying the allocated IP range you want to use:
Before using any of the request data, make the following replacements:
- project-id: The project ID
- source-instance-id: The source instance ID
- target-instance-id: The target instance ID
- allocated-ip-range-name: The name of an allocated IP range
HTTP method and URL:
POST https://sqladmin.googleapis.com/v1/projects/project-id/instances/source-instance-id/clone
Request JSON body:
{ "cloneContext": { "destinationInstanceName": "target-instance-id", "allocatedIpRange": "allocated-ip-range-name" } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
REST v1beta4
Clone the instance, optionally specifying the allocated IP range you want to use:
Before using any of the request data, make the following replacements:
- project-id: The project ID
- source-instance-id: The source instance ID
- target-instance-id: The target instance ID
- allocated-ip-range-name: The name of an allocated IP range
HTTP method and URL:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/source-instance-id/clone
Request JSON body:
{ "cloneContext": { "destinationInstanceName": "target-instance-id", "allocatedIpRange": "allocated-ip-range-name" } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
If you don't specify an allocated IP range, the following behavior is applied:
- If the source instance was created with a specified range, the cloned instance is created in the same range.
- If the source instance was not created with a specified range, the cloned instance is created in a random range.
Troubleshoot
Issue | Troubleshooting |
---|---|
Cloning fails with constraints/sql.restrictAuthorizedNetworks error. |
The cloning operation is blocked by the Authorized Networks configuration.
Authorized Networks are configured for public IP addresses in the Connectivity section
of the Google Cloud console, and cloning is not permitted due to
security considerations.
Remove all |
Error message: Failed to create subnetwork. Couldn't find free
blocks in allocated IP ranges. Please allocate new ranges for this service
provider. Help Token: [help-token-id]. |
You're trying to use the Google Cloud console to clone an instance with a private IP address, but you didn't specify the allocated IP range that you want to use and the source instance isn't created with the specified range. As a result, the cloned instance is created in a random range. Use |