有没有一种方法可以使用logrotate旋转整个目录并压缩它,而不是只压缩某个特定目录中的文件?我尝试使用下面的配置,但没有工作。给予下面的错误消息:
设定:
/path/to/folder/test {
daily
rotate 5
missingok
compress
delaycompress
}
错误:
$logrotate -vf test.conf
reading config file test.conf
reading config info for /path/to/folder/test
Handling 1 logs
rotating pattern: /path/to/folder/test forced from command line (5
rotations)
empty log files are rotated, old logs are removed
error: error creating unique temp file: Permission denied
3条答案
按热度按时间kcrjzv8t1#
Logrotate只对目录中的单个文件进行操作,而不是将整个目录作为一个实体。最直接的解决方案是cronjob,它对该目录调用gzip之类的命令,然后根据需要移动/删除文件。
k0pti3hp2#
如果LOG_DIR没有其他可能被无意删除的tar文件,那么一个简单的shell脚本作为crontab应该可以运行:
zphenhs43#
您可以放置多个路径,这样您就可以在一个目录中为多个单独的日志使用同一个文件。然后,您可以编写一个脚本,在日志轮转文件前面添加新路径,并将其设置在cron上。