Archive for January 2009
Mirroring script for SQL Server / Sharepoint
http://spadmin.spaces.live.com/blog/cns!F030C52B8E5517C3!352.entry
I was working in one of my SharePoint test labs this weekend, and decided to write a script that would recycle, stop or start all of the SharePoint Key services. Copy the text and save it as ManageServices.bat
Enjoy
@ECHO OFF
:CHOICE
CLS
ECHO.
ECHO **********************************************************************
ECHO.
ECHO ** Recycle, Stop, Start SharePoint Key Services
ECHO.
ECHO ** Created April 23 2008
ECHO ** Gene Magerr
ECHO ** genemagerr@hotmail.com
ECHO ** Version 1.0 – April 23 2008
ECHO ** 1.1 -
ECHO ** 1.2 -
ECHO **
ECHO **
ECHO ** You have a royalty-free right to use, modify, reproduce, and
ECHO ** distribute this script file in any way you find useful, provided that
ECHO ** you agree that the creator, owner above has no warranty, obligations,
ECHO ** or liability for such use.
ECHO.
ECHO ** This batch file will Recycle, Stop or Start all of the key
ECHO ** SharePoint 2007 services. It will also do an IISRESET /NOFORCE
ECHO ** after each of the tasks.
ECHO.
ECHO **********************************************************************
ECHO.
ECHO Please choose a menu option.
ECHO.
ECHO Recycle all services …………………. 1
ECHO Stop all services ……………………. 2
ECHO Start all services …………………… 3
ECHO Quit (without affecting services) ……… 4
ECHO.
CHOICE /C:1234 /N /T:180 /D:4
ECHO.
IF ERRORLEVEL == 4 GOTO END
IF ERRORLEVEL == 3 GOTO START
IF ERRORLEVEL == 2 GOTO STOP
IF ERRORLEVEL == 1 GOTO RECYCLE
:RECYCLE
ECHO Stopping and restarting key services
ECHO.
net stop oSearch
net stop SPAdmin
net stop SPTimerv3
net stop SPTrace
net start oSearch
net start SPAdmin
net start SPTimerv3
net start SPTrace
PING 1.1.1.1 -n 1 -w 2000 >NUL
ECHO Recycling IIS
ECHO.
IISRESET /NOFORCE
PAUSE
GOTO CHOICE
:STOP
ECHO Stopping key services
ECHO.
net stop oSearch
net stop SPAdmin
net stop SPTimerv3
net stop SPTrace
PING 1.1.1.1 -n 1 -w 2000 >NUL
ECHO Stopping IIS
ECHO.
IISRESET /STOP
PAUSE
GOTO CHOICE
:START
ECHO Starting key services
net start oSearch
net start SPAdmin
net start SPTimerv3
net start SPTrace
PING 1.1.1.1 -n 1 -w 2000 >NUL
ECHO Starting IIS
ECHO.
IISRESET /START
PAUSE
GOTO CHOICE
:END
Using SQL Alias for failover with Sharepoint (SPS 2007)
SPS 2007 does not have any support for automatic failover to the mirror server.
Microsoft suggested using a SQL Alias or the following approach:
The approach for failover is
Ø If the SQL server falls over, use the stsadm command RenameServer to change the db server name, then stop & restart IIS & the timer service.
Ø If a single db other than configdb falls over, detach & reattach the db using the UI or via stsadm commands.
Ø If configdb falls over, the admin must use PSConfig.exe’s configdb command, or the renameserver command. If they use the latter, they’ll have to detach & reattach the other db’s on the same server, to move those back to their original sql server location.
The above approach seemed to be pretty complicated so I decided to use the SQL Alias approach and have written a windows service to monitor the things, here is an overview of the process:
* using cliconfg.exe, create an alias on each SharePoint server in the farm with a name of the currently configured SQL Server that SharePoint is pointed to. Set the value of the alias to the same server name. Example, if SharePoint is using server1 as the database server, create an alias called server1 and set the value of the alias to server1.
o the cliconfg.exe creates a registry value called server1 with the name of the alias in the following key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo
The data for the server1 value will be DBMSSOCN,server1
* My service periodically queries the database_mirroring_witnesses catalog of the witness server to see what the principal server is for the SharePoint_Config database. This object resides in the master database. Once you query this catalog there is a column that has the current principal server information.
* Remotely query the registries of all the SharePoint servers in the farm to see what database server the SQL alias created above is pointing to. If the alias is pointed at a different server than what the witness server thinks is the principal, remotely update the alias’s value in the registry and run IISRESET.exe /noforce.
The account that runs my service needed to have select access to the databse_mirroring_witnesses catalog on the Witness server.
Also, since I am only querying the witness server to see what the principal server is for the SharePoint_Config database, I am assuming that if this database fails over to the mirror, all the databases have failed over and I am redirecting SharePoint via the alias on all SharePoint servers in the farm.
** I took this from a comment on some site for my own permanent reference **