tktym2tips

技術メモ的な。tips的ななにか。

logrotateでログファイルのサフィックスを日付にする

CentOSとかでサーバを構築するときによく使う。


「/etc/logrotate.conf」もしくは「/etc/logrotate.d配下の個別設定ファイル」で
dateextオプションを有効にすると、ログファイルのサフィックスが日付ベースになる。

以下サンプル。


/etc/logrotate.conf の場合

$ cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
dateext # ←ココ!!

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
minsize 1M
rotate 1
}

/var/log/btmp {
missingok
monthly
create 0600 root utmp
rotate 1
}


/etc/logrotate.d配下の個別設定ファイル(例:syslog)」の場合

$ cat /etc/logrotate.d/syslog
/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
{
sharedscripts
dateext # ←ココ!!
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}