Migrating your onconfig

The one really inconvenient thing about migrating an Informix instance is what the upgrade does to the onconfig file. Well, basically, it only adds the new config parameters to the end of file. So, what you lose is nice order and grouping of parameters with comments describing them. After doing a major upgrade on some instance, your onconfig would be a mess – fewer parameters would be documented in the file itself, and there’d be lots of new parameters at the end of file.

If you don’t want to live with this, you could take new version’s onconfig.std, copy it, run a diff to your current onconfig and manually insert your values in the copy. I like my production onconfigs neat, but as the onconfig grows, maintaining it becomes more time consuming.

So here is the much quicker solution. A groovy script that’ll do that for you. In one of my previous posts, I’ve described how to run groovy scripts. What the script does is take the onconfig.std, make a copy and put your values to the right places in that copy. Parameters that are commented out or don’t show in the std file are added to the end. Comments at the end of line containing actual parameter value are preserved. New onconfig file is named like the original one, with the “.new” at the end.

Here is a usage example. Prepare the current onconfig file for migration to version 11.70FC4:

groovy migrateOnconfig.groovy \
    -i $INFORMIXDIR/etc/$ONCONFIG \
    -s /opt/IBM/informix1170FC4/etc/onconfig.std

The output would be the $INFORMIXDIR/etc/$ONCONFIG.new file.

And here is the script itself. Just copy the code in a file called migrateOnconfig.groovy, and feel free to try it. There’s nothing to lose, as there is no impact to existing files.

/**
 * script to help migrating onconfig to whichever version
 *
 * provide actual onconfig file and onconfig.std of version
 * your migrating on
 *
 * parameters that have no default value in std are appended to the end of file
 *
 * @author Ognjen Orel
 */

// command line parsing specification
def cl = new CliBuilder(usage: getClass().getName() + ' options')
cl.h(longOpt: 'help', 'Show usage information and quit')
cl.i(argName: 'inputFile', longOpt: 'inputFile', args: 1, required: true, 
     'onconfig file currently in use, REQUIRED')
cl.s(argName: 'stdFile', longOpt: 'stdFile', args: 1, required: true, 
     'onconfig.std file to use as a template, REQUIRED')

def options = cl.parse(args)

File std = new File(options.s), output = new File(options.i + '.new')
List input = new File(options.i).readLines()

String param, additional
List written = new ArrayList()
def inputLines
def needsAdditional = ['VPCLASS', 'BUFFERPOOL']

output.delete()
output.createNewFile()

std.eachLine { stdLine ->
   // copy all comment or empty lines
   if (stdLine.startsWith('#') || stdLine.trim().isEmpty())
      output << stdLine + '\n'
   else {
      param = stdLine.tokenize()[0]

      if (needsAdditional.contains(param))
         additional = stdLine.tokenize(',')[0].tokenize(' ')[1]
      else
         additional = null

      inputLines = input.findAll{ 
          it.matches('(' + param + ')(\\s+)(.*)') || it.equals(param) }
      if (!inputLines.isEmpty()) {
         if (additional != null)
            inputLines = inputLines.findAll { it.contains(additional) }

         inputLines.each {
            output << it + '\n'
            written.add it
         }
      }
      else
         output << stdLine + '\n'
   }
}
// write all parameters with no default value in onconfig.std at the end
output << '\n\n### parameters with no default value in onconfig.std: \n\n'
(input - written).each {
   if (!it.trim().startsWith('#') && !it.trim().isEmpty())
      output << it + '\n'
}
Advertisements

, ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: