Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a script which runs as a cronjob every 30 mins and takes mysqldump of some tables. The dump files are stored in /var/log/ as


I'm using logrotate for file rotation, the config file has the following structure:

/var/log/mysqldump/dbname/tablename/*.sql {
  rotate 30

Now my problem is that although logrotate works fine but it's appending "1" or "2" at the end of the gzipped files, for instance this is what I have


I execute logrotate from within the script as

logrotate -f /path/to/mysqldump-logrotate.conf

What am I doing wrong here?

share|improve this question

4 Answers 4

up vote 2 down vote accepted

Logrotate will default to adding a number to the file. This is so that if it's used for filenames like e.g. /var/log/messages, the rotated logs will be named /var/log/messages.0 and /var/log/messages.1 etc.

Your situation is somewhat different since you already have a timestamp in the filename, so that the extension is unnecessary. Logrotate doesn't have an option to not use an extension - but there's a workaround that you might use.

The alternative to using a number sequence is to use a date/timestamp. This defaults to -%Y%m%D, e.g. -20140618. But you can configure what the string should look like - which in your case would be an empty string. You'd do this using the following configuration:

dateext          # to use dateformat string instead of sequential numbers
dateformat ''    # to use an empty string as the dateext
share|improve this answer
Thanks, I should probably set logrotate to run from cron. – reflektor Jun 19 '14 at 6:04
On Centoss 6.6, if you use dateformat '', logrotate appends the actual quotes to the file name. I get myserver.log''.gz – lreeder Nov 19 '14 at 17:13

You are doing nothing wrong this is the default and expected behaviour. If you want a different extension e.g a date then you can specify dateext

dateext Archive old versions of log files adding a daily extension like YYYYMMDD instead of simply adding a number. The extension may be configured using the dateformat option.

From the above you can also see the defaut behaviour is expected to be simply adding a number.

share|improve this answer

You have the option rotate 30 in your configuration, which means that 30 older versions are kept before deleting. This number is how logrotate differentiate the versions. So, in effect you are doing nothing wrong and the program behaves as designed.

share|improve this answer

This is normal behaviour for logrotate as you described it.

Normally you would want to logrotate your logfiles not via script but via cronjob(s).

For gzipping the files via logrotate you could not include the date and rather let logrotate handle the dateext.

So for a "solution" to your issue you could use the logrotate options


and skip writing the day into your filename.

This would "remove" the 1 you see in the filename.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.