Recipe 6.9. Moving Databases and Logs to Different DisksProblemYou want to relocate the files for a database, or the transaction logs for a storage group, from one disk volume to another. SolutionUsing a graphical user interfaceTo move the EDB and/or STM files in a database, do the following:
To move a storage group's logs to another volume, do the following:
Using VBScriptTo move a database to another path, use this code: ' This code moves database files to the specified path. ' The database is dismounted and remounted as necessary. ' ------ SCRIPT CONFIGURATION ------ strServerName = "<serverName>" ' e.g., "BATMAN" strMDBName = "<dbName>" ' e.g., "Mailbox Database (SpiffyDatabaseName)" strNewPath = "<fullPath>" ' e.g., "c:\temp\" ' ------ END CONFIGURATION --------- Set theServer = CreateObject("CDOEXM.ExchangeServer") Set theMDB = CreateObject("CDOEXM.MailboxStoreDB") theServer.DataSource.Open strServerName arrSG = theServer.StorageGroups theFirstSG = arrSG(0) strURL = "LDAP://" & theServer.DirectoryServer & "/cn=" & strMDBName & "," & theFirstSG theMDB.DataSource.Open strURL ' dismount the database before attempting to move it If (theMDB.Status= 0) then theMDB.Dismount End If ' move the DB to the specified path, then remount it theMDB.MoveDataFiles strNewPath & strMDBName & ".edb", strNewPath & strMDBName & ".stm" theMDB.Mount WScript.Echo "Database moved to " & strNewPath & " and remounted." If you want to move transaction logs for a storage group without touching the databases, use this code: ' This code moves transaction logs for the first storage group ' to the specified location ' ------ SCRIPT CONFIGURATION ------ strServerName = "<serverName>" ' e.g., "BATMAN" strNewPath = "<fullPath>" ' e.g., "c:\temp\" ' ------ END CONFIGURATION --------- Set theServer = CreateObject("CDOEXM.ExchangeServer") Set theSG = CreateObject("CDOEXM.StorageGroup") theServer.DataSource.Open strServerName arrSG = theServer.StorageGroups theFirstSG = arrSG(0) strURL = "LDAP://" & theServer.DirectoryServer & "/" & theFirstSG theSG.DataSource.Open strURL ' move the log files to the specified path; this dismounts and remounts ' all of the SG's databases theSG.MoveLogFiles strNewPath WScript.Echo "Moved logs for SG " & theFirstSG & "to " & strNewPath DiscussionFor best performance and recoverability, you should keep your Exchange transaction logs on a different physical disk or array than the Exchange database files. This gives the ability to have up-to-date logs to play back in the event of a database drive failure, allowing administrators to restore to the point of failure. The Exchange 5.5 Performance Wizard would attempt to figure out which disks to put its database (singular) and log files on, but Exchange 2000 and later dump everything in \program files\exchsrvr\mdbdata. You can, and should, relocate your databases and log files to enhance performance and recoverability. However, before you can move a database, it has to be dismounted; and before you can move the log files for a storage group, you'll have to dismount all of its databases. The scripts for this recipe use the CDOEXM interfaces for the MailboxStoreDB and StorageGroup objects to move databases and transaction logs. In both cases, the first SG's URL is used as the basis for constructing the URL to the target SG or database. The database moving script dismounts the database if it's mounted when the script is run, and mounts it after the move, because you cannot move a mounted database. See AlsoMS KB 821915 (How to Move Exchange Databases and Logs in Exchange Server 2003), MS KB 257184 (XADM: How to Move Exchange Databases and Logs in Exchange 2000 Server), and Exchange Server 2003 Performance and Scalability Guide (available from the Microsoft web site at http://www.microsoft.com/technet/prodtechnol/exchange/2003/library/perfscalguide.mspx) |