问题原文
原帖链接 · reflektor · CC BY-SA 4.0
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
/var/log/mysqldump/dbname/tablename/2014-06-15-18-30-dbname-tablename.sql
/var/log/mysqldump/dbname2/tablename2/2014-06-15-19-00-dbname2-tablename2.sql
I'm using logrotate for file rotation, the config file has the following structure:
/var/log/mysqldump/dbname/tablename/*.sql {
daily
rotate 30
compress
nocreate
}
Now my problem is that although logrotate works fine, it's appending "1" or "2" at the end of the gzipped file names, for instance this is what I have
/var/log/mysqldump/dbname2/tablename2/2014-06-15-19-30-dbname2-tablename2.sql.1.gz
/var/log/mysqldump/dbname1/tablename1/2014-06-15-19-00-dbname1-tablename1.sql.2.gz
I execute logrotate from within the script as
logrotate -f /path/to/mysqldump-logrotate.conf
What am I doing wrong here?
已采纳解答
原帖链接 · Jenny D · CC BY-SA 3.0
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
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
