Tuesday, August 12, 2008

Moving Site Collections from Content Databases

Don't be surprised if after running SharePoint for some time you find yourself having to move site collections to new content databases. Maybe one or more of your content databases are experiencing greater growth than you originally anticipated, or you only have one Content Database and would like to logically group your site collections into multiple. Whatever the case may be STSADM includes an operation that allows you to move all or a specified subset of site collections from one content database to another. The operation is MergeContentDBs and was introduced in Microsoft Office SharePoint Server 2007 Service Pack 1.

Creating a New Content Database

If you are moving the Site Collection(s) to an existing content database you may skip this section; keep in mind that the target content database must be associated with the same web application as the source content database. If you need to create a new Content Database to move your Site Collection(s) into follow these steps:

  1. Start the SharePoint Central Administration Web site.

  2. On the Application Management page, in the SharePoint Web Application Management section, click Content databases.

  3. On the Manage Content Databases page, click Add a content database.

  4. On the Add Content Database page:

    1. Select a Web application for the new database.

    2. Select a database server to host the new database.

    3. Specify the authentication method the new database will use and supply an account name and password if necessary.

    4. Specify both the total number of top-level sites that can be created in the database and the number at which a warning will be issued.

  5. Click OK.

Moving all the Site Collections to a Different Content Database (Merging Content Databases)

If you are moving ALL of your Site Collections from one content database to another follow these steps, otherwise skip this section

  1. Run the following stsadm command:
    Stsadm -o mergecontentdbs -url <URL> -sourcedatabasename <database name> -destinationdatabasename <destination database name> -operation 2

  2. where <URL> is the address of the Web application that contains the site collection that you want; <database name> is the name of the database that you want to move the site collection from; and <destination database name> is the name of the database that you want to move the site collection to; operation 2 is the “Full Database Merge” operation.

    (Example: stsadm -o mergecontentdbs -url http://localhost -sourcedatabasename WSS_Content 
    -destinationdatabasename  WSS_Content2 -operation 2)

  3. Restart IIS by typing the following command, and then pressing ENTER:
    iisreset /noforce.

     

Moving Specific Sites to a Different Content Database (Splitting Content Databases)

If you are moving specific site collections from one content database to another follow these steps:

  1. Run the following stsadm command, to get a list of all the sites in your web application

    Stsadm -o enumsites -url <URL> > <path/file name>.xml

    where <URL> is the address of the Web application that contains the site collection that you want to move, and <path/file name> is the name of the XML file that you want to create with the site collection data.

    (Example: stsadm -o enumsites -url http://localhost > c:\Sites.XML)

  2. Open the XML file that you created in a text editing application. If there are any URLs for site collections that you do not want to move, be sure to delete them from the file. The only URLs that should remain in the XML file should be for the site collections that you want to move.

    Note:
    There is no need to change the site count or any of the other site collection information in the file. Only the URLs are relevant to this procedure.

  3. Run the following stsadm command:
    Stsadm -o mergecontentdbs -url <URL> -sourcedatabasename <database name> -destinationdatabasename <destination database name> -operation 3 -filename <file name>

    where <URL> is the address of the Web application that contains the site collection that you want; <database name> is the name of the database that you want to move the site collection from; and <destination database name> is the name of the database that you want to move the site collection to; operation 3 is the “Read from file” operation; and <file name> is the name of the file that you created in step 4.

    (Example: stsadm -o mergecontentdbs -url http://localhost -sourcedatabasename WSS_Content 
    -destinationdatabasename  WSS_Content2 -operation 3 -filename c:\Sites.xml)

    Note: This step assumes that all of the sites in the Sites.xml file where in the source database name. If the sites are located in multiple databases you may need to repeat these steps for each source Content Database.

  4. Restart IIS by typing the following command, and then pressing ENTER:
    iisreset /noforce.


For more information reference the TechNet Articles:
Add, split, and merge content databases (Office SharePoint Server 2007)
Mergecontentdbs: Stsadm operation (Office SharePoint Server)

 

4 comments:

Anonymous said...

Thank you for this post...it was very clear and to the point. Worked great!! Keep up the good work!!

Rafelo said...

Thanks for the feedback. Glad I could be of help.

Douglas Hamilton said...

Thanks! Exactly what I was looking for.

Tim said...

Great article, I used it with succes!