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. |
| 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.
Go to Cloud SQL Instances
- Find the row of the instance to clone. At the right end of the
row, click the More Actions
more_vert 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
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:
curl (Linux, macOS, or Cloud Shell)
Save the request body in a file called request.json,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer "$(gcloud auth print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1/projects/project-id/instances/source-instance-id/clone"
PowerShell (Windows)
Save the request body in a file called request.json,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/project-id/instances/source-instance-id/clone" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/target-instance-id",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "CLONE",
"name": "operation-id",
"targetId": "target-instance-id",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/operations/operation-id",
"targetProject": "project-id"
}
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:
curl (Linux, macOS, or Cloud Shell)
Save the request body in a file called request.json,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer "$(gcloud auth print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/source-instance-id/clone"
PowerShell (Windows)
Save the request body in a file called request.json,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/source-instance-id/clone" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/target-instance-id",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "CLONE",
"name": "operation-id",
"targetId": "target-instance-id",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",
"targetProject": "project-id"
}
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:
curl (Linux, macOS, or Cloud Shell)
Save the request body in a file called request.json,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer "$(gcloud auth print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1/projects/project-id/instances/source-instance-id/clone"
PowerShell (Windows)
Save the request body in a file called request.json,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/project-id/instances/source-instance-id/clone" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/target-instance-id",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "CLONE",
"name": "operation-id",
"targetId": "target-instance-id",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/operations/operation-id",
"targetProject": "project-id"
}
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:
curl (Linux, macOS, or Cloud Shell)
Save the request body in a file called request.json,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer "$(gcloud auth print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/source-instance-id/clone"
PowerShell (Windows)
Save the request body in a file called request.json,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/source-instance-id/clone" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Response
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/target-instance-id",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "CLONE",
"name": "operation-id",
"targetId": "target-instance-id",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",
"targetProject": "project-id"
}
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.