Thursday, July 25, 2013

Moving SharePoint Content Databases

We have a large (30GB) site collection which needs to move from one drive to the next.
This must be done first in SQL and then using stsadm.

Here are the steps moving the content on the same server drive to drive:

1.) Open SQL Server Management Studio.
2.) Take the content database offline
3.) Physically move the mdf and ldf files from the old drive to the new drive
4.) Now execute this script against master database.
ALTER DATABASE MyDB MODIFY FILE (NAME = PrimaryData, NEWNAME = MyDB );
ALTER DATABASE MyDB MODIFY FILE (NAME = PrimaryData_log, NEWNAME = MyDB _log);
GO

ALTER DATABASE MyDB SET OFFLINE;
GO
-- Physically move the file to a new location.
-- In the following statement, modify the path specified in FILENAME to
-- the new location of the file on your server.
ALTER DATABASE MyDB
MODIFY FILE ( NAME = MyDB_log,
FILENAME = 'F:\MSSQL.1\MSSQL\Data\MyDB _Log.ldf');
GO
ALTER DATABASE MyDB
MODIFY FILE ( NAME = MyDB,
FILENAME = 'F:\MSSQL.1\MSSQL\Data\MyDB.mdf');
GO
ALTER DATABASE MyDB SET ONLINE;
GO

--Verify the new location.
SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys.master_files
WHERE database_id = DB_ID(N'MyDB')
--AND type_desc = N'LOG';
(http://www.sqlservercentral.com/Forums/Topic1341567-1550-1.aspx)

5.) Ensure that the new location has the correct permissions.
The users:
OWNER RIGHTS, SQLServerMSSQLUser must have Full Control
6.) Bring the Database online by using command line
ALTER DATABASE MyDB SET ONLINE;
7.) Central Admin > Application Management > Manage Content Databases
8.) Click Database Name
9.) Database status to ready > OK

--If you want to move it to a new server then
10) Use Stsadm
--Detach from the old SQL server instance
stsadm –o deletecontentdb –url http://yoursiteurl –databasename your_content_db –databaseserver source_SQL_server
--Attach to new SQL server instance
stsadm –o addcontentdb –url http://yoursiteurl –databasename your_content_db –databaseserver target_SQL_server
Move SharePoint Configuration Database

No comments:

Post a Comment