ApsaraDB RDS for SQL Server offers an instance-level cloud migration of the entire dataset from one or more databases on a self-managed SQL Server. To migrate, back up all databases from your self-managed SQL Server, upload the backup files to a single folder in an OSS bucket, and run the cloud migration script.
To migrate a single database, see Migrate data from a full backup and Migrate data from an incremental backup.
Prerequisites
The source must be a self-managed SQL Server database.
The destination ApsaraDB RDS for SQL Server instance must meet the following requirements:
The available storage space on the instance must be greater than the size of the data files to be migrated. If the available storage space is insufficient, upgrade the instance specifications.
For SQL Server 2008 R2, you must create a database on the destination instance with the same name as the source database. This requirement does not apply to other versions.
-
If you log on as a RAM user, you must meet the following requirements:
-
The RAM user must have the AliyunOSSFullAccess and AliyunRDSFullAccess permissions. For more information, see Control access to OSS by using RAM and Control access to RDS by using RAM.
-
Ensure that your Alibaba Cloud account has granted the official RDS service account access to your OSS resources.
-
You must manually create an access policy in your Alibaba Cloud account and then attach it to the RAM user.
-
Limitations
This solution supports only full migration; incremental migration is not currently supported.
Billing
If you use the method described in this topic to migrate data, you are charged only for the use of OSS buckets.
|
Scenario |
Billing rule |
|
Upload backup files to an OSS bucket |
Free of charge. |
|
Store backup files in an OSS bucket |
You are charged storage fees. For more information, visit the Pricing page of OSS. |
|
Migrate backup files from an OSS bucket to your RDS instance |
|
Prerequisites
1. Install Python 3
Go to the official Python website to download and install the appropriate package for your operating system. Select version 3.12 or later.
Windows: During the installation, select the
Add python.exe to PATHcheckbox to avoid manually configuring the environment variable.macOS/Linux: You can install using the official installer or a package manager such as Homebrew, apt, or dnf. Refer to the official website for guidance.
2. Verify Python installation and version
The executable name may differ based on your operating system and installation method (for example, python, python3, or py). Try the commands in order and check the output to confirm the installation.
3. Install SDK dependencies
pip install alibabacloud_rds20140815
pip install alibabacloud-oss-v2
pip install alibabacloud_tea_openapi
pip install alibabacloud_tea_util1. Back up self-managed SQL Server databases
To ensure data consistency, do not write new data during the full backup. Schedule this operation in advance to avoid disrupting your services.
If you do not use the backup script, you must name backup files in the
database_name_backup_type_backup_time.bakformat, for example,Testdb_FULL_20180518153544.bak. Otherwise, the backup will fail.
Download the backup script.
Double-click the backup script to open it in Microsoft SQL Server Management Studio (SSMS). For instructions on how to connect using SSMS, see the official documentation.
Modify the following parameters as needed.
Parameter
Description
@backup_databases_list
The databases to back up. Use a semicolon (;) or a comma (,) to separate multiple database names.
@backup_type
The backup type. Valid values:
FULL: full backup.
DIFF: differential backup.
LOG: log backup.
ImportantFor this procedure, you must set this parameter to FULL.
@backup_folder
The local directory to store backup files. This directory is automatically created if it does not exist.
@is_run
Specifies whether to run the backup. Valid values:
1: Runs the backup.
0: Performs a check only.
Run the backup script to back up the databases to the specified directory.

2. Upload backup files to OSS
-
To upload the backup file to OSS, you must first create a bucket.
-
If you use an existing OSS bucket, ensure it meets the following requirements:
-
The storage class of the bucket is Standard. Other storage classes, such as Infrequent Access, Archive, Cold Archive, and Deep Cold Archive, are not supported.
-
server-side encryption is disabled for the bucket.
-
-
If no bucket exists in OSS, you must create one. (Make sure that you have activated OSS.)
-
Log on to the OSS console, click Buckets, and then click Create bucket.
-
Configure the following key parameters. You can retain the default values for other parameters.
Important-
This bucket is created only for this migration, so you only need to configure the key parameters. You can delete the bucket after the migration is complete to prevent data breaches and reduce costs.
-
When you create the bucket, do not enable server-side encryption.
Parameter
Description
Example
Bucket Name
The name of the bucket. The name must be globally unique and cannot be changed after the bucket is created.
Naming conventions:
-
The name can contain only lowercase letters, digits, and hyphens (-).
-
The name must start and end with a lowercase letter or a digit.
-
The name must be 3 to 63 characters in length.
migratetest
Region
The region where the bucket is located. For internal network transfers, the bucket, ECS instance, and ApsaraDB RDS instance must all be in the same region.
China (Hangzhou)
Storage Type
Select Standard. This migration supports only the Standard storage class.
Standard
-
-
-
-
Upload the backup file to OSS.
After you back up your on-premises database, upload the backup file to an OSS bucket that is in the same region as your ApsaraDB RDS instance. If the bucket and the instance are in the same region, they can communicate over the internal network. This allows for faster uploads and avoids outbound internet traffic fees. You can use one of the following methods:
3. Run the migration script
Download the SQL Server migration script.
After you extract the package, run the following command to view the script's parameters.
python ~/Downloads/RDSSQLCreateMigrateTasksBatchly.py -hThe command returns the following output:
RDSSQLCreateMigrateTasksBatchly.py -k <access_key_id> -s <access_key_secret> -i <rds_instance_id> -e <oss_endpoint> -b <oss_bucket> -d <directory>The following table describes the parameters.
Parameter
Description
access_key_id
The AccessKey ID of your Alibaba Cloud account.
access_key_secret
The AccessKey Secret of your Alibaba Cloud account.
rds_instance_id
The ID of the destination RDS instance.
oss_endpoint
The endpoint of the OSS region where your bucket is located.
oss_bucket
The name of the bucket that contains the backup files.
directory
The directory in the OSS bucket for backup files. For the root directory, enter
/.Run the migration script to complete the migration.
This topic provides an example of fully migrating all backup files that meet specified conditions from the
Migrationdatadirectory of an OSS bucket namedtestdatabucketto an ApsaraDB RDS for SQL Server instance with the instance ID rm-2zesz5774ud8s****.python ~/Downloads/RDSSQLCreateMigrateTasksBatchly.py -k yourAccessKeyID -s yourAccessKeySecret -i rm-2zesz5774ud8s**** -e oss-cn-beijing.aliyuncs.com -b testdatabucket -d Migrationdata
4. View migration task progress
Follow the instructions for your ApsaraDB RDS instance's SQL Server version.
SQL Server 2012 and later
In the left navigation pane of your ApsaraDB RDS instance, go to the Backup and Restoration page. On the Cloud Migration Records of Backup Data tab, you can view the cloud migration records, including the task status, start time, and end time. By default, records from the last week are displayed. Adjust the time range as needed.

If the Task Status is Failed, check the Task Description or click View File Details next to the target migration task to determine why the task failed. After you fix the issue, run the migration task again.
SQL Server 2008 R2
In the left navigation pane of your ApsaraDB RDS instance, go to the Data Migration To Cloud page. Then, find the target migration task to view its progress.
If the Task Status is Failed, check the Task Description or click View File Details next to the target migration task to determine why the task failed. After you fix the issue, run the migration task again.
Common errors
Error message | Cause | Solution |
| The AccessKey ID used for the OpenAPI call is incorrect. | Provide the correct AccessKey ID and AccessKey Secret. |
| The AccessKey Secret used for the OpenAPI call is incorrect. | |
| This solution supports only ApsaraDB RDS for SQL Server. Other database engines are not supported. | Use an ApsaraDB RDS for SQL Server instance as the migration destination. |
| The specified RDS instance ID does not exist. | Verify that the provided RDS instance ID is correct. |
| Connection failed due to an incorrect endpoint. | Verify that the provided endpoint is correct. |
| The specified OSS bucket does not exist. | Verify that the provided OSS bucket name is correct. |
| The specified folder does not exist in the OSS bucket, or the folder does not contain any qualifying database backup files. | Verify that the folder exists in the OSS bucket and contains qualifying database backup files. |
| The backup file name does not follow the required naming convention. | If you do not use the backup script, you must name the backup file in the |
| The RAM user has insufficient permissions. | You must grant the RAM user permissions to access OSS and RDS. This requires the AliyunOSSFullAccess and AliyunRDSFullAccess policies. |
| The OpenAPI call returned an error. | Analyze the root cause based on the returned error code and error message. |
OpenAPI error codes
HTTP status code | Error | Message | Description |
403 | InvalidDBName | The specified database name is not allowed. | The database name is invalid. You cannot use system database names. |
403 | IncorrectDBInstanceState | The current instance state does not allow this operation. | The RDS instance is in an invalid state. For example, the instance is in the Creating state. |
400 | IncorrectDBInstanceType | The current instance type does not support this operation. | The instance's engine is not supported. This feature is available only for ApsaraDB RDS for SQL Server. |
400 | IncorrectDBInstanceLockMode | The current instance lock mode does not support this operation. | The database is in an invalid lock state. |
400 | InvalidDBName.NotFound | One or more of the specified database names do not exist, or their status does not allow the operation. | The database does not exist.
|
400 | IncorrectDBType | The database type does not support this operation. | |
400 | IncorrectDBState | The current database state does not allow this operation. | The database is in an invalid state, for example, it is being created or a migration is in progress. |
400 | UploadLimitExceeded | The daily migration quota for the database has been exceeded. | A maximum of 20 migrations are allowed per database on each instance per day. |
400 | ConcurrentTaskExceeded | The daily migration quota for the instance has been exceeded. | An instance is limited to a maximum of 500 migrations per day. |
400 | IncorrectFileExtension | The file extension is not supported. | The backup file has an invalid extension. |
400 | InvalidOssUrl | The specified OSS URL is invalid. | The provided OSS download URL is unavailable. |
400 | BakFileSizeExceeded | The backup file exceeds the allowed size limit. | The backup file size cannot exceed 3 TB. |
400 | FileSizeExceeded | The file is too large for the destination instance. | Restoring the backup file would exceed the storage capacity of the destination instance. |
API reference
|
API |
Description |
|
Creates a data migration task by restoring a backup file from OSS to an ApsaraDB RDS for SQL Server instance. |
|
|
Brings a database online after it is restored as part of a data migration task. |
|
|
Lists the data migration tasks for an ApsaraDB RDS for SQL Server instance. |
|
|
Returns the backup file details for a data migration task. |



, select the backup file that you want to upload, and then click Open.

