/etc/logrotate.d/nginx 配置备份目录的示例
时间: 2023-09-18 16:12:49 浏览: 86
这个问题让我有些困惑,因为它并不是一个问题,而是一个关于特定文件的说明。 "/etc/logrotate.d/nginx" 是一个文件路径,它包含用于配置 logrotate 工具轮换 NGINX 日志文件的脚本。备份目录可以通过这个脚本中的“postrotate”命令指定。这个命令会在轮换日志文件之后执行,所以备份目录将保存上一次的日志文件。这是一个备份目录的示例:
postrotate
test ! -x /usr/sbin/nginx || /usr/sbin/nginx -s reopen >/dev/null 2>&1
# create new directory for log files
DATE=$(date +'%Y%m%d%H%M%S')
mkdir -p /var/log/nginx/backups/$DATE
# copy log files to backup directory
cp -p /var/log/nginx/* /var/log/nginx/backups/$DATE/
# delete old backups
find /var/log/nginx/backups/ -type d -mtime +7 -exec rm -rf {} \;
endscript
请注意,这只是一个示例,并且可能需要根据您的具体需求进行调整。
相关问题
编写一个/etc/logrotate.d/nginx的配置文件
好的,这是一个nginx的日志轮询配置示例:
```
/var/log/nginx/*.log {
daily
missingok
rotate 52
compress
delaycompress
notifempty
create 0640 nginx adm
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
endscript
}
```
这个配置文件将会对nginx的日志文件进行日志轮询,保存最新的52个日志文件,对旧日志进行压缩。其中sharedscripts表示在轮询的前后执行同一个脚本,postrotate中的命令表示给nginx主进程发送USR1信号重新打开日志文件。
阅读全文
相关推荐
![conf](https://img-home.csdnimg.cn/images/20250102104920.png)
![md](https://img-home.csdnimg.cn/images/20250102104920.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)