美文网首页
Linux日志文件总管 - logrotate

Linux日志文件总管 - logrotate

作者: 9682f4e55d71 | 来源:发表于2018-10-23 16:39 被阅读16次

https://linux.cn/article-4126-1.html

  1. 将下面的内容新建文件website放到
    /etc/logrotate.d/
 /data/logs/*.log {
         daily  # 每天备份
         missingok # 忽略错误
         rotate 3 # 保留的备份数
         olddir  /data/logs/logbk   # 备份目录
         dateext  # 备份文件以日期命名
         compress  # 压缩
         delaycompress  # 延时压缩, 下次执行时压缩
         notifempty
         create 640 www www
         sharedscripts
         postrotate
                 if [ -f /var/run/nginx.pid ]; then
                         kill -USR1 `cat /var/run/nginx.pid`
                 fi
         endscript
 }
  1. 测试(dry run)
    logrotate website -d

  2. 强制执行 -f
    logrotate website -vf

相关文章

网友评论

      本文标题:Linux日志文件总管 - logrotate

      本文链接:https://www.haomeiwen.com/subject/doyazftx.html