HOWTO: bulk export / import MOM management packs

Hi,

As a MOM system administrator / consultant I have visited many customers that don't backup the MOM MPs. The say "why? I'm making a SQL onepoint backups , this should do it….” Personally I'm not a big pro on restoring the complete onepoint db if you lose or miss-change a MP. So the mom SDK has some tools to export / import MPs from the command line. The only problem is that this tool only processes 1 rule group at the time. I've written a c# program that solves this problem. This is a simple way to export (backup) your MPs. I use the tool for one reason more: I'm using the MOM to MOM product connector to forward alerts from a co hosting MOM locations to our main MOM location. This requires you to have the same MPs on both sites. My tool has a Import feature as well. So you can make a co-site export and import to the main site in one step.
So if you want to make only a export (for backup resons) you make the source and destination server parameters the same. The tool then only exports the MPs to the given directory. If you fill in a different destination server the tool will imports the exported MPs one by one on the specified server. The tool also export / imports all the RULES , VIEWS , TASKS.

Command line usage:
ExportImportMP.exe <source mom server> <dest mom server> <dest path>

requirements:
– Dot Net 1.1 framework installed
– MOM SDK installed
– must exists:Program FilesMicrosoft Operations Manager 2005ManagementModuleUtil.exe
– execute&nbsp;on the MOM server.

I will share the code. This&nbsp;is a quick programming project , so do not except to much:
(You can download the project from the download section&nbsp;on this blog server)

It is build of 3 parts.
Part one reads out the command line arguments and is creating a MOM management object.

&nbsp;System.Diagnostics.Process proc = new System.Diagnostics.Process();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string arguments;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string SourceSrv;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string DestSrv;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string DestDir;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (args.Length != 3)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(&quot;Error invalid arguments&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(&quot;VERSION : 0.9&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(&quot;Michel Kamp. 2006&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(&quot;Usage: ExportImportMP <source mom server> <dest mom server> <dest path>&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(&quot;Description: Export and import MOM MPs with the ManagementModuleUtil.exe&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(@&quot;Description: besure C:Program FilesMicrosoft Operations Manager 2005ManagementModuleUtil.exe exsists&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(&quot;HINT: If the Source and destionation is the same then no import will be done. This is usefull for making an backup. &quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Environment.Exit(-1);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SourceSrv = args[0].ToString();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DestSrv = args[1].ToString();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DestDir = args[2].ToString();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(&quot;ExportImportMP &quot; + SourceSrv + &quot; &quot; + DestSrv + &quot; &quot; +DestDir );
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Administration admin = Administration.GetAdministrationObject();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RuleGroupsCollection rgs = admin.GetRuleGroups();
&nbsp;&nbsp;&nbsp;&nbsp;

Part 2 does the export

foreach (RuleGroup rg in rgs)
{
Console.WriteLine(&quot;Export RULES: &quot; + rg.Name);
Console.WriteLine(&quot;DestDir: &quot; + DestDir);
arguments = &quot; -O &quot; + SourceSrv + &quot; {&quot; + rg.Id.ToString().ToUpper()&nbsp; + &quot;} &quot; + &quot;&quot;&quot; +&nbsp; DestDir + @&quot;&quot; + rg.Name + @&quot;.AKM&quot; + &quot;&quot;&quot; +&nbsp; &quot; -W&quot;;&nbsp;
proc.EnableRaisingEvents=true;
proc.StartInfo.FileName=@&quot;C:Program FilesMicrosoft Operations Manager 2005ManagementModuleUtil.exe&quot; ;
proc.StartInfo.Arguments=arguments;
Console.WriteLine(&quot;Processing :&quot; + proc.StartInfo.FileName + &quot; &quot; + proc.StartInfo.Arguments);
proc.Start();
&hellip;&hellip;.

&nbsp;Part 3 does the import

if ( SourceSrv != DestSrv )
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(&quot;IMPORT: &quot; + rg.Name);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arguments = &quot; -I &quot; + DestSrv + &quot; &quot;&quot; + DestDir + @&quot;&quot; + rg.Name + &quot;.AKM&quot; + &quot;&quot; -F&quot;;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; proc.EnableRaisingEvents=true;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; proc.StartInfo.FileName=@&quot;C:Program FilesMicrosoft Operations Manager 2005ManagementModuleUtil.exe&quot; ;
proc.StartInfo.Arguments=arguments;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(&quot;Processing :&quot; + proc.StartInfo.FileName + &quot; &quot; + proc.StartInfo.Arguments);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; proc.Start();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; proc.WaitForExit();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }

Hope you can use it. If not please let me know why and what&rsquo;s missing.

You can download the project from the download section&nbsp;on this blog server

Michel Kamp&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;

&nbsp;