You need to enable JavaScript to run this app. Linux服务器bash无法识别星号通配符导致logrotate同步失败
优惠活动
大模型
产品
解决方案
定价
更多

Linux服务器bash无法识别星号通配符导致logrotate同步失败

logrotate 配置S3日志同步运行异常

基本环境与配置说明

我有一台运行Linux系统的实例,通过cron任务调度logrotate完成日志切割流程,配套逻辑是将切割压缩后的SSL相关日志传输到自己AWS账户下的S3存储桶中。当前运行异常的logrotate自定义配置内容如下:

/var/log/httpd/*log {
    compress
    compresscmd /bin/gzip
    compressoptions -9
    compressext .gz

    dateext
    dateformat _%Y-%m-%d.log.%s

    rotate 14
    nomail
    missingok
    #size 5k
    create 640 root root

    sharedscripts
    postrotate
    sudo /sbin/service httpd reload > /dev/null 2>/dev/null || true

    BUCKET=*********
    SITE=*******

    sudo /usr/bin/s3cmd sync /var/log/httpd/access_log_*.gz s3://${BUCKET}/${SITE}/access_logs/access_logs/
    sudo /usr/bin/s3cmd sync /var/log/httpd/ssl_access_log_*.gz s3://${BUCKET}/${SITE}/access_logs/ssl_access_logs/
    sudo /usr/bin/s3cmd sync /var/log/httpd/error_log_*.gz s3://${BUCKET}/${SITE}/error_logs/error_logs/
    sudo /usr/bin/s3cmd sync /var/log/httpd/ssl_error_log_*.gz s3://${BUCKET}/${SITE}/error_logs/ssl_error_logs/
    sudo /usr/bin/s3cmd sync /var/log/httpd/ssl_request_log_*.gz s3://${BUCKET}/${SITE}/request_logs/ssl_request_logs/

endscript
}

运行时输出的报错信息

配置执行过程中,使用的s3cmd工具输出如下异常:

ERROR: Parameter problem: Invalid source: '/var/log/httpd/access_log_*.gz' is not an existing file or directory
ERROR: Parameter problem: Invalid source: '/var/log/httpd/ssl_access_log_*.gz' is not an existing file or directory
ERROR: Parameter problem: Invalid source: '/var/log/httpd/error_log_*.gz' is not an existing file or directory
ERROR: Parameter problem: Invalid source: '/var/log/httpd/ssl_error_log_*.gz' is not an existing file or directory
ERROR: Parameter problem: Invalid source: '/var/log/httpd/ssl_request_log_*.gz' is not an existing file or directory
error: error running shared postrotate script for '/var/log/httpd/*log '

已知现象与已排查内容

  • 异常表现:postrotate脚本执行时无法识别路径中的星号通配符,无法匹配同前缀的所有压缩日志文件,导致上传流程中断
  • 已完成的验证项:
    • 通配符指向的目标目录下,对应前缀的压缩日志文件确实存在
    • 整个logrotate脚本以root身份运行,不存在目录访问权限不足的问题
  • 当前状态:始终无法定位故障原因,需要排查该问题的产生根源

内容的提问来源于stack exchange,提问作者yaronp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.12 03:27:03