2

I have created log rotation but it seems not working for me, as it's creating a large number of files like "smartfox.log.2020-01-05-07.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1"

Furthermore, rotate 3 and maxsize 100M is also not working as I am seeing files older than 3 days and more than 100M.

If an not wrong following log rotation should delte file older than 3 days and keep only 100M log file:

admin@ip-172-20-44-75:/etc/logrotate.d$ cat   /etc/logrotate.d/smartfox-qa
/var/log/cog-qa/smartfox-qa/*{

        rotate 3
        copytruncate
        missingok
        notifempty
        delaycompress
        maxsize 100M
        daily
        create 0644 root root
}

admin@ip-172-20-44-75:/var/log/cog-qa/smartfox-qa$ ls -lthr

-rw-r--r-- 1 root root    0 Jan  6 03:18 smartfox.log.2020-01-05-13.1.1.1.1.1.1.1.1.1.1.1.1.1
-rw-r--r-- 1 root root 655M Jan  6 03:18 smartfox.log.2020-01-05-14.1.1.1.1.1.1.1.1.1.1.1.1.1
-rw-r--r-- 1 root root    0 Jan  6 03:18 smartfox.log.2020-01-05-14.1.1.1.1.1.1.1.1.1.1.1.1
-rw-r--r-- 1 root root 656M Jan  6 03:18 smartfox.log.2020-01-05-15.1.1.1.1.1.1.1.1.1.1.1.1
-rw-r--r-- 1 root root    0 Jan  6 03:18 smartfox.log.2020-01-05-15.1.1.1.1.1.1.1.1.1.1.1
-rw-r--r-- 1 root root 653M Jan  6 03:18 smartfox.log.2020-01-05-16.1.1.1.1.1.1.1.1.1.1.1
-rw-r--r-- 1 root root    0 Jan  6 03:18 smartfox.log.2020-01-05-16.1.1.1.1.1.1.1.1.1.1
-rw-r--r-- 1 root root 661M Jan  6 03:18 smartfox.log.2020-01-05-17.1.1.1.1.1.1.1.1.1.1
-rw-r--r-- 1 root root    0 Jan  6 03:18 smartfox.log.2020-01-05-17.1.1.1.1.1.1.1.1.1
-rw-r--r-- 1 root root 660M Jan  6 03:19 smartfox.log.2020-01-05-18.1.1.1.1.1.1.1.1.1
-rw-r--r-- 1 root root    0 Jan  6 03:19 smartfox.log.2020-01-05-18.1.1.1.1.1.1.1.1
-rw-r--r-- 1 root root 665M Jan  6 03:19 smartfox.log.2020-01-05-19.1.1.1.1.1.1.1.1
-rw-r--r-- 1 root root    0 Jan  6 03:19 smartfox.log.2020-01-05-19.1.1.1.1.1.1.1
-rw-r--r-- 1 root root 658M Jan  6 03:19 smartfox.log.2020-01-05-20.1.1.1.1.1.1.1
-rw-r--r-- 1 root root    0 Jan  6 03:19 smartfox.log.2020-01-05-20.1.1.1.1.1.1
-rw-r--r-- 1 root root 675M Jan  6 03:19 smartfox.log.2020-01-05-21.1.1.1.1.1.1
-rw-r--r-- 1 root root    0 Jan  6 03:19 smartfox.log.2020-01-05-21.1.1.1.1.1
-rw-r--r-- 1 root root 656M Jan  6 03:19 smartfox.log.2020-01-05-22.1.1.1.1.1
-rw-r--r-- 1 root root    0 Jan  6 03:20 smartfox.log.2020-01-05-22.1.1.1.1
-rw-r--r-- 1 root root 660M Jan  6 03:20 smartfox.log.2020-01-05-23.1.1.1.1
-rw-r--r-- 1 root root    0 Jan  6 03:20 smartfox.log.2020-01-05-23.1.1.1
-rw-r--r-- 1 root root 649M Jan  6 03:20 smartfox.log.2020-01-06-00.1.1.1
-rw-r--r-- 1 root root    0 Jan  6 03:20 smartfox.log.2020-01-06-00.1.1
-rw-r--r-- 1 root root 662M Jan  6 03:20 smartfox.log.2020-01-06-01.1.1
-rw-r--r-- 1 root root    0 Jan  6 03:20 smartfox.log.2020-01-06-01.1
-rw-r--r-- 1 root root 661M Jan  6 03:20 smartfox.log.2020-01-06-02.1
-rw-r--r-- 1 root root    0 Jan  6 03:20 smartfox.log.2020-01-06-02

Please let me know where I am wrong!

Ashish Karpe
  • 277
  • 2
  • 5
  • 19

1 Answers1

3

It seems that you are rotating not only the files you probably want to (smartfox.log.????-??-??-??) but all the files in the smartfox-qa folder. If so, you should correct your wildcard expression

/var/log/cog-qa/smartfox-qa/smartfox.log.????-??-??-?? {
    rotate 3
    copytruncate
    missingok
    notifempty
    delaycompress
    maxsize 100M
    daily
    create 0644 root root
}

Please note that man logrotate warns explicitely about the use of wildcards

Please use wildcards with caution. If you specify *, logrotate will rotate all files, including previously rotated ones. A way around this is to use the olddir directive or a more exact wildcard (such as *.log).

J.M. Robles
  • 925
  • 6
  • 9
  • and what about Max log file size shouldn't be 100Mb right? – Ashish Karpe Jan 07 '20 at 02:12
  • so if I use *.log then it will rotate smatfox.log only and not smartfox.log.1, right? – Ashish Karpe Jan 07 '20 at 04:02
  • Right, but your files do not end with .log but with the date followed by an integer. About maxsize, please see https://stackoverflow.com/questions/20162176/centos-linux-setting-logrotate-to-maximum-file-size-for-all-logs, and choose the option that best fits your needs. – J.M. Robles Jan 07 '20 at 04:58
  • your files do not end with .log but with the date followed by an integer....That's the concern, normally it should create the only smatfox.log but I am not sure date followed by integers is generated due to wrong (*.log) log rotation or it's application generating it how to troubleshoot this issue – Ashish Karpe Jan 08 '20 at 02:13
  • Bty above-mentioned log rotation in my question will just rotate old log but won't delete old logs right? so any solution to delete old logs? – Ashish Karpe Jan 08 '20 at 02:18
  • 1
    Your concern has more to do with smartfox itself (with its way to log information) than with logrotate. Please, take a look at http://docs2x.smartfoxserver.com/GettingStarted/log-configuration . About the removal of old files, that behaviour is configured by the "rotate" parameter. Don't doubt consulting man 8 logrotate (rotate count - Log files are rotated count times before being removed or...) – J.M. Robles Jan 09 '20 at 03:10