When preparing to upgrade SharePoint 2007 to 2010 you will need to run the pre-upgrade scan tool include with SharePoint 2007 SP2 as in the article http://technet.microsoft.com/en-us/library/cc262231.aspx. When completed, you may see upgrade scan failures for orphaned site collections such as the one below.
Removing these orphaned sites is important for a clean migration.
There are two basic types of orphaned sites; Configuration Database and Content Database orphans. Configuration orphans are listed in the Configuration database but have no corresponding site in any Content database in your farm. Content orphans may be sites that are not listed in the configuration database or the data in the configuration database has become corrupted. For instance, there may be duplicate sites listed.
Cory Burns has written a terrific article which describes orphans in detail (SharePoint Orphans Explained) and also provides a SQL script for identifying and determining the type of orphan.
Fixing Configuration orphans is fairly straightforward. By detaching and re-attaching the content database with the orphaned site, you can refresh the Configuration information.
Content orphans are more difficult and there are two methods to try.
First, try using the stsadm database repair command detailed in http://technet.microsoft.com/en-us/library/cc288636.aspx
Example: stsadm -o databaserepair -url <web app url> -databasename WSS_Content_MOSS_01
Use it with the –deletecorruption param to clean up problems.
This is the easiest, but it doesn’t always find or fix everything – especially duplicates. Fortunately SP2 provides some new commands which can help.
With the orphans found by the Preupgrade scan, we can see the content database of the orphan.
Running run the enumallwebs command (stsadm -o enumallwebs -databasename WSS_Content_MOSS_01) shows us two sites with the same URL. I can see that the second site is not listed in the Site Map (config db).
<Site Id="bde1a85e-5f7e-462f-bcf9-f18ca1674730" OwnerLogin="WIN-B34GDFGEY6Xmoss" InSiteMap="True">
<Webs Count="1">
<Web Id="9dd15537-ed26-46eb-81cf-817cefc3a811" Url="/sites/CaptureConfiguration" LanguageId="1033" TemplateName="S
TS#0" TemplateId="1" />
</Webs>
</Site>
<Site Id="2ddf2957-4ec6-4866-8711-fae1eee84d2f" OwnerLogin="WIN-B34GDFGEY6Xmoss" InSiteMap="False">
<Webs Count="1">
<Web Id="b1929e04-6d56-487e-88d8-10b120f0b254" Url="/sites/CaptureConfiguration" LanguageId="1033" />
</Webs>
</Site>
</Sites>
Now I can force the a site deletion with the new –force param of stsadm –o deleteweb, passing the webid identified by enumallwebs.
Example: stsadm -o deleteweb -force -webid b1929e04-6d56-487e-88d8-10b120f0b254 -databasename WSS_Content_MOSS_01 -databaseserver WIN-B34GDFGEY6X
This will force the removal of the orphaned site.