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
-
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
-
SME doesn't use etc/logrotate.d AFAIK
-
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.
-
on SME9, /etc/logrotate.conf includes 'dateext'. I don't see 'dateext' in /etc/logrotate.conf on SME8
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.
# 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
-
Here is what I ended up doing.
- Create a script that copies the file to a network share (or it could be another directory) and adds the date to the file name.
- Add a "job" to the CRON Daily so that it rotates everyday.
Here is what my script looked like.
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.