大网数据广告活动
服务器运维问答

Logrotate appends "1" at the end of compressed file name

· 52CE 我爱测

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/dbna…

问题原文

原帖链接 · 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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-06-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0 / CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。