Thursday, 14 February 2013

Logrotation in Linux/unix

Log files are the most valuable tools available for Linux system security. The logrotate program is used to provide the administrator with an up-to-date record of events taking place on the system. The logrotate utility may also be used to back up log files, so copies may be used to establish patterns for system use.

logrotate
the logrotate program is a log file manager. It is used to regularly cycle (or rotate) log files by removing the oldest ones from your system and creating new log files. It may be used to rotate based on the age of the file or the file’s size, and usually runs automatically through the cron utility. The logrotate program may also be used to compress log files and to configure e-mail to users when they are rotated.

Configuration File :- 
Files
/var/lib/logrotate.status   >> this file update  status of recent execution of  logrotation.

root@puppet:~/sadeek/big# ls -l /var/lib/logrotate/status
-rw-r--r-- 1 root root 2030 Feb 23 07:55 /var/lib/logrotate/status
root@puppet:/etc/logrotate.d# ls -l /var/lib/logrotate/status
-rw-r--r-- 1 root root 2030 Feb 24 05:57 /var/lib/logrotate/status

Default state file.
/etc/logrotate.conf     by default configuration file of logs

below are the some example for log rotation configuration, you need to create a file and make the entry as below. it will rotate the logs weekly.
/etc/logrotate.d/
 vi samba
/var/log/samba/log.smbd {
        weekly
        missingok
        rotate 7
        postrotate
                reload smbd 2>/dev/null
        endscript
        compress
        notifempty

root@puppet:/etc/logrotate.d# 
for different application you need to create a file and config . we can execute the script with the help of postrotate  you need to mention the script location. 

root@puppet:/etc/logrotate.d#
this job execute by cron.daily  you can cehck the cron.daily entry under the cat /etc/cron.daily file 
 vi test
/root/sadeek/logs/logs.log {
    daily
    rotate 2
    missingok
    copytruncate
    olddir /root/sadeek/big
#    postrotate
#        /bin/sh /root/sadeek/rotate.sh
#    endscript
}
FOR MORE OPTION YOU CAN CHECK THE man logroate

3 comments:

  1. Very Good Info..

    ReplyDelete
  2. Ki pape!!! 14th february ko hi likh diya... gf ke saath dating pe jane ka tha bhai...
    ---> Greetings from Nepal!!! :) (S.S.)

    ReplyDelete
  3. Jaldi dekh liya BHai....Thanks :)

    ReplyDelete