LDM Log File Rotation

Without intervention, the LDM log file , ldmd.log, will grow without bound. For this reason, it is desirable to have an automatic process manage the LDM log file. A convenient mechanism for curtailing growth is provided by the ldmadmin newlog command in conjunction with the UNIX crontab utility.

The ldmadmin newlog command rotates through the last $numlogs log files of the LDM, where $numlogs is a user-customizable variable in the ldmadmin script. The command causes every log file matching the patten ldmd.log.n, where n is a positive integer less than $numlogs, to be renamed ldmd.log.n+1, where n+1 denotes the next higher integer. This action will proceed from the larger n-s to the smaller so that no log file is lost. Then, the file ldmd.log is renamed ldmd.log.1. Finally an empty ldmd.log file is created.

For example, if the ldmadmin newlog command was executed at 18:00 on the 20th and if the $numlogs variable was 2, then the following files:

-rw-r--r--   1 ldm      staff       972 Sep 19 18:00 /opt/ldm/logs/ldmd.log
-rw-r--r--   1 ldm      staff       845 Sep 18 18:00 /opt/ldm/logs/ldmd.log.1
-rw-rw-r--   1 ldm      staff       826 Sep 17 18:00 /opt/ldm/logs/ldmd.log.2
-rw-r--r--   1 ldm      staff       981 Sep 16 18:00 /opt/ldm/logs/ldmd.log.3
would become
-rw-r--r--   1 ldm      staff         0 Sep 20 18:00 /opt/ldm/logs/ldmd.log
-rw-r--r--   1 ldm      staff       972 Sep 19 18:00 /opt/ldm/logs/ldmd.log.1
-rw-r--r--   1 ldm      staff       845 Sep 18 18:00 /opt/ldm/logs/ldmd.log.2
-rw-r--r--   1 ldm      staff       981 Sep 16 18:00 /opt/ldm/logs/ldmd.log.3
Note that the ldmd.log.3 file was untouched.

An excellent way to ensure that this rotation occurs on an automatic and regular basis is to execute the command out of the LDM user's crontab file. For example, the following entry will cause the command to be executed at 1800 hours local-time every day:

0 18 * * * bin/ldmadmin newlog

Because the timestamps in an LDM log file are usually in UTC, a common convention is to rotate the log files at 0000 hours UTC. This is why the above example used 1800 hours MDT. (If we remember, we change the execution-time to 1700 MST when appropriate.) An alternative convention is to rotate the log file at local midnight, e.g.,

0 0 * * * bin/ldmadmin newlog
Both conventions are equally valid. You'll just have to remember which one you use.

We also like to keep a week's worth of LDM log file entries around -- so we change the $numlogs variable to 7.

This rotation (and purging) of the LDM log files will ensure that the space occupied by the log files will not grow indefinitely.