Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Navigation  Back up to About Overview 
  
[+] Expand All
[-] Collapse All

Configuring the Logrotate Utility (SRC CLI)

Use the options described in Table 8 to configure global and local options for the logrotate utility. You set global options under the [edit system logrotate logrotate.conf] hierarchy level. You set local options for specific logging configuration files such as the /var/log/wtmp file under the [edit system logrotate logrotate.conf logfiles name] hierarchy level. You specify log rotation for system and SRC components under the [edit system logrotate file-name logfiles] hierarchy levels.

Table 8: Logrotate Options

Option

Description

compress

(Optional) Compress old versions of log files in gzip format.

delay-compress

(Optional) Postpone compression of the previous log file until the next rotation cycle. This option takes effect only when used in conjunction with the compress option. Use this option when a program cannot be instructed to close its log file and as a result may continue writing to the previous log file indefinitely.

copy

(Optional) Make a copy of the log file, but do not modify the original log file. Use this option to make a snapshot of the current log file, or when some other utility needs to truncate or parse the file. When you use this option, the create option has no effect because the original log file stays in place.

daily

(Optional) Rotate log files every day.

weekly

(Optional) Rotate log files weekly. This option rotates log files if the current weekday is earlier than the weekday of the last rotation or if more than a week has passed since the last rotation.

monthly

(Optional) Rotate log files monthly. This option rotates log files the first time that logrotate is run in a month (which is normally on the first day of the month).

rotate rotate

(Optional) Rotate log files the specified number times before removing them. If set to 0, old versions are removed rather than rotated.

size size

(Optional) Rotate log files when they grow larger than the specified size in bytes.

  • If the size is followed by k, the size is assumed to be in kilobytes.
  • If the size is followed by M, the size is assumed to be in megabytes.
  • If the size is followed by G, the size is assumed to be in gigabytes.

For example, size 100, size 100k, size 100M, or size 100G are all valid settings for this option.

This option is mutually exclusive of the time interval options (daily, weekly, or monthly), and log files are rotated without regard for the last rotation time.

no-create

(Optional) Do not create new log files. This option overrides the settings under the [edit system logrotate logrotate.conf create], [edit system logrotate logrotate.conf logfiles name create], and [edit system logrotate file-name logfiles name create] hierarchy levels.

copy-truncate

(Optional) When set, this option copies the active log file to a backup and truncates the active log file. Truncate the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one. This option is useful when programs cannot be instructed to close their log file and as a result, may continue writing (appending) to the previous log file indefinitely.

Note: There is a very small time period between copying the file and truncating it, so some logging data might be lost. When you specify this option, the create option has no effect because the old log file stays in place.

if-empty

(Optional) Rotate the log file even if it is empty.

missing-ok

(Optional) If the log file is missing, go on to the next log file without issuing an error message.

filenames filenames

(Optional) Names of the log files to rotate. Separate filenames with a space.

shared-scripts

(Optional) Normally, the scripts you specify with the pre-rotate and post-rotate options are run for each log that is rotated and the absolute path to the log file is passed as the first argument to the script. This means a single script may be run multiple times for log file entries that match multiple files. If you specify the shared-scripts option, the scripts are run only once, regardless of how many logs match the wildcard pattern, and the entire pattern is passed to them. However, if none of the logs in the pattern require rotating, the scripts are not run at all. If the scripts exit with an error, the remaining actions are not executed for any log.

pre-rotate pre-rotate

(Optional) The lines between the pre-rotate and endscript (both of which must appear on lines by themselves) are executed (using /bin/sh) before the log file is rotated and only if the log is actually to be rotated. These directives may appear only inside a log file definition. Normally, the absolute path to the log file is passed as the first argument to the script. If the shared-scripts option is specified, the whole pattern is passed to the script.

post-rotate post-rotate

(Optional) The lines between the post-rotate and endscript (both of which must appear on lines by themselves) are executed (using /bin/sh) after the log file is rotated. These directives may appear only inside a log file definition. Normally, the absolute path to the log file is passed as the first argument to the script. If the shared-scripts option is specified, the entire pattern is passed to the script.

first-action first-action

(Optional) The lines between first-action and endscript (both of which must appear on lines by themselves) are executed (using /bin/sh) once before all log files that match the wildcard pattern are rotated, before the pre-rotate script is run, and only if at least one log is to be rotated. These directives may appear only inside a log file definition. The entire pattern is passed to the script as the first argument. If the script exits with an error, no further processing is performed.

last-action last-action

(Optional) The lines between last-action and endscript (both of which must appear on lines by themselves) are executed (using /bin/sh) once after all log files that match the wildcard pattern are rotated, after the post-rotate script is run, and only if at least one log is rotated. These directives may appear only inside a log file definition. The entire pattern is passed to the script as the first argument. If the script exits with an error, only an error message is shown (because this is the last action).

Use the options described in Table 9 under the [edit system logrotate logrotate.conf create], [edit system logrotate logrotate.conf logfiles name create], and [edit system logrotate file-name logfiles name create] hierarchy levels to specify the permissions, owner, and group of new log files. The default is to use the same mode, owner, and group as the original file.

Table 9: Options for Specifying How Log Files Are Created

Option

Description

default

Create new log files with the same mode, owner, and group as the original file.

mode mode

Create new log files with the specified mode in octal format.

owner owner

Create new log files with the specified owner (username).

group group

Create new log files with the specified group.

Configuring the Global Options for the Logrotate Utility

To configure global options for the logrotate utility:

Note: The CLI editing level must be set to expert to set the global options.

  1. From configuration mode, access the configuration statement that configures global options for the logrotate utility.
    [edit]user@host# edit system logrotate logrotate.conf
  2. Specify how you want to rotate and compress the log files by setting the desired options listed in Table 8. For example, to rotate log files weekly and compress them:
    [edit system logrotate logrotate.conf]user@host# set weekly user@host# set compress
  3. Specify how you want to create new log files by setting the options listed in Table 9. For example, to use the default setting:
    [edit system logrotate logrotate.conf]user@host# edit create user@host# set default

Configuring Log Rotation Options for Specific Logging Configuration Files

Use the following procedure to configure log rotation options for specific files such as the /var/log/wtmp file.

To configure local options for the logrotate utility:

  1. From configuration mode, access the configuration statement that configures local options for the logrotate utility and specify one or more log filenames. Separate log filenames with a space.
    [edit]user@host# edit system logrotate logrotate.conf logfiles name
  2. Specify how you want to rotate and compress the log files by setting the desired options listed in Table 8. For example, to rotate log files weekly:
    [edit system logrotate logrotate.conf logfiles name]user@host# set weekly
  3. Specify how you want to create new log files by setting the options listed in Table 9. For example, to use the default setting:
    [edit system logrotate logrotate.conf logfiles name]user@host# edit create user@host# set default

Configuring Logging Rotation Options for System and SRC Components (SRC CLI)

Options you configure for system and specific SRC components override global and local options of the same name.

To configure log rotation options for the system or for SRC components:

  1. From configuration mode, access the configuration statement to configure local options and specify the filename used by the SRC component.
    [edit]user@host# edit system logrotate file-name

    For example, to specify local options for the ACP component:

    [edit]user@host# edit system logrotate UMCacp
  2. Specify the name of one or more log files for which you want to configure compression and rotation options. Separate log filenames with a space.
    [edit system logrotate UMCacp]user@host# edit logfiles name

    For example, to specify the UMCacp-1 log file:

    [edit system logrotate UMCacp]user@host# edit logfiles UMCacp-1
  3. Specify how you want to rotate and compress the log files by setting the desired options listed in Table 8. For example, to rotate log files weekly:
    [edit system logrotate UMCacp logfiles UMCacp-1]user@host# set weekly
  4. Specify how you want to create new log files by setting the options listed in Table 9. For example, to use the default setting:
    [edit system logrotate UMCacp logfiles UMCacp-1]user@host# edit create user@host# set default

Related Documentation

Modified: 2017-08-02