ApsaraDB RDS for SQL Server instances allow you to easily migrate data to the cloud. You need to only upload the full backup data of the source database on your self-managed SQL Server instance to an Object Storage Service (OSS) bucket, and then migrate the full backup data to the destination database on your ApsaraDB RDS for SQL Server instance by using the ApsaraDB RDS console. You can use this feature in scenarios such as data backup, migration, and disaster recovery.
You can perform the operations that are described in this topic only when your RDS instance runs SQL Server 2008 R2 with cloud disks or runs SQL Server 2012 or later.
For more information about how to migrate the full backup data of a self-managed SQL Server instance to an RDS instance that runs SQL Server 2008 R2 with local disks, see Migrate the full backup data of a self-managed SQL Server instance to an ApsaraDB RDS instance that runs SQL Server 2008 R2 with local disks.
Prerequisites
The RDS instance runs SQL Server 2008 R2 with cloud disks or runs SQL Server 2012 or later. The names of the databases on the RDS instance are different from the names of the databases that you want to migrate from the self-managed SQL Server instance. For more information about how to create an RDS instance, see Create an ApsaraDB RDS for SQL Server instance.
NoteApsaraDB RDS instances that run SQL Server 2008 R2 with cloud disks are no longer available for purchase. For more information, see [EOS/Discontinuation] ApsaraDB RDS instances running SQL Server 2008 R2 with cloud disks are no longer available for purchase from July 14, 2023.
The available storage of the RDS instance is sufficient. If the available storage is insufficient, you must expand the storage capacity of the RDS instance before you start the migration. For more information, see Change the specifications of an ApsaraDB RDS for SQL Server instance.
A privileged account is created for the RDS instance. For more information, see Create accounts and databases.
The
DBCC CHECKDB
statement is executed to ensure that noallocation errors
orconsistency errors
occur in the self-managed SQL Server instance. If no allocation or consistency errors occur, the following execution 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.
OSS is activated. For more information, see Activate OSS.
If you use a RAM user, make sure that the following requirements are met:
The AliyunOSSFullAccess and AliyunRDSFullAccess policies are attached to the RAM user. For more information about how to grant permissions to RAM users, see Use RAM to manage OSS permissions and Use RAM to manage ApsaraDB RDS permissions.
The service account of ApsaraDB RDS is authorized by using your Alibaba Cloud account to access the OSS bucket.
A custom policy is manually created by using your Alibaba Cloud account and is attached to the RAM user. For more information about how to create a custom policy, see the Create a custom policy on the JSON tab section in Create custom policies.
Usage notes
The migration method that is described in this topic is at the database level. You can migrate the full backup data only of a single self-managed database to your RDS instance at a time. If you want to migrate the backup data of multiple or all databases in a self-managed SQL Server instance at a time, we recommend that you use an instance-level migration method. For more information, see Migrate data from a self-managed SQL Server instance to an ApsaraDB RDS for SQL Server instance.
You cannot migrate the backup files of a self-managed SQL Server instance that runs a later database engine version than the RDS instance. For example, you cannot migrate the backup files of a self-managed instance that runs SQL Server 2016 to an RDS instance that runs SQL Server 2012.
Differential backup files and log backup files are not supported.
To avoid data migration failures, make sure that the name of a full backup file does not contain the following special characters: ! @ # $ % ^ & * ( ) _ + - =
After you authorize the service account of ApsaraDB RDS to access the OSS bucket, a role named AliyunRDSImportRole is created in RAM. Do not modify or delete this role. If you modify or delete this role, the backup files cannot be downloaded from the OSS bucket. In this case, you must re-authorize the service account by using the migration wizard.
The RDS instance does not carry over the accounts of the self-managed SQL Server instance. After the migration is complete, you must create accounts for the RDS instance in the ApsaraDB RDS console.
Before the migration is complete, do not delete the full backup file from the OSS bucket. If you delete the full backup file before the migration is complete, the migration fails.
The name of a backup file must be suffixed by bak, diff, trn, or log. The following list describes the suffixes:
bak: indicates a full backup file.
diff: indicates a differential backup file.
trn or log: indicates a log backup file of transactions.
NoteIf the backup files do not use the preceding suffixes, the system may fail to identify the types of the backup files. This affects subsequent operations.
By default, the full backup files of the RDS instance are in the ZIP format. If you download a ZIP file, you must decompress the ZIP file to obtain a full backup file whose name is suffixed by bak. Then, you can use the full backup file to migrate the data to your RDS instance.
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 |
|
Step 1: Back up the source database on the self-managed instance
Before you perform a full backup, you must stop all data writes to the source database on the self-managed instance. The data that is written to the self-managed database during the full backup process cannot be backed up.
Download the backup script and use SQL Server Management Studio (SSMS) to open the backup script.
Modify parameters based on your business requirements. The following table describes the parameters in the backup script.
Parameter
Description
@backup_databases_list
The name of the database that you want to back up. If you specify multiple databases, separate the names of the databases with semicolons (;) or commas (,).
@backup_type
The backup type. Valid values:
FULL: full backup
DIFF: incremental backup
LOG: log backup
@backup_folder
The directory that is used to store backup files on the self-managed database. If the specified directory does not exist, the system automatically creates one.
@is_run
Specifies whether to perform a backup or a check. Valid values:
1: performs a backup.
0: performs a check.
NoteModify the preceding parameters in the SELECT statement in the YOU HAVE TO INIT PUBLIC VARIABLES HERE section of the backup script.
Run the backup script.
Step 2: Upload backup file to the OSS bucket
If an OSS bucket is created, check whether the bucket meets the following requirements:
The storage class of the OSS bucket is Standard. The storage class cannot be Standard, Infrequent Access (IA), Archive, Cold Archive, or Deep Cold Archive. For more information, see Overview.
Data encryption is not enabled for the OSS bucket. For more information, see Data encryption.
Create an OSS bucket.
Log on to the OSS console.
In the left-side navigation pane, click Buckets. On the Buckets page, click Create Bucket.
Configure the following parameters. Retain the default values for other parameters.
ImportantThe created OSS bucket is used only for the data migration and is no longer used after the data migration is complete. You need to only configure key parameters. To prevent data leaks and excessive costs, we recommend that you delete the OSS bucket after the data migration is complete at the earliest opportunity.
Do not enable data encryption when you create an OSS bucket. For more information, see Data encryption.
Parameter
Description
Example
Bucket Name
The name of the OSS bucket. The name is globally unique and cannot be modified after it is configured.
Naming conventions:
The name can contain only lowercase letters, digits, and hyphens (-).
It 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 of the OSS bucket. If you want to upload data to the OSS bucket from an Elastic Compute Service (ECS) instance over an internal network and then restore the data to the RDS instance over the internal network, make sure that the OSS bucket, ECS instance, and RDS instance reside in the same region.
China (Hangzhou)
Storage Class
The storage class of the bucket. Select Standard. The cloud migration operations described in this topic cannot be performed in buckets of other storage classes.
Standard
Upload backup files to the OSS bucket.
NoteIf the RDS instance and the OSS bucket reside in the same region, they can communicate with each other over an internal network. You can use the internal network to upload the backup data. The method is faster, and no fees are generated for Internet traffic. We recommend that you upload the backup file to an OSS bucket that is in the same region as the destination RDS instance.
After the full backup on the self-managed SQL Server instance is complete, you must use one of the following methods to upload the generated full backup file to the OSS bucket:
Step 3: Create a migration task
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 Backup and Restoration.
In the upper-right corner of the page, click Migrate OSS Backup Data to RDS.
In the Import Guide wizard, click Next twice.
NoteIf you use the OSS-based migration wizard for the first time, you must authorize the service account of ApsaraDB RDS to access the OSS bucket. In this case, you must click Authorize and complete the authorization. Otherwise, the OSS Bucket drop-down list in the Import Data step is empty.
Configure the following parameters.
Parameter
Description
Database Name
Enter the name of the destination database on your RDS instance. The destination database is used to store the data that is migrated from the source database on the self-managed SQL Server instance. The name of the destination database must meet the requirements of open source SQL Server.
ImportantBefore migration, you must make sure that the names of the databases on the destination RDS instance are different from the name of the database that you want to restore by using the specified backup file. In addition, make sure that database files with the same name as the database that you want to restore by using the specified backup file are not added to the databases on the destination RDS instance. If both preceding requirements are met, you can restore the database by using a database file in the backup set. Note that the database file must have the same name as the database that you want to restore.
If one of the preceding requirements is not met, the migration fails.
OSS Bucket
The OSS bucket that stores the full backup file.
OSS Subfolder Name
The name of the OSS subfolder that stores the full backup file.
OSS File
The full backup file that you want to import. You can enter a prefix in the search box and click the icon to search for the full backup file in fuzzy match mode. The name, size, and update time of each full backup file whose name contains the prefix are displayed. Select the backup file that you want to migrate to the cloud.
Cloud Migration Method
Immediate Access (Full Backup): If you want to migrate only a full backup file, select this migration plan. For this example, select Immediate Access (Full Backup). In this case, the following parameter settings take effect in the CreateMigrateTask operation:
BackupMode = FULL
andIsOnlineDB = True
.Access Pending (Incremental Backup): If you want to migrate a full backup file and a log or differential backup file, select this migration method. In this case, the following parameter setting takes effect in the CreateMigrateTask operation:
BackupMode = UPDF
andIsOnlineDB = False
.
Consistency Check Mode
Asynchronous DBCC: The DBCC CHECKDB statement is executed after the destination database is opened. This reduces the time that is required to open the destination database and minimizes the downtime of your application. If the destination database is large, a long period of time is required to execute the DBCC CHECKDB statement. If your application is sensitive to downtime but insensitive to the result of the DBCC CHECKDB statement, we recommend that you select this consistency check mode. In this case, the following parameter setting takes effect in the CreateMigrateTask operation:
CheckDBMode = AsyncExecuteDBCheck
.Synchronous DBCC: The DBCC CHECKDB statement is executed at the same time when the destination database is opened. If you want to identify consistency errors between the source database and the destination database based on the result of the DBCC CHECKDB statement, we recommend that you select this consistency check mode. However, the time that is required to open the destination database increases. In this case, the following parameter setting takes effect in the CreateMigrateTask operation:
CheckDBMode = SyncExecuteDBCheck
.
Click OK.
Wait until the migration task is complete. You can click Refresh to view the latest state of the migration task. If the migration task fails, you can troubleshoot the failure based on the description of the migration task. For more information, see Common errors.
Step 4: View the migration task
If you want to view details about the migration task, go to the Backup and Restoration page and click the Cloud Migration Records of Backup Data tab. By default, this tab displays the migration tasks over the last week.
Common errors
Each migration task record on the Backup Data Upload History tab of the Backup and Restoration page contains the description of a task. If the migration task fails or an error is reported, you can troubleshoot the failure or error based on the task description. The following common errors may occur:
An existing database on the RDS instance has the same name as the source database.
Error message: The database (xxx) is already exist on RDS, please backup and drop it, then try again.
Cause: If an existing database on the RDS instance has the same name as the source database, the migration is not supported. This mechanism is designed to ensure the security of your data.
Solution: If you want to overwrite an existing database on the RDS instance, back up the database, delete the database from the RDS instance, and then create and run a 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 file that you upload is a differential backup file rather than a full backup file. The migration method in this topic supports only full 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 file that you upload is a log backup file rather than a full backup file. The migration method in this topic supports only full backup files.
The full backup file fails the verification.
Error message: Failed to verify xxx.bak, backup file was corrupted or newer edition than RDS.
Cause: The full backup file is corrupted, or the self-managed instance runs a later SQL Server version than the RDS instance. For example, this error occurs if the self-managed instance runs SQL Server 2016 and the RDS instance runs SQL Server 2012.
Solution: If the full backup file is corrupted, perform a full backup on the self-managed SQL Server instance again. Then, create and run a migration task again. If the self-managed instance runs a later SQL Server version than the RDS instance, select a different RDS instance that runs the same version as or a later version than the self-managed instance.
NoteTo upgrade the major engine version of an existing RDS for SQL Server instance, see Upgrade the major engine version.
The DBCC CHECKDB statement fails.
Error message: DBCC checkdb failed.
Cause: The self-managed SQL Server instance encounters allocation or consistency errors.
Solution: Execute the following statement on the self-managed SQL Server instance to fix the error. Then, create and run a migration task again.
ImportantIf you use this solution to fix the issue, your data may be lost.
DBCC CHECKDB (DBName, REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS, ALL_ERRORMSGS
The available storage of the RDS instance is insufficient.
Error 1
Error message: Not Enough Disk Space for restoring, space left (xxx MB) < needed (xxx MB).
Cause: The available storage of the RDS instance is less than the minimum storage that is required to restore data by using the full backup file.
Solution: Expand the storage capacity of the RDS instance. For more information, see Change the specifications of an ApsaraDB RDS for SQL Server instance.
Error 2
Error message: Not Enough Disk Space, space left xxx MB < bak file xxx MB.
Cause: The available storage of the RDS instance is less than the size of the full backup file.
Solution: Expand the storage capacity of the RDS instance. For more information, see Change the specifications of an ApsaraDB RDS for SQL Server instance.
No privileged account is created on the RDS instance.
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 is created on the RDS instance. As a result, the migration task cannot find the account that requires authorization. However, the full backup file has been restored to the RDS instance, and the migration task is successful.
Solution: Create a privileged account on the RDS instance. For more information, see Create a privileged account or a standard account.
The RAM user does not have the required permissions.
Error 1
Error: The parameters that are described in the substep 5 of Step 3: Create a migration task are correctly configured, but the OK button is dimmed.
Cause: You are using a RAM user that does not have the required permissions.
Solution: Refer to the "Prerequisites" section of this topic to grant required permissions to the RAM user.
Error 2
Error: A message appears to indicate that the RAM user does not have permissions to grant the
AliyunRDSImportRole
permission.Cause: The RAM user that you are using does not have the required permissions.
Solution: Use your Alibaba Cloud account to grant the
AliyunRAMFullAccess
permission to your RAM user. For more information, see Use RAM to manage ApsaraDB RDS permissions.
Related operations
Operation | Description |
Creates a data migration task. | |
Opens the database to which backup data is migrated on an ApsaraDB RDS for SQL Server instance. | |
Queries the tasks that are created to migrate the backup data of an ApsaraDB RDS for SQL Server instance. | |
Queries the backup file details of a backup data migration task for an ApsaraDB RDS for SQL Server instance. |