Published on

April 26, 2016

Migrating SQL Server Databases to a New Drive

During a recent project, I was tasked with moving SQL Server databases from one drive to another. In this case, the databases were located on the H drive, and we needed to migrate them to the J drive. Since this was a clustered instance, we had to consider the dependencies as well. Here are the steps we followed to successfully migrate the clustered disks:

  1. First, we needed to alter all databases (except for the master database) to change the drive letter to J. We used the following commands to modify the system database metadata:
USE master;
GO
ALTER DATABASE tempdb MODIFY FILE (
	NAME = tempdev,
	FILENAME = N'J:\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\tempdb.mdf'
);
GO
ALTER DATABASE tempdb MODIFY FILE (
	NAME = templog,
	FILENAME = N'J:\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\templog.ldf'
);
GO

ALTER DATABASE model MODIFY FILE (
	NAME = modeldev,
	FILENAME = N'J:\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\model.mdf'
);
GO
ALTER DATABASE model MODIFY FILE (
	NAME = modellog,
	FILENAME = N'J:\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\modellog.ldf'
);
GO

ALTER DATABASE msdb MODIFY FILE (
	NAME = msdbdata,
	FILENAME = N'J:\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\msdbdata.mdf'
);
GO
ALTER DATABASE msdb MODIFY FILE (
	NAME = msdblog,
	FILENAME = N'J:\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\msdblog.ldf'
);
	
  1. We then needed to update the registry key on both nodes of the cluster. The key is located at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server. We searched for all references to the old drive letter (H) and changed them to the new drive letter (J).
  2. Next, we updated the startup parameters in SQL Server Configuration Manager to reflect the new path for the master database files.
  3. We took the SQL Server offline, but left the clustered disk resources online.
  4. We copied all the files from the old disk (H drive) to the new disk (J drive).
  5. We then changed the SQL Server group dependencies so that the SQL Server service was dependent on each disk resource.
  6. Finally, we removed the old disks from the resource group and brought the SQL resource online.
  7. To ensure everything was working correctly, we performed failover and failback tests.

These steps allowed us to successfully migrate the SQL Server databases from the H drive to the J drive. It’s important to note that the specific commands may vary depending on your server settings, so be sure to adjust them accordingly.

If you have any questions or think something is missing from these steps, please feel free to leave a comment below!

Click to rate this post!
[Total: 0 Average: 0]

Let's work together

Send us a message or book free introductory meeting with us using button below.