Blog

SCOM 2007: Automated Backup of Unsealed Management packs

As part of my series how to back up your SCOM environment I ‘ve created a backup strategy for my unsealed management packs.

The setup I choose is to use a PowerShell script with error handling included which is run by the Task Scheduler on the RMS and monitored by a management pack in SCOM.

The advantages of this setup are:

  • No additional load on the RMS (although this script is light you never know what will happen)
  • Better control over when the script is running.

The PowerShell script I used is based on the UnsealedMPbackup management pack which is posted here: https://skydrive.live.com/?cid=397bb61b75cc76c5&id=397BB61B75CC76C5%21217#

Although this is an excellent script I modified it to have Error handling in there. If you look at the script there’s also a mailer included in the script but it’s commented out for now. If you would like to use this as a standalone script without the monitoring of SCOM over the process you can easily switch on the email function and be alerted when things went wrong.

This script will:

  • Create a folder with the date of today in a root folder you define
  • export all unsealed management packs to this folder
  • Delete folders which are older than 15 days.

The script:

The parameters you will need to fill in are marked in yellow.

You can download the PowerShell script here.

Section 1:

  • Reading out the parameters which will be used through the script:
    • RMS: A simple $rootMS = ‘Local host’ would do the trick as well but I like a WMI approach so added that in. The WMI approach will not work if you use it on a clustered environment. In this case it’s best to just add the name of the cluster hardcoded in the script.
  • Initializing the ops MGR 2007 snap in: Just loading the necessary cmdlets.
  • Set Culture Info: In my case this is Dutch Belgium. This is important for the date format so please don’t forget to change it as you please.
  • Error handling Setup: Defining the error handling for further use in the script.

scom_backup_unsealedMP0000

Section 2

In this section we are actually defining the location and exporting the management packs:

Define the backup location:

  • Get Date: Here we are reading the system date to name our folder to backup to.
  • Define Backup location: Create the folder to backup to
  • Delete backup location older than 15 days: All the folders older than 15 days will be deleted. If you want to change the retention just change the parameter $Retentionperiod.

Export the unsealed management packs. With this command we’ll export all the unsealed management packs to the folder. If you (for one reason or another) want to backup all your management packs you can change this code to:

$all_mps = get-managementpack

foreach($mp in $all_mps)

{

export-managementpack -managementpack $mp -path “C:\backups”

}

Thanks to Maarten Goet for providing this example.

Error handling

In this section the script is writing to the Operations manager eventlog a event whether it was successful (id 910) or unsuccessful (ID 911). This can be used to monitor the process.

Feel free to change the ID’s as you please but don’t forget to modify the supplied management pack later on.

scom_backup_unsealedMP0001

Section 3

The mailing section:

If you choose not to monitor this process with SCOM you can activate the mailing section that warns you about the outcome of the process.

Make sure to change the highlighted sections.

scom_backup_unsealedMP0003

Scheduling the script on the RMS

As said before I’m scheduling this script on the RMS using the build-in Windows Task Scheduler.

The command to schedule should be (if you save the file in c:\scripts):

powershell -command “& ‘c:\scripts\backup_mp.ps1’ ”

Monitor the process with SCOM

You can easily monitor the process with SCOM and setup notifications whenever there’s an error. I’ve created a small management pack which contains a monitor to check the status of the backup.

This monitor is healthy by default and comes in critical error when event 911 is logged. However when the next backup is successful, when event 910 is logged, it will return back to healthy. I don’t mind to miss one backup Smile

There’s an automated recovery task included as well to restart the backup when failed.

You can download this small MP here.

Don’t forget to setup your notifications and you’re all done.

Enough talk, let’s build
Something together.