Koozali.org: home of the SME Server

Obsolete Releases => SME Server 8.x => Topic started by: fastxl on September 09, 2016, 06:47:44 PM

Title: logrotate Add date to rotated file name.
Post by: fastxl on September 09, 2016, 06:47:44 PM
How can I append the date to the filename of a log that I rotate daily? Right now it is only keeping 4 logs and just compressing them. I see other logs are keeping them longer with the date added to the file name. Currently I have a custom service in the /etc/logrotate.d

Thanks,
Eric
Title: Re: logrotate Add date to rotated file name.
Post by: Stefano on September 09, 2016, 07:23:25 PM
SME doesn't use etc/logrotate.d AFAIK
Title: Re: logrotate Add date to rotated file name.
Post by: fastxl on September 09, 2016, 07:48:31 PM
How does it rotate the system logs? I am using it as a syslog server, send info to it from a device. I setup it up based on this
 https://wiki.contribs.org/Syslog  (https://wiki.contribs.org/Syslog)
and I am rotating the logs based on this
https://linuxconfig.org/setting-up-logrotate-on-redhat-linux (https://linuxconfig.org/setting-up-logrotate-on-redhat-linux)
Now I would just like to add the date to the rotated filename.
Title: Re: logrotate Add date to rotated file name.
Post by: mmccarn on September 10, 2016, 01:11:49 PM
on SME9, /etc/logrotate.conf includes 'dateext'.  I don't see 'dateext' in /etc/logrotate.conf on SME8

Quote from: man logrotate
       dateext
              Archive  old versions of log files adding a daily extension like
              YYYYMMDD instead of simply adding a number.


I can't find any template for /etc/logrotate.conf -- so you should be able to add 'dateext' there immediately after the 'create' directive.

Quote from: /etc/logrotate.conf on SME 9
# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
dateext

# uncomment this if you want your log files compressed
#compress

...


[edit]
I suspect you can get this behavior for any single log by adding 'dateext' immediately after the 'create' command in the associated config file in /etc/logrotate.d

Title: Re: logrotate Add date to rotated file name.
Post by: fastxl on September 23, 2016, 09:05:23 PM
Here is what I ended up doing.


Here is what my script looked like.
Code: [Select]
cp -p /var/log/mylog.1.gz /home/e-smith/files/ibays/test/html/SME-share/mylog.1.`date +%Y.%m.%d_%H.%M.%S`.gz
And for the CRON Jobs I just followed these steps. https://wiki.contribs.org/Cron_entry (https://wiki.contribs.org/Cron_entry)

Seems to be working for me.