TencentDB for SQL Server supports data migration by using COS files. The migration method described in this document is also applicable to migration from an SQL Server instance purchased at another cloud service provider or self-created instance to a TencentDB for SQL Server instance on the same version.
Note:
- Before migration, please make sure that the SQL Server version of the target instance is the same as that of the source instance.
- For the .bak files used for migration, please make sure that each .bak file contains only one database.
- The name of the migrated database cannot be the same as that of the TencentDB for SQL Server instance.
There are two ways to prepare a full backup file:
.bak
format). The server should be shut down until the migration is completed.Note:
- The backup file name cannot be customized and must follow the naming convention in the script.
- After full backup is performed, you need to perform incremental backup restoration until the data on the source instance is the same as that on the target instance.
- If the filename contains
1full1
, it is full backup.- In the incremental restoration scenario, after backup upload and data migration are completed, the database will be in "restoring" status before the last incremental backup and restoration is performed. At this time, the database cannot be accessed, which is normal. You need to perform the last incremental backup and restoration to make the database accessible.
You do not need to shut down your SQL Server instance purchased at another cloud service provider or self-created instance. Perform backup of the database and export the backup file.
---If incremental restoration is not required:
backup database db to disk='d:\db.bak' with init
---If incremental restoration is required:
declare @dbname varchar(100)
declare @localtime varchar(20)
declare @str varchar(max)
set @dbname='db'
set @localtime =replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')
set @str='BACKUP DATABASE [' + @dbname + '] TO DISK = N''d:\dbbak\' + @dbname + '_' + @localtime + '_1full1_1noreconvery1.bak'' WITH INIT'
exec(@str)
go
Note:
- The backup file name cannot be customized and must follow the naming convention in the script.
- If the filename contains
1diff1
, it is incremental backup.
Note:
After "backup generation, backup upload, and data migration" are completed, the database will be in "restoring" status. At this time, it cannot be accessed, which is normal. You can repeat this operation until the last backup upload and migration, and then perform the next step (i.e., "last incremental backup after server shutdown").
declare @dbname varchar(100)
declare @localtime varchar(20)
declare @str varchar(max)
set @dbname='db'
set @localtime =replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')
set @str='BACKUP DATABASE [' + @dbname + '] TO DISK = N''d:\dbbak\' + @dbname + '_' + @localtime + '_1diff1_1noreconvery1.bak'' WITH DIFFERENTIAL, NOFORMAT, INIT'
exec(@str)
go
Note:
Only after this operation is performed can the database be accessed normally.
declare @dbname varchar(100)
declare @localtime varchar(20)
declare @str varchar(max)
set @dbname='db'
set @localtime =replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')
set @str='BACKUP DATABASE [' + @dbname + '] TO DISK = N''d:\dbbak\' + @dbname + '_' + @localtime + '_1diff1_1reconvery1.bak'' WITH DIFFERENTIAL, NOFORMAT, INIT'
exec(@str)
go
_1diff1_1reconvery1
) is imported, the status of the target instance will change from read-only to usable, and you can switch your business to the TencentDB for SQL Server instance.
Was this page helpful?