2

I am using logrotate to compress the log on daily basis and also delete the compressed log files older than 30 days . So here is my logrotate script :-

/var/www/html/application/logs/*.php
{
    daily
    missingok
    rotate 0
    maxage 30
    compress
    notifempty   
    dateext
}

I am creating separate files to log the PHP error on each day . It means a log files will be created on start of each day to store the PHP log of the same.

Here is the directory details :-

 -rw-rw-rw- 1 root   root       0 Dec 17  2015 log-2015-12-16.php
 -rw-rw-rw- 1 root   root     243 Dec 17  2015 log-2015-12-16.php-20151217.gz
 -rw-rw-rw- 1 root   root       0 Dec 18  2015 log-2015-12-17.php
 -rw-rw-rw- 1 root   root     243 Dec 18  2015 log-2015-12-17.php-20151218.gz
 -rw-rw-rw- 1 root   root       0 Dec 19  2015 log-2015-12-18.php

 -----
 -----

 -rw-r--r-- 1 root   root    1410 Aug 17 03:14 log-2016-08-16.php-20160817.gz
 -rw-r--r-- 1 root   root       0 Aug 18 04:21 log-2016-08-17.php
 -rw-r--r-- 1 root   root    1404 Aug 18 04:21 log-2016-08-17.php-20160818.gz
 -rw-r--r-- 1 root   root       0 Aug 19 04:28 log-2016-08-18.php
 -rw-r--r-- 1 root   root    1390 Aug 19 04:28 log-2016-08-18.php-20160819.gz
 -rw-r--r-- 1 root   root       0 Aug 20 03:34 log-2016-08-19.php
 -rw-r--r-- 1 root   root    1446 Aug 20 03:34 log-2016-08-19.php-20160820.gz
 -rw-r--r-- 1 root   root       0 Aug 21 03:37 log-2016-08-20.php
 -rw-r--r-- 1 root   root    1329 Aug 21 03:37 log-2016-08-20.php-20160821.gz
 -rw-r--r-- 1 root   root       0 Aug 22 03:27 log-2016-08-21.php
 -rw-r--r-- 1 root   root    1358 Aug 22 03:27 log-2016-08-21.php-20160822.gz
 -rw-r--r-- 1 root   root       0 Aug 23 03:37 log-2016-08-22.php
 -rw-r--r-- 1 root   root    1400 Aug 23 03:37 log-2016-08-22.php-20160823.gz
 -rw-r--r-- 1 root   root       0 Aug 24 03:27 log-2016-08-23.php
 -rw-r--r-- 1 root   root    1369 Aug 24 03:27 log-2016-08-23.php-20160824.gz
 -rw-r--r-- 1 root   root       0 Aug 25 03:24 log-2016-08-24.php
 -rw-r--r-- 1 root   root    1335 Aug 25 03:24 log-2016-08-24.php-20160825.gz
 -rw-r--r-- 1 root   root   27399 Aug 25 23:01 log-2016-08-25.php
 -rw-r--r-- 1 root   root    3426 Aug 26 02:06 log-2016-08-26.php

Please note that we have empty php files also , which should be deleted after creating compress file of own and on next rotation if any compresses files are older than 30 days then it also should be deleted .

I am unable to find the error on this logrotate script . Can you please give a solution that what I am missing or doing wrong .

  • @the_velour_fog , You can see that logrotate utility is doing their work except deleting it . – Deepak Dixit Aug 26 '16 at 7:45
  • @the_velour_fog Yes , thats the place where I stores my PHP log. – Deepak Dixit Aug 26 '16 at 7:48
  • You have rotate 0, so this would not age away files older than 30 days any way you do it. I assume there's no way around the datestamp in the log file coming from the application? (I'd be tempted to do something that makes logrotate believe that's the timestamp it put in there itself, but that probably means renaming the logfile for the current day.) – Ulrich Schwarz Aug 26 '16 at 9:26
2

Created a file "apache" in /etc/logrotate.d/

/usr/local/apache/logs/*log {
 daily
 rotate 52
 compress
 missingok
 notifempty
 sharedscripts
 postrotate
        /usr/local/apache/bin/apachectl restart > /dev/null 2>/dev/null || true
 endscript
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.