Wednesday, June 2, 2010

Sharepoint Powershell: Finding and configuring databases to be configured as failover in Sharepoint.

First, I need to take a second to be an over the top fangirl about how great the failover mirroring is in sharepoint 2010 w/sql 2008 (R2 in our case). Beautiful, amazing, etc. Lightning fast failover not just from the DB side, but from the app side. We're only running a small test farm (compared to our much larger production infrastructure), and we haven't done serious load testing yet (so I hope I won't come back disappointed in a couple of weeks). But seriously, just in our "I hard crash the SQL server while our SharePoint administrator messes around adding items/clicking around" we're seeing one dropped request and no data loss (obviously you can't take messing around testing to the bank). It's synchronous mirroring so I suppose it would be shocking if it did lose data but still, so nice. Way faster failover than anything I've seen on SQL and since we don't have RAC, faster than I've ever seen Oracle failover either. Just gorgeous. Really, I'm not doing it justice. It's so pretty I want to buy it things.

Configuration of failover mirroring from the sql side is standard synchronous with witness. Initial SharePoint configuration is easy with the powershell interface. There's a lot of great articles out there. This technet article publishes the script.

You can run the following command to get the list of databases and their failover servers but if you have a whole bunch of content databases it's easy to miss, or misidentify one.
"get-spdatabase | select name, failoverserver"

Again, cribbed from the technet script for configuring database mirroring the first time is here. My hacking of the meat of the script to check for and configure unconfigured databases is below.


Param([string]$FailoverInstance = $(Read-Host "Enter the Mirror (Partner) SQL Instance(like server\instance)"))
get-spserviceinstance -all | foreach-object {
if ($_.typeName -eq "Microsoft SharePoint Foundation Database")
{
foreach ($Database in $_.Databases){
if ($Database.FailoverServer -eq $null) {
write-host "Found unconfigured database -- setting failover instance to " $Database.Name "to" $FailoverInstance
$Database.AddFailoverServiceInstance($FailoverInstance)
$Database.Update()
write-host "Successfully Updated Failover Partner on" $Database.Name "to" $FailoverInstance

}
else {
write-host $Database.Name "already configured."}
}
}
}



2 comments:

  1. This post is worthy of appreciation, looking forward to more exciting! armani horloges outlet

    ReplyDelete
  2. Wow, perfect. Fortunately, I found your website!
    Thanks for sharing!Armani Exchange NL

    ReplyDelete