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

Logrotate script not uploading to s3

· 52CE 我爱测

I am trying to use logrotate to upload log files from my rails and nginx commands once a day. When I run the logrotate command manually the files successfully upload, but it never does it on its own. I have tried using lastaction…

问题原文

原帖链接 · John · CC BY-SA 3.0

I am trying to use logrotate to upload log files from my rails and nginx commands once a day. When I run the logrotate command manually the files successfully upload, but it never does it on its own. I have tried using lastaction and also postrotate but neither actually uploads to S3. Is there something trivial that I'm missing?

/home/deploy/www/mysite.com/log/*log {
su
daily
dateext
dateformat _%Y_%m_%d
rotate 3
missingok
dateext
compress
delaycompress
notifempty
copytruncate
sharedscripts
lastaction
  rvmsudo passenger-config reopen-logs;
  /usr/bin/s3cmd sync /home/deploy/www/mysite.com/log/*.gz s3://mysite_com/logs/rails/
endscript
}

EDIT: Below is the corrected way of doing this. So instead of using the lastaction script, call a shell script instead.

lastaction
  ./rails_reload_and_upload.sh
endscript

which contains

#/bin/bash

./reload_rails_logs.sh
/usr/bin/s3cmd --config /home/username/.s3cfg sync /home/deploy/www/mysite.com/log/*.gz s3://mysite_com/logs/rails/

已采纳解答

原帖链接 · womble · CC BY-SA 3.0

I'd say it's most likely that either rvmsudo or s3cmd need extra environment variables to run successfully, which aren't set in the context of logrotate, but which are in your interactive shell session. I wouldn't be surprised if rvmsudo isn't available in the restrictive PATH which cron sets.

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

资料来源与适用范围

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

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

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