Exporting MQ Objects into Individual Files

I posted this item on mqseries.net and I thought I should do a write up here.

Back in the early 2000s, I was a consultant at a customer site and they wanted the nightly dumps of the MQ objects (not messages), 1 line per object and then check those files into a source code repository.

I used SupportPac MS03 to dump the MQ objects but it put all objects in the same file and each object was on many lines. So, I wrote a simple Rexx script to extract each object type to: (1) flatten each object to 1 line and (2) write it their own object file.

SupportPac MS03 has been replaced with the dmpmqcfg program.

I have updated the list of object types in the Rexx script for the modern IBM MQ v9.2 (because IBM has added a lot of new objects in the last 15 years).

Example of running dmpmqcfg against your queue manager called MQA1:

dmpmqcfg -m MQA1 -a > MQA1.all.mqsc

Then you run it against my REXX script called fmt_dmpmqcfg.rex:

/* Format output from dspmqcfg command to a single line for each entry.  */
/* Put each MQ object type into a different file.                        */
/*                                                                       */
/* Example dspmqcfg command:                                             */
/*    dmpmqcfg -m MQA1 -a > MQA1.all.mqsc                                */

trace o
Parse Arg inFN .

if inFN = "" then
do
   Say "Invalid number of parameters."
   Say "i.e."
   Say "     fmt_dmpmqcfg.rex input_file_name"
   Exit
end

types = "QMGR CHANNEL LISTENER NAMELIST PROCESS QALIAS QLOCAL QMODEL QREMOTE SERVICE SUB TOPIC AUTHREC AUTHINFO CHLAUTH COMMINFO"


/* open file */
Call Stream inFN,'C','OPEN READ'

/* Delete previous output and then open it. */
do i=1 to Words(types)
   ptr = Word(types,i)
   outFN = inFN||"."||ptr||".mqsc"
   if (STREAM( outFN, 'C', 'QUERY EXIST' ) <> "") then
      "ERASE  "outFN
   Call Stream outFN,'C','OPEN WRITE'
   counts.ptr = 0
end

total = 0
mqscCmd = ""
do until Lines(inFN) = 0

   inLine = Strip(LineIn(inFN))   /* read next line */

   if (inLine = "") then
      NOP   /* blank line, forget-about-it */
   else if (SubStr(inLine,1,1) = "*") then
      NOP   /* comment line, forget-about-it */
   else
   do
      /* Last attribute in MQSC command? */
      if (Length(inLine) <> LastPos('+',inLine)) then
      do
         mqscCmd = mqscCmd || " " || inLine  /* add last attribute */
         ptr = Word(mqscCmd, 2)

         if (Pos("(", ptr) > 0) then
            ptr = SubStr(ptr, 1, Pos("(", ptr) - 1)

         nothing = LineOut(inFN||"."||ptr||".mqsc", mqscCmd)   /* write to the file  */

         counts.ptr = counts.ptr + 1
         total = total + 1
         mqscCmd = ""
      end
      else
      do
         temp = Strip(SubStr(inLine,1,(LastPos('+',inLine) - 1)))  /* remove '+' */
         if (mqscCmd = "") then
            mqscCmd = temp
         else
            mqscCmd = mqscCmd || " " || temp
      end
   end
end

/* close the files  */
Call Stream inFN,'C','CLOSE'
do i=1 to Words(types)
   ptr = Word(types,i)
   outFN = inFN||"."||ptr||".mqsc"
   Call Stream outFN,'C','CLOSE'
   Say outFN || " contains " || counts.ptr || " MQSC formatted commands."
end

Say ""
Say "Total formatted MQSC commands was:" total

Exit

To run the Rexx script, the command is:

rexx fmt_dmpmqcfg.rex  MQA1.all.mqsc

The Rexx script will output:

MQA1.all.mqsc.QMGR.mqsc contains 1 MQSC formatted commands.
MQA1.all.mqsc.CHANNEL.mqsc contains 43 MQSC formatted commands.
MQA1.all.mqsc.LISTENER.mqsc contains 5 MQSC formatted commands.
MQA1.all.mqsc.NAMELIST.mqsc contains 3 MQSC formatted commands.
MQA1.all.mqsc.PROCESS.mqsc contains 2 MQSC formatted commands.
MQA1.all.mqsc.QALIAS.mqsc contains 4 MQSC formatted commands.
MQA1.all.mqsc.QLOCAL.mqsc contains 111 MQSC formatted commands.
MQA1.all.mqsc.QMODEL.mqsc contains 7 MQSC formatted commands.
MQA1.all.mqsc.QREMOTE.mqsc contains 11 MQSC formatted commands.
MQA1.all.mqsc.SERVICE.mqsc contains 6 MQSC formatted commands.
MQA1.all.mqsc.SUB.mqsc contains 1 MQSC formatted commands.
MQA1.all.mqsc.TOPIC.mqsc contains 8 MQSC formatted commands.
MQA1.all.mqsc.AUTHREC.mqsc contains 438 MQSC formatted commands.
MQA1.all.mqsc.AUTHINFO.mqsc contains 4 MQSC formatted commands.
MQA1.all.mqsc.CHLAUTH.mqsc contains 3 MQSC formatted commands.
MQA1.all.mqsc.COMMINFO.mqsc contains 1 MQSC formatted commands.

Total formatted MQSC commands was: 648

If you setup a job (script/batch file) to do this nightly and then check the output files into a source code repository then you will have a complete history of changes made to your queue manager. Because the Rexx script flattens the data to 1 line per object, your source code repository will show you exactly which objects have changed.

Its a simple hack but well worth implementing.

Regards,
Roger Lacroix
Capitalware Inc.

This entry was posted in IBM MQ, IBM MQ Appliance, Linux, macOS (Mac OS X), Open Source, Programming, Rexx, Windows.

Comments are closed.