Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dateformat %H doesn't work #551

Open
Tracked by #576
Forza-tng opened this issue Oct 18, 2023 · 2 comments · May be fixed by #554
Open
Tracked by #576

Dateformat %H doesn't work #551

Forza-tng opened this issue Oct 18, 2023 · 2 comments · May be fixed by #554

Comments

@Forza-tng
Copy link

I am using logrotate-3.21.0 on Gentoo Linux AMD64.

The problem i am experiencing is that the hour is always 12, no matter when logrotate runs. This is evident if we look at the timestamps from ls:

-rw------- 1 root root 40320853 Oct 18 14:02 bees.3t_backup.log
-rw------- 1 root root  3587829 Oct 17 21:06 bees.3t_backup.log-20231016-120700.zst
-rw------- 1 root root  2901724 Oct 18 07:01 bees.3t_backup.log-20231017-120111.zst
-rw------- 1 root root  6894067 Oct 18 13:00 bees.3t_backup.log-20231017-120112.zst
-rw------- 1 root root  4650221 Oct 18 03:01 bees.3t_backup.log-20231017-120123.zst
-rw------- 1 root root  3872284 Oct 18 00:33 bees.3t_backup.log-20231017-123328.zst

My logrotate.conf:

create
minsize 1M
maxsize 100M
notifempty
maxage 30
rotate -1
dateext
dateyesterday
dateformat -%Y%m%d-%H%M%S
compress
compresscmd /usr/bin/zstd
uncompresscmd /usr/bin/unzstd
compressext .zst
compressoptions --long --ultra -15 -T4
nomail

include /etc/logrotate.d

/etc/logrotate.d/bees

/var/log/bees/*.log {
    copytruncate
    notifempty
    missingok
}

Logrotate is run via /etc/cron.hourly/logrotate

#!/bin/sh
echo `date` >> /var/log/logrotate.log
/usr/bin/logrotate /etc/logrotate.conf >> /var/log/logrotate.log 2>&1
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
echo `date` >> /var/log/logrotate.log
exit $EXITVALUE
cgzones added a commit to cgzones/logrotate that referenced this issue Oct 19, 2023
Instead of setting the hour unconditionally to 12 (noon), let mktime(3)
detect whether DST is in effect at the specific time.

Closes: logrotate#551
@cgzones cgzones linked a pull request Oct 19, 2023 that will close this issue
@cgzones
Copy link
Member

cgzones commented Oct 19, 2023

Since you rotate hourly, you shouldn't use dateyesterday but datehourago.

Otherwise #554 removes the hardcoded noon time.

@Forza-tng
Copy link
Author

Since you rotate hourly, you shouldn't use dateyesterday but datehourago.

Otherwise #554 removes the hardcoded noon time.

Thank you. I removed dateyesterday and it works. I see why the hour was set to 12.

I don't actually want to rotate every hour, but sometimes certain logs grow quickly and I want to rotate them early (max size).

After reading the dst issue, I decided to set TZ=UTC-0 which should not use DST. Am I right in thinking this?

@cgzones cgzones mentioned this issue Jan 5, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants