Quantcast
Channel: automation – The SharePoint Redneck
Viewing all articles
Browse latest Browse all 3

Create mount/dismount database scripts

$
0
0

One of the architectures I use for some of the farms in my care is a disaster recovery model where I have 2 farms in 2 data centers.  One farm is actively serving content while the other is a mirror copy of the farm with no content databases attached.  I will talk through the various architectures I use in a future post, but this particular one works well for those users who require instant live content and can’t use the publishing methodologies.  We use SQL mirroring to keep the content databases in sync.  If I have an event that requires me to flip to the other data center, I have the DBAs flip the mirrors or possibly break the mirrors if a real disaster has occurred.  Then the network guys flip the traffic to the other side and we are up and running.

Just one problem to this is that mirroring is one way so only 1 side can be live and only 1 farm can have content attached.  This means that before I can have the data flipped, I have to dismount all the databases from the primary farm, flip the mirrors and attach on the other side.  In most farms, this is probably 5-10 databases and is no big deal.  For some of my farms, I have 150+ databases on the farm spread across multiple web applications.  As such, it isn’t an easy thing to dismount and remount databases.  This is why I had to automate the process.

The script we are talking about today actually creates 2 additional scripts: one to mount and another to dismount.  The script is actually pretty simple and if it performs as expected will create both the mount and dismount scripts that you will use.  In my process, I create these files and copy both to the other farm.  I then run the dismount script on the primary farm, have the DBAs and network guys flip everything to the other data center and then run the mount script there.  If I built everything properly, the farms use the same URLs and such and everything is seamless.  It takes 30 seconds to 3 minutes per database depending on size of the database, so plan for that.

In my next post I will discuss performing mass database upgrades when applying service packs and cumulative updates.

#Variables that you can change to fit your environment
$DMFile = "Dismount.ps1"
$MFile = "Mount.ps1"

#Get all web apps
$webapps = Get-SPWebApplication
#Loop through the web apps
foreach($webapp in $webapps)
{
    #Get the content databases in this web app
    $ContentDatabases = $webapp.ContentDatabases

    #Add a comment to the mount and dismount files saying which web app is affected
    Add-Content -Path $DMFile -Value "#Content databases for $($webapp.url)"
    Add-Content -Path $MFile -Value "#Content databases for $($webapp.url)"

    #Loop through the content databases
    foreach($ContentDatabase in $ContentDatabases)
    {
        #Add the appropriate PowerShell command to the right file
        Add-Content -Path $DMFile -Value "Dismount-SPContentDatabase $($ContentDatabase.Name) -Confirm:`$False"
        Add-Content -Path $MFile -Value "Mount-SPContentDatabase $($ContentDatabase.Name) -WebApplication $($webapp.url) -Confirm:`$False"
    }
}



Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles



Latest Images