OCS 2007 Backup Script

One of the more useful items from the OCS 2007 Resource Kit book was the extras disc that contained a few Excel worksheets on setting up backups for different types of servers. Using those worksheets I created a script that automates some of the backup process for a standard edition server. I tried to make the script fairly configurable as far as file locations and naming conventions, but feel free to change it to suit your needs. What happens is this:

  • A SQL backup job script is created with options for a full backup that overwrites the previous one.
  • A scheduled task is created that backs up the global and pool-level settings for OCS.
  • A scheduled task is created that backs up the machine-level settings for OCS.
  • A scheduled task is created that runs the SQL backup job script.

All of the files from these tasks are dumped into a single folder of your choosing on a nightly basis. At that point you can do what you like with the contents. You could schedule your backup program to simply pick up this folder on a regular schedule or you could create another scheduled task that copies the folder to a file share on another machine. Just make sure you’re saving that folder collection somewhere else and you should be fine.

There is one manual change you must make before the SQL backup job can run successfully. You need to enable TCP/IP connections to the SQL Express instance and change the port back to the default. To do that, perform these steps:

  1. Install SQL Server Management Studio Express.
  2. Open Start | Programs | MS SQL Server 2005 | Configuration Tools | SQL Server Configuration Manager.
  3. Expand SQL Server 2005 Network Configuration | Protocols for RTC.
  4. Right-click TCP/IP and choose Enable.
    sql1
  5. Right-click TCP/IP | Properties and change the TCP Dynamic Ports value to 1433.
    sql2 
  6. Restart the SQl Server (RTC) service and you should be all set.

To use the script just rename the link to a .vbs and execute it. A few things to keep in mind:

  • Run the script as a user who is both a member of RTCUniversalAdmins and in the local administrators group on the machine.
  • You’ll be prompted for your password 3 times, once for each scheduled task.
  • Make sure you manually run the tasks a few times make sure they work properly.
  • Read the comments in the script – I tried to be detailed and make it easy to follow if you need to change something.

OCS Standard Edition Backup Script 

‘———————————————-
‘ Edit these values
‘———————————————-

‘ Backup folder – this is directory the files are saved to. Do
‘ NOT use a trailing backslash. You MUST create the folder
‘ before running the script.
strBackupFolder = "C:\OCS 2007 Configuration"

‘ Global & Pool Level File Name – this is the file name of the
‘ XML used for storing global and pool level settings
strGlobalPoolLevelFileName = "ocs-2007-global-pool-settings.xml"

‘ Global & Pool Level File Name – this is the file name of the
‘ XML used for storing machine level settings. By default it
‘ includes the machine name.
strMachineLevelFileName = "ocs-2007-machine-settings.xml"

‘ Global & Pool Level Task Name
strGlobalPoolTaskName = "OCS 2007 – Global and Pool Level Settings Backup"

‘ Global & Pool Level Task Start Time
strGlobalPoolTaskStart = "04:00"

‘ Machine Level Task Name
strMachineTaskName = "OCS 2007 – Machine Level Settings Backup"

‘ Machine Level Task Start Time
strMachineTaskStart = "04:05"

‘ SQL Backup Task Name
strSQLBackupTaskName = "OCS 2007 – Database Backup"

‘ SQL Backup Start Time
strSQLBackupTaskStart = "04:10"

‘ SQL Backup Script Name
strSQLBackupScriptName = "ocs-backup-job.sql"

‘ SQL Backup File Name
strSQLBackupFileName = "rtc-full.bak"

‘———————————————-
‘ You can probably leave this section alone
‘———————————————-

set objFSO = CreateObject ("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("" & strBackupFolder & "\" & strSQLBackupScriptName & "",True)
objFile.WriteLine("BACKUP DATABASE [rtc] TO  DISK = N’" & strBackupFolder & "\" & strSQLBackupFileName & "’ WITH NOFORMAT, INIT,  NAME = N’rtc-Full Database Backup’, SKIP, NOREWIND, NOUNLOAD,  STATS = 10")
objFile.WriteLine("Go")
objFile.Close

‘Create an array of OCS Pools
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOCSPools = objWMIService.ExecQuery("Select * from MSFT_SIPPoolSetting")

‘Get name of OCS pool
For Each objOCSPool in colOCSPools
  strOCSPool = objOCSPool.pooldisplayname
Next

‘Create task for global and pool settings backup
Set objShell = WScript.CreateObject("WScript.Shell")
taskParameters = "/create /sc daily /st " & strGlobalPoolTaskStart & " /tr ""\""%programfiles%\Common Files\Microsoft Office Communications Server 2007\LCSCmd.exe\""/config /action:export /level:global,pool /configfile:\""" & strBackupFolder & "\" & strGlobalPoolLevelFileName & "\"" /poolname:" & strOCSPool & """ /TN """ & strGlobalPoolTaskName &""""
objShell.Run "schtasks.exe " & taskParameters

‘Create task for machine settings backup
taskParameters = "/create /sc daily /st " & strMachineTaskStart & " /tr ""\""%programfiles%\Common Files\Microsoft Office Communications Server 2007\LCSCmd.exe\""/config /action:export /level:machine /configfile:\""" & strBackupFolder & "\" & strMachineLevelFileName & "\"" /poolname:" & strOCSPool & """ /TN """ & strMachineTaskName &""""
objShell.Run "schtasks.exe " & taskParameters

‘Create task for SQL backup
taskParameters = "/create /sc daily /st " & strSQLBackupTaskStart & " /tr ""sqlcmd.exe -e -s .\RTC -i \""" & strBackupFolder & "\" & strSQLBackupScriptName & "\"""" /TN """ & strSQLBackupTaskName &""""
objShell.Run "schtasks.exe " & taskParameters

Here

Recent content I've written for you—just for you!— to enjoy while you're here.

There

Quick commentary and links to other sources you'll find interesting. I promise.

Everywhere

Some personal background, links to related projects, and other ways to connect.

Hi there. My name is Tom Pacyk and this is my small home on the web. I love the intersection of design, technology, and communication, which is a combination that led me to a career in sales and marketing roles at places like Zoom and ServiceNow. They're a bit old now, but I also had the opportunity to publish a couple of books along the way.

Portland, Oregon is home for me, my wife Beth, and our three kids, but I'm actually a Midwestern transplant—I grew up in the Chicago suburbs and went to school at Purdue and Illinois. When I find some free time I'm probably going to concerts, rooting for the Portland Timbers, or working on my Sunshine Burn Photography project.