ApsaraDB RDS for SQL Server provides a solution that allows you to migrate self-managed SQL Server databases to Alibaba Cloud. You need to only upload the full backup data of your self-managed SQL Server database to Alibaba Cloud Object Storage Service (OSS) and then import the full backup data to the specified ApsaraDB RDS for SQL Server database from the ApsaraDB RDS console. This solution is suitable for scenarios such as data backup, data migration, and disaster recovery.
Prerequisites
The ApsaraDB RDS for SQL Server instance must meet the following requirements:
The remaining storage space of the instance must be greater than the size of the data files to be migrated. If the storage space is insufficient, upgrade the storage of the instance in advance.
If the instance runs SQL Server 2012 or later, or SQL Server 2008 R2 with cloud disks, make sure that the instance does not contain a database that has the same name as the database to be migrated.
If the instance runs SQL Server 2008 R2 with high-performance local disks, make sure that a database that has the same name as the database to be migrated is created on the instance.
If you log on as a RAM user, the following requirements must be met:
The RAM user is granted the AliyunOSSFullAccess and AliyunRDSFullAccess permissions. For more information about how to grant permissions to a RAM user, see Manage OSS permissions by using RAM and Manage ApsaraDB RDS permissions by using RAM.
Your Alibaba Cloud account (primary account) has authorized the ApsaraDB RDS official service account to access your OSS resources.
Manually create a permission policy in your Alibaba Cloud account (primary account), and then attach the policy to the RAM user.
Notes
Migration scope: This solution supports only the migration of a single database (database level). To migrate multiple databases or all databases, use the instance-level migration solution.
Version compatibility: A backup file that is created in a self-managed SQL Server environment cannot be migrated to an ApsaraDB RDS for SQL Server instance that runs a lower version.
Permission management : After you grant the ApsaraDB RDS service account the permissions to access OSS, the system creates a role named
AliyunRDSImportRolein RAM. Do not modify or delete the role. Otherwise, migration tasks fail . If you accidentally modify or delete the role, grant the permissions again in the data migration wizard.Account management: After the migration is complete, the accounts of the original database become unavailable. Create accounts again in the ApsaraDB RDS console.
OSS file retention: Before the migration task is complete, do not delete the backup file from OSS. Otherwise, the task fails.
Backup file requirements:
File name: The file name cannot contain special characters such as
!@#$%^&*()_+-=. Otherwise, the migration fails.File extension: The backup files supported by ApsaraDB RDS include
.bak(full backup),.diff(differential backup), and.trnor.log(log backup) files. Files of other types cannot be recognized.File type: Only full backup files can be uploaded. Differential backup files and log backup files are not supported.
File source: If the source data is a full backup file of ApsaraDB RDS for SQL Server that was previously downloaded (in
.zipformat by default), decompress it into a.bakfile before you migrate the data to the cloud.
Billing
Only OSS-related fees are incurred in this solution. For more information, see the following:
Scenario | Billing |
Upload the backup file of the self-managed database to OSS | Free of charge. |
Store the backup file in OSS | OSS storage fees are charged. For more information about billing, see OSS pricing. |
Migrate the backup file from OSS to ApsaraDB RDS |
|
Preparation
Run the DBCC CHECKDB statement in the self-managed database environment to make sure that the database does not contain allocation errors or consistency errors. If the database is in the normal state, the following result is returned:
...
CHECKDB found 0 allocation errors and 0 consistency errors in database 'xxx'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.1. Back up the self-managed database
Select a solution based on the version of your ApsaraDB RDS for SQL Server instance.
SQL Server 2012 or later, or SQL Server 2008 R2 with cloud disks
Before you create a full backup for the self-managed database, make sure that data writes are stopped. Data that is written during the backup process is not included in the backup file.
Run the following command to check the current recovery model of the source database:
SELECT name AS DatabaseName, recovery_model_desc AS RecoveryModel, state_desc AS State FROM sys.databases ORDER BY name;Before you create a production backup for migration to ApsaraDB RDS, change the recovery model of the database to FULL:
ALTER DATABASE [db_simple] SET RECOVERY FULL WITH NO_WAIT;Download the backup script, and then open the backup script in SQL Server Management Studio (SSMS).
Modify the following parameters in the SELECT statement of the script. The parameters are located below
YOU HAVE TO INIT PUBLIC VARIABLES HEREin the script.Parameter
Description
@backup_databases_list
The databases that you want to back up. Separate multiple databases with semicolons (;) or commas (,).
@backup_type
The backup type. Valid values:
FULL: full backup.
DIFF: differential backup.
LOG: log backup.
@backup_folder
The local directory in which the backup files are stored. If the directory does not exist, the directory is automatically created.
@is_run
Specifies whether to perform the backup. Valid values:
1: performs the backup.
0: performs only a check and does not perform the backup.
Run the backup script.
SQL Server 2008 R2 with high-performance local disks
Open Microsoft SQL Server Management Studio (SSMS).
Log on to the database that you want to migrate.
Run the following command to check the current recovery model of the source database:
USE master; GO SELECT name, CASE recovery_model WHEN 1 THEN 'FULL' WHEN 2 THEN 'BULK_LOGGED' WHEN 3 THEN 'SIMPLE' END model FROM sys.databases WHERE name NOT IN ('master','tempdb','model','msdb'); GOIf the
modelvalue in the query result is notFULL, perform Step 4.If the
modelvalue in the query result isFULL, perform Step 5.
Run the following command to set the recovery model of the source database to
FULL:ALTER DATABASE [dbname] SET RECOVERY FULL; GO ALTER DATABASE [dbname] SET AUTO_CLOSE OFF; GOImportantAfter the recovery model is set to
FULL, more SQL Server logs are generated. Make sure that sufficient disk space is available.Run the following command to back up the source database.
In this example, the dbtest database is backed up to the backup.bak file.
USE master; GO BACKUP DATABASE [dbtest] to disk ='d:\backup\backup.bak' WITH COMPRESSION,INIT; GORun the following command to verify the integrity of the backup file:
USE master GO RESTORE FILELISTONLY FROM DISK = N'D:\backup\backup.bak';ImportantIf a result set is returned, the backup file is valid.
If an error is reported, perform the backup again.
Optional: Run the following command to restore the recovery model of the database:
ImportantIf the recovery model of the database is already
FULL, skip this step.ALTER DATABASE [dbname] SET RECOVERY SIMPLE; GO
2. Upload the backup file to OSS
Select a solution based on the version of your ApsaraDB RDS for SQL Server instance.
SQL Server 2012 or later, or SQL Server 2008 R2 with cloud disks
Before you upload backup files to OSS, you must create a bucket in OSS.
If a bucket already exists in OSS, make sure that the bucket meets the following requirements:
The storage class of the bucket is Standard. The IA, Archive, Cold Archive, and Deep Cold Archive storage classes are not supported.
Server-side encryption is not enabled for the bucket.
If no bucket exists in OSS, create a bucket first. (Make sure that OSS is activated.)
Log on to the OSS console, click Buckets, and then click Create bucket.
Configure the following key parameters and keep the default values for other parameters.
ImportantThe bucket is used only for this data migration, so you need to only configure the key parameters. After the migration is complete, delete the bucket in a timely manner to prevent data leaks and additional fees.
Do not enable server-side encryption when you create the bucket.
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 rules:
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 in which the bucket resides. If you upload data to the bucket from an ECS instance over the internal network and restore the data to the ApsaraDB RDS instance over the internal network, make sure that the ECS instance, bucket, and ApsaraDB RDS instance reside in the same region.
China (Hangzhou)
Storage Type
Select Standard. The migration operation described in this topic does not support buckets of other storage classes.
Standard
Upload the backup file to OSS.
After the backup of the self-managed database is complete, upload the backup file to an OSS bucket that resides in the same region as your ApsaraDB RDS instance. If the bucket and the ApsaraDB RDS instance reside in the same region, the bucket and the instance can communicate over the internal network. In this case, no Internet traffic fees are charged and data is uploaded at a faster speed. You can use one of the following methods:
SQL Server 2008 R2 with high-performance local disks
Before you upload backup files to OSS, you must create a bucket in OSS.
If a bucket already exists in OSS, make sure that the bucket meets the following requirements:
The storage class of the bucket is Standard. The IA, Archive, Cold Archive, and Deep Cold Archive storage classes are not supported.
Server-side encryption is not enabled for the bucket.
If no bucket exists in OSS, create a bucket first. (Make sure that OSS is activated.)
Log on to the OSS console, click Buckets, and then click Create bucket.
Configure the following key parameters and keep the default values for other parameters.
ImportantThe bucket is used only for this data migration, so you need to only configure the key parameters. After the migration is complete, delete the bucket in a timely manner to prevent data leaks and additional fees.
Do not enable server-side encryption when you create the bucket.
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 rules:
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 in which the bucket resides. If you upload data to the bucket from an ECS instance over the internal network and restore the data to the ApsaraDB RDS instance over the internal network, make sure that the ECS instance, bucket, and ApsaraDB RDS instance reside in the same region.
China (Hangzhou)
Storage Type
Select Standard. The migration operation described in this topic does not support buckets of other storage classes.
Standard
Upload the backup file to OSS.
After the backup of the self-managed database is complete, upload the backup file to an OSS bucket that resides in the same region as your ApsaraDB RDS instance. If the bucket and the ApsaraDB RDS instance reside in the same region, the bucket and the instance can communicate over the internal network. In this case, no Internet traffic fees are charged and data is uploaded at a faster speed. You can use one of the following methods:
Set the validity period of the backup file URL and obtain the URL of the backup file.
Log on to the OSS console.
Click Buckets, and then click the name of the destination bucket.
In the left-side navigation pane, choose File Management > Files.
Click Details in the Actions column of the destination database backup file, and then change Expiration (Seconds) to 28800 seconds, which is 8 hours, in the panel that appears.
ImportantThe URL of the backup file is required when you migrate the backup file from OSS to ApsaraDB RDS. If the URL expires before the migration is complete, the data migration fails.
Click Copy Object URL to obtain the URL of the backup file.

Modify the URL of the backup file.
The URL that you obtain is the public URL of the file by default. To migrate data over the internal network, change the endpoint in the file URL to the internal endpoint.
For example, if the URL of the backup file is
http://rdstest.oss-cn-shanghai.aliyuncs.com/testmigraterds_20170906143807_FULL.bak?Expires=15141****&OSSAccessKeyId=TMP****, changeoss-cn-shanghai.aliyuncs.comin the URL tooss-cn-shanghai-internal.aliyuncs.com.ImportantInternal endpoints vary based on network type and region. For more information, see Regions and endpoints.
3. Import the OSS backup data to ApsaraDB RDS
Select a solution based on the version of your ApsaraDB RDS for SQL Server instance.
SQL Server 2012 or later, or SQL Server 2008 R2 with cloud disks
Go to the Instances page. In the top navigation bar, select the region in which the RDS instance resides. Then, find the RDS instance and click the ID of the instance.
In the left-side navigation pane, choose Restoration.
Click Restore Backup Data from OSS in the upper part of the page.
On the Import Guide page, click Next twice to go to the data import step.
NoteWhen you use the OSS backup data migration feature for the first time, you must authorize the ApsaraDB RDS service account to access OSS. Click Authorization URL and confirm the authorization. Otherwise, the OSS Bucket drop-down list is empty due to a permission issue.
If the destination file is not displayed on the page, check whether the file extension of the backup file in OSS meets the requirements (you can view the extension requirements in Notes in this topic), and make sure that the ApsaraDB RDS instance and the OSS bucket reside in the same region.
Configure the following parameters.
Parameter
Description
Database Name
The name of the database to which the backup data is imported on the destination ApsaraDB RDS instance. The name must comply with the official SQL Server naming rules.
ImportantBefore you migrate data to the cloud, make sure that no database that has the same name as the database to be restored from the backup file exists on the destination instance and no unattached database file that has the same name exists. If neither of them exists, you can restore the database by using the database file that has the same name as the target database name in the backup set.
If a database that has the same name as the database to be restored from the backup file exists on the destination instance or an unattached database file that has the same name exists, the migration fails.
OSS Bucket
Select the OSS bucket in which the backup file is stored.
OSS File
Click the
icon on the right to search for backup files by file name prefix. The file name, file size, and update time of each file are displayed. Select the backup file that you want to migrate.Cloud Migration Method
Immediate Access (Only One Full Backup): full migration. This option is suitable for scenarios in which only one full backup file is used for migration. In this example, Immediate Access (Only One Full Backup) is selected. In this case,
BackupMode = FULLandIsOnlineDB = Truein the CreateMigrateTask operation.Access Pending (Incremental Backup or Log Files): incremental migration. This option is suitable for scenarios in which a full backup file together with log backup files or differential backup files is used for migration. In this case,
BackupMode = UPDFandIsOnlineDB = Falsein the CreateMigrateTask operation.
Consistency Check Mode
Asynchronous DBCC: The system does not run DBCC CHECKDB when the database is opened. Instead, the system asynchronously runs DBCC CHECKDB after the database opening task is complete. This reduces the time overhead of opening the database (DBCC CHECKDB is time-consuming for large databases) and shortens the service downtime. If your service is highly sensitive to downtime and you do not care about DBCC CHECKDB results, use asynchronous DBCC. In this case,
CheckDBMode = AsyncExecuteDBCheckin the CreateMigrateTask operation.Synchronous DBCC: Compared with asynchronous DBCC, synchronous DBCC is suitable for users who care about DBCC CHECKDB results and want to identify data consistency errors in self-managed databases. In this case, the time required to open the database increases. In this case,
CheckDBMode = SyncExecuteDBCheckin the CreateMigrateTask operation.
Click OK.
Wait until the migration task is complete. You can click Refresh to view the latest status of the task. If the migration task fails, troubleshoot the issue based on the message in the task description. For more information, see Common errors in this topic.
NoteAfter the data migration is complete, the system initiates a backup at the specified backup time based on the automatic backup policy of the ApsaraDB RDS instance. You can manually change the backup time. The generated backup set contains the migrated data. You can view the backup set on the Restoration page of the ApsaraDB RDS instance.
If the backup time is not reached but you want to generate a backup in the cloud at the earliest opportunity, you can perform a manual backup.
SQL Server 2008 R2 with high-performance local disks
Log on to the ApsaraDB RDS console and go to the Instances page. In the top navigation bar, select the region in which the RDS instance resides. Then, find the RDS instance and click the ID of the instance.
In the left-side navigation pane, click Databases.
Find the destination database and click Migrate Backup Files from OSS in the Actions column.

In the Import Guide dialog box, read the message, and then click Next.
Read the message about OSS upload, and then click Next.
In the OSS URL of the Backup File field, enter the OSS URL of the backup file, and then click OK.
NoteApsaraDB RDS for SQL Server instances that run SQL Server 2008 R2 with high-performance local disks support only the solution that migrates full backup files to the cloud at a time.
4. View the backup migration progress
Select a solution based on the version of your ApsaraDB RDS for SQL Server instance.
SQL Server 2012 or later, or SQL Server 2008 R2 with cloud disks
Go to the Restoration page in the left-side navigation pane of the ApsaraDB RDS instance, and then view the backup migration records on the Cloud Migration Records of Backup Data tab. The records include the task status, task start time, and task end time. By default, the records of the last week are displayed. You can change the time range as needed.

If Task Status is Failed, check Task Description or click View File Details next to the destination migration task to identify and fix the cause of the failure, and then perform the data migration again.
SQL Server 2008 R2 with high-performance local disks
Go to the data migration page in the left-side navigation pane of the ApsaraDB RDS instance, and then find the destination migration task to view the progress of the data migration.
If Task Status is Failed, check Task Description or click View File Details next to the destination migration task to identify and fix the cause of the failure, and then perform the data migration again.
Common errors
Each backup migration record contains a task description. You can identify the causes of task failures and errors from the task description. The following error messages are common:
A database with the same name already exists
Error message 1: The database (xxx) is already exist on RDS, please backup and drop it, then try again.
Error message 2: Database 'xxx' already exists. Choose a different database name.
Cause: To ensure data security on ApsaraDB RDS for SQL Server, ApsaraDB RDS for SQL Server does not support the migration of data to a database that has the same name as an existing database.
Solution: If you want to overwrite the data of the existing database, back up the existing data, delete the database, and then perform the data migration task again.
A differential backup file is used
Error message: Backup set (xxx.bak) is a Database Differential backup, we only accept a FULL Backup.
Cause: The backup file that you provided is a differential backup file instead of a full backup file. One-time migration of full backup files supports only full backup files and does not support differential backup files.
A log backup file is used
Error message: Backup set (xxx.trn) is a Transaction Log backup, we only accept a FULL Backup.
Cause: The backup file that you provided is a log backup file instead of a full backup file. One-time migration of full backup files supports only full backup files and does not support log backup files.
Backup file verification failure
Error message: Failed to verify xxx.bak, backup file was corrupted or newer edition than RDS.
Cause: The backup file is corrupted, or the version of the SQL Server instance in the self-managed environment is later than the version of the ApsaraDB RDS for SQL Server instance. As a result, the verification fails. For example, this error is reported when you restore a backup file of SQL Server 2016 to an ApsaraDB RDS for SQL Server instance that runs SQL Server 2012.
Solution: If the backup file is corrupted, create another full backup in the self-managed environment and create another migration task. If the version of the SQL Server instance in the self-managed environment is later than the version of the ApsaraDB RDS for SQL Server instance, use an ApsaraDB RDS for SQL Server instance that runs the same version or a later version.
NoteTo upgrade an existing ApsaraDB RDS for SQL Server instance to a later version, see Upgrade database version.
DBCC CHECKDB failure
Error message: DBCC checkdb failed.
Cause: The DBCC CHECKDB operation failed. This indicates that errors have occurred in the database in the self-managed environment.
Solution: Run the following command to fix the database errors in the self-managed environment, and then migrate the data again.
ImportantThe process of fixing errors by using this command may result in data loss.
DBCC CHECKDB (DBName, REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS, ALL_ERRORMSGS
Insufficient storage space 1
Error message: Not Enough Disk Space for restoring, space left (xxx MB) < needed (xxx MB).
Cause: The remaining storage space of the ApsaraDB RDS instance does not meet the minimum storage space that is required to migrate the backup file.
Solution: Upgrade the storage space of the instance.
Insufficient storage space 2
Error message: Not Enough Disk Space, space left xxx MB < bak file xxx MB.
Cause: The remaining storage space of the ApsaraDB RDS instance is less than the size of the backup file and does not meet the minimum storage space requirement.
Solution: Upgrade the storage space of the instance.
Insufficient permissions of the logon account
Error message: Cannot open database "xxx" requested by the login. The login failed.
Cause: The account that is used to log on to the ApsaraDB RDS instance does not have the access permissions on the database.
Solution: Grant the access or management permissions on the database to the account on the Accounts page of the ApsaraDB RDS instance. For more information, see Modify the permissions of an account and Account permissions in an ApsaraDB RDS for SQL Server instance.
No privileged account
Error message: Your RDS doesn’t have any init account yet, please create one and grant permissions on RDS console to this migrated database (xxx).
Cause: No privileged account exists on the ApsaraDB RDS instance. The migration task cannot determine the account to which the permissions on the migrated database must be granted. However, the backup file is restored to the destination instance. Therefore, the task status is Success.
Solution: Create a privileged account.
Insufficient operation permissions of the RAM user
Q1: When I perform Step 5 of the data migration task creation procedure, all parameters are configured, but the OK button is grayed out and cannot be clicked. What do I do?
A1: The button cannot be clicked possibly because you are logged on as a RAM user and your account has insufficient permissions. Check Prerequisites in this topic to make sure that the required permissions are granted.
Q2: What do I do if the
permission deniedmessage appears when I use a RAM user to grant permissions onAliyunRDSImportRole?A2: Use your Alibaba Cloud primary account to temporarily grant the AliyunRAMFullAccess permission to the RAM user.
The database name is the same as the name of a SQL Server system database
Error message: The database (xxx) is mssql system db, change your database name and try again.
Cause: The specified database name is the same as the name of a SQL Server system database such as master, msdb, tempdb, or model.
Solution: Specify another database name.
The database name is the same as the name of a system database of the RDS instance
Error message: The database (xxx) is RDS system db, change your database name and try again.
Cause: The specified database name is the same as the name of a management database of the ApsaraDB RDS for SQL Server instance, such as rdscore.
Solution: Specify another database name.
The number of databases exceeds the upper limit
Error message: The database (xxx) migration failed due to databases count limitation: xxx.
Cause: The number of databases exceeds the upper limit.
Solution: Reduce the number of databases on the instance and try again.
OSS download URL issues
Error message 1: Failed to download backup (xxx) since OSS URL was expired.
Error message 2: Failed to download since could not find backup file (xxx) on OSS.
Cause: The OSS download URL expired, the ApsaraDB RDS service account was not authorized, the RAM user had insufficient permissions, or the file does not exist.
Solution: Check whether the file exists in OSS, whether permissions are properly granted, and whether the authorization is valid. Then, try again.
Striped backup issues
Error message: Failed to verify (xxx.bak), error message:The media set has xxx media families but only 1 are provided. All members must be provided. VERIFY DATABASE is terminating abnormally.
Cause: The striped backup feature was used when the source database was backed up. In this case, a full backup is split into multiple .bak files, but only one file is provided when the data is migrated from OSS to ApsaraDB RDS. ApsaraDB RDS does not support migration based on multiple files at a time.
Solution: Back up the source database to a single .bak file and try again.
Common return messages
Task type | Task status | Task description | Description |
One-time migration of full backup files | Success |
| The migration is successful. |
Failed |
| The validity period of the OSS download URL expired, which caused the migration to fail. | |
| The backup file is corrupted or created on a later version than the RDS version, which caused the migration to fail. | ||
| The DBCC checkdb operation failed, which caused the migration to fail. | ||
| A log backup file was used, which caused the migration to fail. | ||
| A differential backup file was used, which caused the migration to fail. |
Related API operations
API | Description |
Restores backup files from OSS to an ApsaraDB RDS for SQL Server instance and creates a data migration task. | |
Opens the database of a backup data migration task on an ApsaraDB RDS for SQL Server instance. | |
Queries the list of backup data migration tasks on an ApsaraDB RDS for SQL Server instance. | |
Queries the details of the backup files of a backup data migration task on an ApsaraDB RDS for SQL Server instance. |



, select the backup file that you want to upload, and then click Open. The local file is uploaded to OSS.

