log rotation:
To Rotate the logs periodically.
We do log rotation to suppress the alerts on filesystem utilization.
a)Create a file under /etc/logrotate.d/
and update entries like below.
full_path_of_the_log file{
compress
copytruncate
daily
dateext
notifempty
missingok
}
EOF
Validation:
# logrotate -df /etc/logrotate.d/inpute-logs <-- test run
# logrotate -vf /etc/logrotate.d/inpute-logs <-- real deal
compress
Old versions of log files are compressed with gzip(1) by default.
See also nocom-
press.
compresscmd
Specifies which command to use to compress log files. The default is
gzip. See also
compress.
uncompresscmd
Specifies which command to use to uncompress log files. The default
is gunzip.
compressext
Specifies which extension to use on compressed logfiles, if
compression is enabled.
The default follows that of the configured compression command.
compressoptions
Command line options may be passed to the compression program, if one
is in use. The
default, for gzip(1), is "-9" (maximum compression).
copy Make a copy of the log file, but don’t change the original at all.
This option can
be used, for instance, to make a snapshot of the current log file, or
when some other
utility needs to truncate or parse the file. When this option is
used, the create
option will have no effect, as the old log file stays in place.
copytruncate
Truncate the original log file in place after creating a copy,
instead of moving the
old log file and optionally creating a new one. It can be used
when some program
cannot be told to close its logfile and thus might continue writing
(appending) to
the previous log file forever. Note that there is a very small
time slice between
copying the file and truncating it, so some logging data might be
lost. When this
option is used, the create option will have no effect, as the old
log file stays in
place.
create mode owner group, create owner group
Immediately after rotation (before the postrotate script is run) the
log file is cre-
ated (with the same name as the log file just rotated). mode
specifies the mode for
the log file in octal (the same as chmod(2)), owner specifies the
user name who will
own the log file, and group specifies the group the log file will
belong to. Any of
the log file attributes may be omitted, in which case those
attributes for the new
file will use the same values as the original log file for the
omitted attributes.
This option can be disabled using the nocreate option.
createolddir mode owner group
If the directory specified by olddir directive does not exist, it is
created. mode
specifies the mode for the olddir directory in octal (the same as
chmod(2)), owner
specifies the user name who will own the olddir directory, and group
specifies the
group the olddir directory will belong to. This option can be
disabled using the
nocreateolddir option.
daily Log files are rotated every day.
dateext
Archive old versions of log files adding a daily extension like
YYYYMMDD instead of
simply adding a number. The extension may be configured using the
dateformat option.