Logrotate
Erscheinungsbild
logrotate
logrotate rotiert und komprimiert Logdateien, damit diese nicht unkontrolliert anwachsen.
- Die Konfig-Dateien sind: /etc/logrotate.conf und /etc/logrotate.d
- Nach Ablauf eines Intervalls verschiebt er die Datei, indem er die Dateiendung .1 hinten anstellt, beim nächsten Intervall wird die zuvor verschobene Datei wieder umbenannt und diesmal auch noch komprimiert, sodass hinten ein .2.gz steht.
- Wie viele alte Logfiles und das Intervall kann man in der logrotate.conf ändern
So könnte eine logrotate.conf aussehen:
# 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
# uncomment this if you want your log files compressed
#compress
# packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp, or btmp -- we'll rotate them here
/var/log/wtmp {
missingok
monthly
create 0664 root utmp
rotate 1
}
/var/log/btmp {
missingok
monthly
create 0660 root utmp
rotate 1
}
Dateien in logrotate.d sind nach dem gleichen Muster aufgebaut
root@alex:/etc/logrotate.d# cat apt
/var/log/apt/term.log {
rotate 12
monthly
compress
missingok
notifempty
}
/var/log/apt/history.log {
rotate 12
monthly
compress
missingok
notifempty
}
logrotate sollte am besten täglich ausgeführt werden. Hierfür eignet sich cron.