Advanced Workflow with MQ File Mover (How To #6)

And now for something completely different. 🙂 In this blog posting, I will show you how to create an MQFM Workflow to do something other than move files with MQ.

Lets say you have an online backup service or a cloud service where you want to backup important files to. So lets create an MQFM Workflow to handle this business process. Here are the tasks that need to be completed:

  • Compress all of the files and directories that will be backed up
  • Encrypt the compressed file so that prying eyes do not know what we have
  • ftp the file to the remote site
  • Delete the local compressed and encrypted files

This following example was tested on Windows. It can be easily adopted for Unix, Linux, Mac OS X or IBM i servers.

Step #1: On the Windows server, in the jobs directory, create a file called ftp_offsite_1.xml and copy the following into the file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE MQFM_Job SYSTEM "MQFM_Job.dtd">
<MQFM_Job>
  <Job name="ftp">
    <Command wait='y'>ftp.exe</Command>
    <Parm>-n</Parm>
    <Parm>-s:ftp_cmds_1.txt</Parm>
    <Parm>offsite.server.com</Parm>
  </Job>
</MQFM_Job>

The MQFM Job XML defines how to run an external command. For the Windows ftp program, it requires 3 parameters. The 2nd parameter points to a file that will be defined in Step #2 (below). The 3rd parameter contains the URL of the remote ftp server. You will need to update it with your ftp server’s URL.

Step #2: On the Windows server, in the MQFM install directory, create a file called ftp_cmds_1.txt and copy the following into the file:

user roger mypwd
prompt off
binary
cd offsite
put C:\temp\offsite\mydata.enc
quit

The above ftp commands will login into the remote ftp server, set the transfer type, change directory to offsite then upload the file. Note: The first line should contain your UserID and Password for your offsite/cloud service.

Step #3: On the Windows server, in the MQFM install directory, create a file called mqfm_offsite_1.xml and copy the following into the file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE MQFM_Workflow SYSTEM "MQFM_Workflow.dtd">
<MQFM_Workflow>
  <Global>
    <Property name="my_zip_file" value="C:\temp\offsite\mydata.zip" />
    <Property name="my_enc_file" value="C:\temp\offsite\mydata.enc" />
  </Global>

  <Actions>

    <Zip file="${my_zip_file}">
      <File>C:\data</File>
    </Zip>

    <EncryptFile file="${my_enc_file}" keysize="128"
               passphrase="this is 8 secret words for my script">
      <File>${my_zip_file}</File>
    </EncryptFile>

    <Execute xmlfile="ftp_offsite_1.xml" />

    <Delete>
      <File>${my_enc_file}</File>
      <File>${my_zip_file}</File>
    </Delete>

  </Actions>
</MQFM_Workflow>

The above MQFM Workflow has 4 actions. When MQFM is started, it will compress the files and directories located at C:\data\, next it will encrypt the zip file. The Execute Action will run an ftp command to upload the file to a remote server. Finally, the last action will delete the compressed and encrypted files.

Step #4: On the Windows server, to run the the MQFM Workflow, issue the following command:

./mqfm.sh mqfm_offsite_1.xml

This blog demonstrates how easy it is to create an MQFM Workflow to process business tasks.

Regards,
Roger Lacroix
Capitalware Inc.

This entry was posted in Capitalware, IBM i (OS/400), IBM MQ, Java, Linux, macOS (Mac OS X), MQ File Mover, Open Source, Unix, Windows.

Comments are closed.