You can call the CopyDatabaseBetweenInstances operation to copy databases from one instance to another.

You can also call the CopyDatabaseBetweenInstances operation to restore specific databases to an existing instance by point in time or backup file. For more information, see Restore the data of an ApsaraDB RDS for SQL Server instance.

Before you call this operation, make sure that the following requirements are met:

  • The source and destination instances belong to the same account.
  • The source and destination instances run the same version of database engine.
  • The source and destination instances are in the same region and can belong to different zones. The network types must be the same.
  • The source and destination instances do not have databases whose names are the same.
  • The available storage space of the destination instance is larger than the size of the databases to be copied.
    Note The CopyDatabaseBetweenInstances operation is applicable only to ApsaraDB RDS for SQL Server instances that run SQL Server 2012 or SQL Server 2016. You can restore specific databases or tables of an ApsaraDB RDS for MySQL instance to the original instance or a new instance. For more information, see Restore individual databases and tables of an ApsaraDB RDS for MySQL instance.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes CopyDatabaseBetweenInstances

The operation that you want to perform. Set the value to CopyDatabaseBetweenInstances.

DBInstanceId String Yes rm-uf6wjk5xxxxxxx

The ID of the source instance.

DbNames String Yes {"test1":"test2"}

The names of the databases to be copied. Format: {"Source instance database name":"Destination instance database name"}.

TargetDBInstanceId String Yes rm-ut5ajk3xxxxxxx

The ID of the destination instance, which must differ from the ID of the source instance.

BackupId String No 1065238746521

The ID of the backup file based on which you want to copy databases. When you copy databases based on the backup file, you can call the DescribeBackups operation to obtain the backup file ID.

Note You must specify one of the BackupId or RestoreTime parameter.
RestoreTime String No 2011-06-11T16:00:00Z

The point in time when the system copies databases. You can select a point in time within the backup retention period. Specify the time in the ISO 8601 standard in the yyyy-MM-ddTHH:mm:ssZ format. The time must be in UTC.

Note You must specify one of the BackupId or RestoreTime parameter.
SyncUserPrivilege String No NO

Specifies whether to copy users and permissions.

  • YES: copies users and permissions. If the destination instance has a user whose name is the same as a user in the source instance, the permissions of the user in the source instance will also be granted to the user in the destination instance after you copy user permissions.
  • NO: does not copy users and permissions.

Default value: NO.

Response parameters

Parameter Type Example Description
DBInstanceId String rm-uf6wjk5xxxxxxxxxx

The ID of the instance.

RequestId String 803D11AF-C370-465B-AB46-CB3A642DC303

The ID of the request.

Examples

Sample requests

http(s)://rds.aliyuncs.com/?Action=CopyDatabaseBetweenInstances
&DBInstanceId=rm-uf6wjk5xxxxxxx
&TargetDBInstanceId=rm-ut5ajk3xxxxxxx
&DbNames={"test1":"test2"}
&<Common request parameters>

Sample success responses

XML format

<CopyDatabaseBetweenInstancesResponse>
	  <RequestId>803D11AF-C370-465B-AB46-CB3A642DC303</RequestId>
</CopyDatabaseBetweenInstancesResponse>

JSON format

{
    "RequestId": "803D11AF-C370-465B-AB46-CB3A642DC303"
}

Error codes

HTTP status code Error code Error message Description
403 StorageLimitExceeded Exceeding the allowed Storage of DB instance. The error message returned because the disk space of the instance is less than the size of the databases to be copied.

For a list of error codes, visit the API Error Center.