Star Hype News.

Premium celebrity moments with standout appeal.

news

Logrotate is deleting my logs

By James Williams

I have this logrotate config which is not in /etc/logrotate.d

/path/to/my/logfile.log { su root root daily maxage 365000 copytruncate dateext dateformat -%d.%m.%Y
}

I run it crontab:

59 23 * * * root logrotate /path/to/my/logrotate/config > /some/logfile

Every day I can see only two log files, the truncated logfile.log and a new logfile.log-DD-MM-YYYY file. All older logs get deleted.

Every day I copy the new rotated file and give it a new name, the next day logs from the previous day are gone. How can I fix this?

2 Answers

You need the following line in your configuration:

rotate <count>

Replace <count> with the number of times you'd like the log to be rotated before it removes the oldest rotated log. So five times would be:

/path/to/my/logfile.log { su root root daily maxage 365000 copytruncate dateext dateformat -%d.%m.%Y rotate 5
}

You can check your logrotate man page for more information.

1

You have not used the rotate directive to specify how many rotations of log you want to keep i.e. how many rotations to do. If not mentioned, the default value of the parameter is 0.

From config.c of logrotate source, check rotateCount:

int readAllConfigPaths(const char **paths)
{ int i, result = 0; const char **file; struct logInfo defConfig = { .pattern = NULL, .files = NULL, .numFiles = 0, .oldDir = NULL, .criterium = ROT_SIZE, .threshhold = 1024 * 1024, .minsize = 0, .maxsize = 0, .rotateCount = 0, ... <truncated>

A value of 0 for rotate will make logrotate to remove old versions of the log, rather than to rotate. This is happening in your case.

So, use a sane value for the rotate directive to meet your need. For example, a value of 7 would do 7 rotations. If the logs are big in size, look at compress also.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy