Orphaned Objects are items that do not have any
parent or child relationship and remain in the content database uncleaned. When
you perform the Test-SPContentDatabase to validate a content database you
might receive errors which provides information about orphans in the content
database
These orphaned objects need to be removed on the below
situations:
1. Before
applying service packs or cumulative updates to the SharePoint servers
2. Before
performing a migration from a older version of SharePoint to a newer version.
3. Before
reapplying templates or performing any updates to the database.(certain
powershell commands would not work when running update scripts on the database.
ex. Applying modification to a Custom Master Page that is already
deployed to the sites). The execution of powershell scripts will fail when
iterating the tables for fetching or applying update to the data in SharePoint
content databases
There are 2 types of Orphan Objects
1. Config
Orphans (Orphan Site exist in
Configuration Database but does not have any child item in Content Database).
Central Admin ->View All Site Collections shows the site info, but the
actual site cannot be accessed via browser.
2. Content Orphans (Orphans include Lists
without Parent sites, Documents with no parent document library, Web Parts that
does not have an assembly, Web Pages with no Parent Site E.t.c..). Site
Collections that are available in content database but not in config db (Will
not show in Central Admin -> View All Site Collections page)
A.
Config
Orphan Object Removal:
Cleaning the config orphan is the easiest one.
Simply detach the content database that has the orphan site
from your farm and attach it back. This will refresh and remove the stale
entries.
B.
Content
Orphan Object Removal
There are 2 ways to remove content orphans from the content
database
1. Use SharePoint
Health Analyzer
2. Use STSADM or
PowerShell Commands
1.
SharePoint
Health Analyzer
(Note : Not recommended in a
Production farm as it sometimes might cause SQL Blocking if there are very
large content databases)
Go to Central Admin - > Monitoring > Health Analyzer
Section > Review Problems and Solutions > Content Database Contain
Orphaned Items - Click on the Ribbon Command "Repair Automatically".
2.
Using
STSADM Commands
I have provided two scripts to first log the orphans in text
file.(STSADM Method)
When you execute the first script, this will list out the
orphaned objects in text file
The second one will delete the orphans.
This method will delete only when you have orphan sites in
one content database.
Modify the site collection name and database name related to
the STSADM command line.
To
Check Orphans (Store the below content in a .Bat file)
echo on
rem *** set local environment variables
setlocal
set LogFile="D:\LogOrphans.txt"
c:
cd "\Program Files\Common Files\Microsoft Shared\Web
Server Extensions\14\BIN" >> %LogFile%
Echo "List Orphans ...." >> %LogFile%
stsadm.exe -o databaserepair -url https://contoso.com/sites/sitecollection
-databasename Content10_ContentDB >> %LogFile%
Echo "************** E N D*********" >>
%LogFile%
pause
PowerShell
Command to check orphans:
$contentdb
= Get-SPContentDatabase | Where-Object {$_.Name –match
"Content_Contentdb"}
test-spcontentdatabase
$contentdb -showrowcounts | Format-Table -Wrap | Out-File -FilePath
c:\testcontent.txt
To
Delete Orphans(Store the below content in a .Bat file):
echo on
rem *** set local environment variables
setlocal
set LogFile="D:\LogOrphans.txt"
c:
cd "\Program Files\Common Files\Microsoft Shared\Web
Server Extensions\14\BIN" >> %LogFile%
Echo "List Orphans ...." >> %LogFile%
stsadm.exe -o databaserepair -url https://contoso.com/sites/sitecollection
-databasename Content10_ContentDB -deletecorruption >> %LogFile%
Echo "************** E N D*********" >>
%LogFile%
pause
The
Ouput in log File below:
"List Orphans ...."
"************** E N D*********"
Note:
In some scenarios certain orphan object might not get
removed, but still show that it is removed and will remain in the
database.
To validate this, run the below command to list the objects
in the content database and cross verify with the log files
stsadm -o
enumallwebs -databasename Content10_ContentDB
Output of the
above Stsadm command
If the property InSiteMap=False then the
site collection is an orphan.
Final
Validation:
If you still have the orphaned objects listed, then try the
below options and then validate again with the log file
1. Disconnect the database and reconnect the database so that
the references will be removed.
2. Try removing the corrupted list or item using the
sharepoint designer tool.
3. Try deleting the site using below Stsadm commands
stsadm -o
deletesite -force -url http://contoso.com/sites/contososubsite11 -databaseserver ds -databasename contentdb1
(or)
stsadm
-o deletesite -force -siteid e2a114b8-80c9-41f6-87bf-3feddf2ad9b6 -databaseserver ds -databasename
contentdb1
4. Try
running the below Powershell commands
(Get-SPContentDatabase ).Repair($true)
Ex:
(Get-SPContentDatabase Collab_ContentDB).Repair($true)
No comments:
Post a Comment