Automating Informix Startup: the dbstart.informix.sh ScriptTo Oracle DBAs: You will miss Oracle's oratab file; there is no similar file in Informix.Not having a global configuration file makes a lot of things more difficult, one of them being backups. When writing a shell script to back up all Informix instances on a given machine, how do you know what instances to back up? You can't ask Informix, which definitely does not know about the other instances. I would like to suggest a different method of starting Informix that would also make backups easier. Let's start with the basics. In order for an Informix database to be started up after a system reboot, a startup script must be placed somewhere in /etc. Startup scripts are run by root, and therefore should be owned by root and placed in a directory that root controls. A startup script in /etc should not be calling a startup script in informix's home directory. However, this creates an extra task for both the SAs and DBAs. The DBA must find a SA every time he wants to add a new instance to the startup script. The SAs would rather not have to do this, but they don't want root running shell scripts found in informix's home directory. The SAs are also normally in charge of backups, and this is one way to find out that there is a new instance to back up. How does Oracle accomplish this task? It's as simple as the oratab file. The start-up scripts are in a directory owned by root, and the oratab file is in a directory owned by the oracle ID. The start-up script starts up any instances in the oratab file that have a "Y" in the third field. All a DBA needs to do to have a new instance started is add the instance to that the oratab file. This also gives backup scripts a great place to start. For example, the oraback.sh utility automatically backs up any instances that it finds in the oratab file. Sure, it's possible for a DBA to create and start up a new instance that does not get put into the oratab file. However, if the oratab file is being used to both start up and back up Oracle, DBAs will get into the habit of putting new instances there. Otherwise, they will continually have to start the instances manually and the instances will also never get backed up. With a little practice, Informix DBAs can be shown to do the same thing that Oracle DBAs do with the oratab file… I present the inftab file, an Informix version of Oracle’s oratab file. The inftab FileThis inftab file in Figure 13-1 has several comments, but only one actual configuration line. This line tells the startup scripts that there is an Informix instance called "crash," that its $INFORMIXDIR is /informix, and that it should be restarted after a reboot. Its logical logs should go to /informix/logical. (The logical backup destination variable will be used for the backup scripts that are covered later in this chapter.)# This file is used by the startup, shutdown and backup scripts
Figure 13-1: A sample inftab file The dbstart.informix.sh script in Figure 13-2 acts very much like Oracle's dbstart script (see Chapter 14). It starts by reading the inftab file to determine the names of all instances. Then it either starts or stops each of the instances that have a Y specified in the third field. It also calls rclogs.sh for each of those instances. Rclogs.sh, discussed later, automatically starts continuous backups in the background. #!/bin/sh
INFTAB=/informix/etc/inftab Usage()
#This script starts up all instance on this box specified in $INFTAB
SCRIPT=`basename $0` if [ $SCRIPT != dbstart -a "$1" != start ] ; then
WHO=`id | awk -F'(' '{print $2}' | awk -F')' '{print $1}' ` if [ "$WHO" = root ] ; then
grep -v '^#' $INFTAB \
STARTUP=`echo $LINE|cut -d: -f3`
BINDIR=$INFORMIXDIR/local/bin
if [ `basename $0` = dbstart -o "$1" = start ] ; then
done
An inftab file provides a single point for all global Informix activities. The difficult part is getting in the habit of using one. However, if all startup, backup, and monitoring scripts base their actions on the inftab file, it will get used soon enough. The DBAs will be happy because they can change a single file that they own, and Informix will automatically start up, back up, and monitor a new instance. The SAs will be happy because they won't have to worry about changing a root-owned shell script every time a new instance is created. Installing the dbstart.informix.sh scriptIf you'd like to begin using dbstart.informix.sh to start up your Informix instances automatically, follow the steps below to install and customize it for your environment.Install the filesCopy the dbstart.informix.sh, dbstart, and dbstop programs into the same directory (e.g., $INFORMIXDIR/local/bin) and make sure that they are executable. If you have only dbstart.informix.sh, dbstart and dbstop are merely hard links to that file. You can make those links yourself by entering:$ ln dbstart.informix.sh dbstart
Copy inftab into a directory that the informix user ID can write to (e.g., $INFORMIXDIR/etc). (They can be placed in the same directory as the other files, but do not need to be.) If you plan to use rclogs.sh with dbstart.informix.sh, you need to read about it later in this chapter, and to configure it as well. Edit the inftab fileIf you have not already done so, edit the file $INFORMIXDIR/etc/inftab. This works basically like Oracle's oratab file. Each Informix instance should be listed in this file, in the following format:onconfig_file:$INFORMIXDIR:Y|N:log_destination
The first field should be the relative name of the onconfig file for that instance (e.g., prod, not $INFORMIXDIR/etc/prod).
Edit the dbstart.informix.sh scriptThe main thing that you need to do is to make sure that the location specified for the inftab file is correct. This is done by changing the $INFTAB variable at the top of the script. If you are not going to use rclogs.sh, you also want to delete the lines that refer to it.Change the startup filesCheck your system documentation for the proper location of startup and shutdown scripts and place dbstart.informix.sh there. On a SVr4-style Unix, you are looking for a file in one of the rc directories. For example, on Solaris, there is probably a file in /etc/init.d, with links to it in other directories. If the file is called informix, simply copy dbstart to informix. This will cause the links to it to run it with the appropriate stop and start arguments. On a BSD-style Unix, you are looking for a command somewhere in /etc/rc or /etc/rc.local.Automating Archives with ontape: the infback.sh UtilityInfback.sh is a shell script that automates performing archives with ontape. Before examining how infback.sh works, we explain why automating ontape backups is difficult.Why automating ontape is difficultThe ontape utility is simple and flexible, but automating it has always been a little difficult, because it is a little picky about how it receives the answers to its questions. For example, some versions of ontape do not accept a typical "here document ", as shown in Figure 13-17 below:LEVEL=0
EOF
Ontape now accepts the use of a –L level argument, but it still requires you to respond to a prompt after executing the command. Ontape can still give you difficulties if you use the above syntax. The method shown in Figure 13-17 is often mentioned in FAQs and other books, but it does not work on every version of Informix. The method that does always seem to work is shown in Figure 13-18: LEVEL=0
"| ontape -s | head -100 > /tmp/logfile
There are two differences between the methods shown in Figures 13-17 and 13-18. The first difference is the way in which the answers are passed to ontape; Method 2 seems to be a little more robust. The second difference between the two methods is the addition of the head command in the second one. The head command is not required, but is a good precaution in case the backup device becomes full. Here’s why: once ontape detects that the backup device is full, it prompts for a second tape. It is not very easy to answer provide a second tape and answer this prompt without using a program such as expect . (There is a way to answer prompts like this by redirecting stdin and stdout to named pipes, but that can be really tricky with ontape. Ontape prompts repeatedly for the second tape and things get pretty ugly very quickly.) The head command keeps this repeated prompting from happening, since it truncates the output to 100 lines, but once the 100 lines have been reached, ontape aborts. How infback.sh worksInfback.sh is a shell script that automates performing archives with ontape. (As discussed above, its one limitation is that it cannot handle multi-volume archives.)Infback.sh consists of several files:
With no argumentsIf you call infback.sh with no arguments, it decides what to backup and what device to use by looking at infback.conf.With arguments specifying backup parametersYou can tell infback.sh which device and level to use by giving them as arguments. If you do this without giving it a list of instances to back up, it will back up any instances it finds in inftab. If you specify instances to back up, it will back up only the instances that you specify.With at as the first argument, with or without backup parameter argumentsSpecifying at as the first argument causes infback.sh to look at infback.conf to determine what time to back up. It then schedules an at job using the same arguments given after the at argument. (That means that the scheduled backup will either figure out what and how to backup via infback.conf or the arguments that were given.)When infback.sh runsOne of the first things that infback.sh does is to check if the word skip is in field 2 of infback.conf. If so, it skips the backup once, and removes the word skip from infback.conf. (This allows a DBA to manually skip tonight's backup, but does not allow the DBA to accidentally disable backups forever.)If infback.sh determines that it is not supposed to skip the backup,
it then needs to determine what instances to back up ($INSTANCE_LIST),
what level backup to run ($LEVEL) and what device to use ($DEVICE).
How infback.sh does this depends on which arguments (if any) it receives.
If called with no arguments:$ infback.shinfback.sh looks at the third field in infback.conf to determine what level of backup to run. That field specifies the full backup day. If today is the full backup day, then it performs a level 0 archive. If it is not today, it performs a level 1 archive. Infback.sh then looks at fields six and seven of infback.conf to get the name of the device server and device that it should backup to. Finally, it looks at inftab for a list of instances to back up. If infback.sh is called with arguments specifying backup parametersIf infback.sh is called with arguments as follows:$ infback.sh level [device|host:device] [instancea instanceb ...] it will determine its level and device from the arguments. If it also receives a list of instances to backup, it will use that as the list of instances. If not, it determines the list of instances to backup by listing each instance list in inftab. The arguments and their possible values are as follows:
If infback.sh is called with “at” as the first argumentIf infback.sh is called with at as the first argument (as it would be called in cron or at):$ infback.sh at infback.sh sets the $TIME variable so that the backups take place at a specified time. If it is a level 0 backup, infback.sh sets the $TIME variable to the value in field 4. If it is a level 1 backup, it sets the $TIME variable to the value in field 5. Infback.sh then schedules an at job that will perform the backup at the time specified by $TIME. If there were other arguments given after the at argument, those arguments are passed to the scheduled run of infback.sh. When the at job runs infback.sh, it will then determine what and how to backup based on the arguments (if any) that it was given. The backup beginsOnce the actual backup is supposed to run, infback.sh checks to see if the database is up. If it is not, infback.sh complains and exits. If it is up, infback.sh checks to see if there is enough space to make a change to the onconfig file . What it does next depends on whether or not you specified that compression should be used.If there is a value specified in infback.conf for $COMPRESS, infback.sh creates a named pipe called $INFORMIXDIR/$INSTANCE.level.$LEVEL.fifo, and changes TAPEDEV to that filename. It does this using onmonitor, so the change will be effective immediately. After creating the named pipe and telling ontape to use it, it calls compress and tells it to read from the named pipe, compress the data, and write it to the location specified as the original device. Infback.sh then calls either ontape or tbtape, depending on the version of Informix you are running , passing it the appropriate level. It checks the status of the backup command and, if backing up to disk, compresses the backup file. If there is no value specified for $COMPRESS, infback.sh sets TAPEDEV to $DEVICE_SERVER:$DEVICE_FILE using onmonitor. It then calls ontape to perform the archive to the specified device. Installing infback.sh and its configuration filesIf you'd like to use infback.sh, you'll need to install the files in the appropriate directory, configure inftab and infback.conf, and customize infback.sh to your environment.Copy infback.sh, localpath.sh, rempath.sh, and config.guess into the
same directory (e.g., $INFORMIXDIR/local/bin) and make sure that
they are executable.
Editing the infback.sh configuration filesIf you have not already done so, you should configure inftab for use on this system. For details on how to do that, read the previous "Editing inftab" section under the dbstart.informix.sh heading.Editing infback.confInfback.conf is the configuration file for inback.sh and rclogs.sh. It should contain one line for each machine in the following format:hostname.master::full_day:full_time:inc_time:device_server:archive_dest:allow_ids:compress:mail_ids
Editing infback.shThere are a few minor changes that you need to make to the infback.sh file itself. Locate the following variable and function declarations in the top of the script, and set them to the appropriate value for your environment.
Centralized configurationJust like oraback.sh, the configuration file infback.conf can be shared via NFS. If multiple servers share the same configuration file, and you are using the at argument, you could make changes to all Informix backups by changing one file. Suppose that Informix backups are currently set up to run a full backup on Sunday at 1900. However, you know that the network will be down this Sunday. With most home-grown backup scripts, you would need to log into several servers and change multiple cron entries. With a centralized infback.conf file, you need only to changefield three for each server from "Sun" to "Mon." If you know that there will be some intensive processing this evening, you could also skip all infback.sh backups by putting the word "skip" in field two.Scheduling backupsTo use all scheduling features of infback.sh, create a cron entry that calls infback.sh at a time earlier than the earliest time specified in fields four and five in infback.conf. Since most backups are run after 6 P.M., a common entry would be like the following:0 17 * * * /informix/local/bin/infback.sh at This specifies to run the script with the at argument at 5 P.M. This causes infback.sh to look at the infback.conf file to determine what level of backup to run, and what time to run it. It will then schedule an at job for the appropriate time. The reason for keeping the entry as late as possible is to allow the DBAs to make changes to infback.conf. Since infback.sh does not look at the file until 5 P.M., they can change tonight's backup time or skip tonight's backups by changing the file any time before then. Automating Continuous Backups: the rclogs.sh UtilityThe rclogs.sh program can back up to either tape or disk, but it works best if backing up to disk because it can automate the "swap tapes" step by automatically moving and creating files as needed. The first step that rclogs.sh performs is to check that the Informix instance is online. It performs a WHILE loop until the instance reports "On-line" or "Read-only." If it stays in this loop for 60 seconds, it exits with an error. Without this feature, a malfunctioning instance would prevent other instances from starting when this program is called from dbstart.The next thing that rclogs.sh does is check to see if there are any ontape -c backups running for this instance. If so, it stops them. If rclogs.sh was called with the stop argument, it then exits. If it was called with the start argument, it then needs to "swap tapes." If backing up to disk, rclogs.sh moves the continuous backup file to a date/time-stamped file and creates an empty file for the next ontape -c session. If backing up to tape, this program cannot be run from cron; it must be run manually from a terminalbecause once it stops the ontape -c session, it can only notify the operator running the program to swap the tape, and wait for notification that this has been done. Once rclogs.sh knows that the tape has been swapped, it will start a new ontape -c session in the background. It then queries Informix to verify that continuous backups are running, and sends notification of success or failure. Installing rclogs.sh and its configuration filesInstall the files rclogs.sh, localpath.sh, rempath.sh and config.guess in the same directory (e.g., $INFORMIXDIR/local/bin) and make sure that they are all executable. Install inftab and infback.conf in a directory writable by informix (e.g., $INFORMXDIR/etc). (These two files do not have to be in the same directory as the executables, but they can be.)Editing rclogs.sh and its configuration filesMake sure you have already configured the inftab and infback.conf files for use on this system; details on how to do this can be found in the previous Editing the infback.sh configuration files section. (The only field that rclogs.sh uses from infback.conf file is the mail ids field.)Check the site-specific section at the top of rclogs.sh and make sure that all the values are appropriate for your environment. The following values are found there:
Testing the rclogs.sh programBefore adding the rclogs.sh script to cron, you might want to run it a few times to make sure that it works in your environment. Run rclogs.sh:
Scheduling backupsOnce you are sure the program works for you, you have a few options for how it is used. If you have installed dbstart.informix.sh, it automatically calls rclogs.sh when the system shuts down or starts up. This means that continuous backups are automatically started when the instance is started using dbstart.informix.sh.If you are backing up to disk, you can greatly increase your recoverability options by running rclogs.sh every hour or half-hour. This is especially true if you have added some commands to the Backup_the_backup function. Instead of having one large log for each day, you will have many small logs that get backed up throughout the day. Doing this ensures you'll never lose more than 30 minutes worth of data. The following cron entry runs rclogs.sh every half-hour: 00,30 * * * * /informix/local/bin/rclogs.sh start Using the Scripts TogetherThe scripts discussed in the previous sections all work together. Dbstart, rclogs.sh, and infback.sh all use the inftab file. Rclogs.sh and infback.sh both use the infback.conf file. Dbstart automatically calls rclogs.sh. Running rclogs.sh on an hourly or half-hourly basis will provide you with multiple logical log backups that you can use at recovery time. Running a weekly full and daily incremental backup using infback.sh will reduce the amount of time spent doing backups, and still requires only three tapes for a restore (the third tape is the logical log backup). |