Use the sp_rds_copy_database stored procedure to replicate a database on ApsaraDB RDS for SQL Server 2012 or later. The time required varies based on the size of the source database.
To replicate a database on an RDS instance that runs SQL Server 2008 R2, see Replicate databases of an ApsaraDB RDS instance that runs SQL Server 2008 R2.
Prerequisites
Before you begin, make sure you have:
An RDS instance running SQL Server 2012 or later
Available storage capacity on the destination RDS instance that is at least 1.3 times larger than the size of the source database
Replicate a database
Run the following statements in sequence to replicate a database.
Step 1: Switch to the master database context.
USE master
GOStep 2: (Optional) Check the database engine version.
-- Verify the SQL Server version before proceeding
SELECT @@Version
GOStep 3: Create the source database (skip this step if the source database already exists).
-- Create the source database for testing
CREATE DATABASE testdb
GOStep 4: Replicate the source database.
-- Replicate testdb (source) to testdb_copy (destination)
-- Replace testdb and testdb_copy with your actual database names
EXEC sp_rds_copy_database 'testdb', 'testdb_copy'Monitor replication progress
After calling sp_rds_copy_database, query sys.databases and sys.database_recovery_status to track progress.
Check whether the destination database was created:
SELECT *
FROM sys.databases
WHERE name IN ('testdb', 'testdb_copy')Check the recovery status of the databases:
SELECT
family_guid, database_guid, *
FROM sys.database_recovery_status
WHERE DB_NAME(database_id) IN ('testdb', 'testdb_copy')What's next
Connect to the destination database and verify the schema and data.
Update application connection strings if you are using the replicated database as a replacement or test environment.