Sql Server Migration

Side-by-side migration

A side-by-side upgrade/Migration consists of installing SQL Server Latest Version and moving the databases from the old instance to the new instance. The side-by-side method gives us a chance to test the effects SQL Server 2Latest Version will have on the application before moving from the older version. The new instance can be installed on a second server, or we can use the same server provided it meets the installation requirements. Migration provides access to two instances of the system, letting us verify and compare the two systems. During migration, both the old and new systems remain online until migration to the new instance is complete. At the end of the migration, all applications are directed to access the new instance and the old instance is manually removed.

Once we have installed the new instance of SQL Server Latest Version, there are three methods for moving the databases to the new instance:

1) Copy database Wizard
2) Database Backup and Restore
3) Detaching and Attaching

Installing SQL Server Latest Version in this side-by-side approach is no different from doing a fresh install. However, with a side-by-side upgrade, we need to worry is about how to migrate the database to the new instance.

Copy database Wizard: The Copy Database Wizard lets us move or copy databases and their objects easily from one instance to another instance, with no server downtime. We can use the Copy Database Wizard to copy our database to an upgraded instance of SQL Server Latest Version. We are given the option to make a copy of the database or completely move the database. We may also choose to copy the database by using the detach and attach method, or by using SQL Management Objects (SMO). If we use the detach and attach method from the wizard, we need to make sure that there are no users trying to access the database before running the wizard. If we use SMO, the database will remain online during the entire process. We can also choose to move any database-related objects, such as logins and jobs. We should point out that while we can copy logins using the Copy Database Wizard, for security reasons, the wizard creates the login on the destination server with a random password and then disables the login.

Using this wizard, we can do the following.
1) Pick a source and destination server.
2) Select databases to move or copy.
3) Specify the file location for the databases.
4) Create logins on the destination server.
5) Copy additional supporting objects, jobs, user-defined stored procedures, and error messages.
6) Schedule when to move or copy the databases.

NOTE: The Copy Database Wizard creates a SQL Server Agent job that executes an SSIS package. We need to make sure that we have Integration Services installed and the SQL Server Agent running on the destination server prior to executing the Copy Database Wizard.

Database Backup and Restore: Using the backup and restore method is a good way to copy the database to the new instance without impacting the availability of the current database. All we need to do is take a full backup of the current database, copy that backup to the new location, and restore it. SQL Server will upgrade the database during the restore process. The result will be a SQL Server Latest Version database that we will not be able to move back to an earlier release.
We need to copy any objects outside the database, such as logins and jobs, since we cannot restore system databases to a newer version of SQL Server.

Detaching and Attaching: We can prefer the detach and attach method when permanently moving databases to a new instance of SQL Server. By moving each file itself instead of a copy of the file at any given point in time, we can be sure that we have captured the exact state of the database as it existed on the previous instance. Since the database is detached, it will be inaccessible for any transactions, ensuring that no data will be committed on the old system during the upgrade. Detaching the database also helps to validate that all the connections have been reconfigured to point to the new system.
We can use the sp_detach_db stored procedure to detach a database. We should also set the database to single-user mode and immediately roll back any transactions before trying to detach the database.

T-SQL Script to Detach a Database:

USE [master]
GO
ALTER DATABASE [DatabaseName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
EXEC master.dbo.sp_detach_db ‘DatabaseName’
GO

To attach a database in SQL Server Latest Version, we should use the CREATE DATABASE statement with the FOR ATTACH clause. This statement and clause replace the sp_attach_db stored procedure that was previously used to attach a database. The sp_attach_db stored procedure has been deprecated and will be removed in a future release. We will also need to specify the locations of the data files that are going to be attached.

T-SQL Script to Attach a Database:

USE [master]
GO
CREATE DATABASE [DatabaseName] ON
( FILENAME = N’C:\MSSQL\DATA\DatabaseName.mdf’ ),
( FILENAME = N’C:\MSSQL\DATA\DatabaseName_log.ldf’ )
FOR ATTACH
GO

We can detach and attach databases using the GUI in SQL Server Management Studio.
To detach a database using the GUI, we can right-click on the database we want to detach, select Tasks, and then select Detach from the context menu. This will bring up the Detach Databases screen. Select OK to detach the database.
To attach a database using the GUI, we can right-click on the Databases folder and select Attach from the context menu. This will bring us to the Attach Databases screen. Selecting Add will bring up the Locate Database Files screen, which will allow us to navigate to the data file we would like to attach. Once we have selected the data file, select OK to close the Locate Database Files screen and OK once again on the Attach Databases screen to close the screen and attach the database.

Note : Above are not only the methods to migrate database\Instance, its all based on Databases Size\Client Requirement\Downtime …etc.,

There so many other Methods to migrate the Databases like we can configure High Availability(Logshipping,Mirroring,Replication,AlwaysON) ,backpac, Import and Export, SSMA tool ..etc.,

As I said it all depends on Environment and discussion having with Client.

And the Latest one which I come to know when searching for Migration on Internet is DBATOOLS , its a Awesome way to migrate the Databases or Entire Instance very quick and easy method using Powershell.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.