Export your RDS instance data to a self-managed SQL Server database by downloading physical backup files from the RDS console and restoring them using T-SQL RESTORE DATABASE commands.
You can also use Data Transmission Service (DTS) to migrate physical backup files or snapshot backup files from the cloud to a self-managed SQL Server instance, with ApsaraDB RDS for SQL Server as the source and your self-managed SQL Server as the destination.
Prerequisites
Before you begin, make sure you have:
Physical backup files created for the RDS instance. For details, see Physical backup
Access to the self-managed SQL Server host to run T-SQL commands
How it works
The migration follows four phases:
Download the full and incremental physical backup files from the RDS console.
Upload and decompress the backup files on the self-managed SQL Server host.
Restore the database from the full backup (with
NORECOVERYto keep it in a restoring state).Optionally apply the incremental backup, then bring the database online with
RECOVERY.
Download backup files
Download the full and incremental physical backup files from the RDS console. For the download steps and link format, see Download data backup files and log backup files.
If the self-managed SQL Server host can reach the RDS instance network, download the backup files directly on the host:
wget "<download-url>"Replace <download-url> with the download URL of the backup files.
Upload and decompress backup files
Upload the downloaded backup files to the self-managed SQL Server host.
Decompress the full and incremental physical backup files.
The full and incremental backup files have the same filename after decompression. Rename them before restoring to avoid confusion. Use the format
<Database name>_<Backup method>_<Date>.bak. For example: -testdb_datafull_201901071320.bak—datafullindicates a full backup -testdb_datadiff_201901071330.bak—datadiffindicates an incremental backupNote the file paths. For example:
Full backup:
/tmp/testdb_datafull_201901071320.bakIncremental backup:
/tmp/testdb_datadiff_201901071330.bak
Query logical file names
Log in to the self-managed SQL Server database and run the following command to list the logical file names inside the backup file:
RESTORE FILELISTONLY FROM DISK='/tmp/testdb_datafull_201901071320.bak';
GOThe output shows the logical names for the data and log files. In this example:
Data file logical name:
testdbLog file logical name:
testdb_log

Restore from full backup
Run the following command to restore the database from the full backup file and specify the target paths for the data and log files:
RESTORE DATABASE testdb FROM DISK = '/tmp/testdb_datafull_201901071320.bak' WITH REPLACE, NORECOVERY, STATS = 10,
MOVE 'testdb' TO '/var/opt/mssql/data/testdb.mdf',
MOVE 'testdb_log' TO '/var/opt/mssql/data/testdb_log.ldf';
GOAfter the command completes, the testdb database status shows Restoring.
If you only need to restore the full backup data, skip the next section and go directly to Bring the database online.
Path reference:
| Path | Description |
|---|---|
/var/opt/mssql/data/testdb.mdf | Target path for the data file (testdb is the logical name) |
/var/opt/mssql/data/testdb_log.ldf | Target path for the log file (testdb_log is the logical name) |
To find the target paths on your system, check Properties > Files of the destination database.
Apply incremental backup (optional)
Run the following command to apply the incremental backup on top of the full backup restore:
RESTORE DATABASE testdb FROM DISK = '/tmp/testdb_datadiff_201901071330.bak' WITH REPLACE, NORECOVERY, STATS = 10,
MOVE 'testdb' TO '/var/opt/mssql/data/testdb.mdf',
MOVE 'testdb_log' TO '/var/opt/mssql/data/testdb_log.ldf';
GOAfter the command completes, the testdb database status shows Restoring.
Bring the database online
Run the following command to finalize the restore and bring the database to an available state:
RESTORE DATABASE testdb WITH RECOVERY;
GOThe testdb database is now online and accessible.