0

I have on my server more file rotate, but when I want to compress it, i Have an extension 1.gz, but I just want .gz

These files are automatically rotate by the application:

server.log.2023-03-16
server.log.2023-03-15
server.log.2023-03-14

My result:

server.log.2023-03-16.1.gz
server.log.2023-03-15.1.gz
server.log.2023-03-14.1.gz

I want:

server.log.2023-03-16.gz
server.log.2023-03-15.gz
server.log.2023-03-14.gz

My logrotate file:

#/var/log/application/*/server*.log.* {
  daily
  rotate 14
  compress
  delaycompress
  missingok
}

How can I fix this?

3
  • logrotate numbers logs, so it can rotate. It's not quite clear what you want? Don't you want to preserve older logs? If you don't want to preserve older logs, why compress them? Commented Apr 21, 2023 at 11:59
  • I Marcus,I just want to compress logs.
    – sam
    Commented Apr 30, 2023 at 9:48
  • 1
    Then why use logrotate? You could just run gzip on all the relevant log files.
    – Kusalananda
    Commented Jan 15 at 16:26

1 Answer 1

-1

if you want your rotated log file to looks like -- > server.log.2023-03-16.gz just add

dateext
dateformat .%Y-%m-%d

to your logrotate file.

2
  • Note that the user's logrotate pattern matches the compressed log files. You may want to amend your answer to take this into account.
    – Kusalananda
    Commented Jan 15 at 16:27
  • Also OP's logs already have the date suffix added by the application that does the logging, so this will probably result in a file like server.log.2023-03-16.2023-03-16.gz
    – muru
    Commented Jan 16 at 7:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .