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!

1 Answer 1

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).

6
  • and what about Max log file size shouldn't be 100Mb right? Jan 7, 2020 at 2:12
  • so if I use *.log then it will rotate smatfox.log only and not smartfox.log.1, right? Jan 7, 2020 at 4:02
  • Right, but your files do not end with .log but with the date followed by an integer. About maxsize, please see stackoverflow.com/questions/20162176/…, and choose the option that best fits your needs. Jan 7, 2020 at 4: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 Jan 8, 2020 at 2:13
  • 1
    Your concern has more to do with smartfox itself (with its way to log information) than with logrotate. Please, take a look at 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...) Jan 9, 2020 at 3:10

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.