[英]Heroku Rake task not running shell script
I have this Rake task that works locally: 我有在本地工作的Rake任务:
namespace :backup_to_s3 do
task run: :environment do
puts "Started S3 backup"
# create .pgpass so we don't have to enter the password
entry = "#{ENV['RDS_DB_HOSTNAME']}:*:*:#{ENV['RDS_DB_SUPER_USERNAME']}:#{ENV['RDS_DB_SUPER_PASSWORD']}"
`echo '#{entry}' > ~/.pgpass;
chmod 0600 ~/.pgpass;
bash backup_to_s3.sh`
puts "Finished S3 backup"
end
end
Notice that it makes a call to run a shell script. 请注意,它会调用以运行Shell脚本。 Here's that shell script:
这是shell脚本:
#!/bin/bash
backupTime=`date +%Y%m%d-%H:%M`
S3Bucket=$S3_BUCKET_NAME
RDSHostname=$RDS_DB_HOSTNAME
RDSUsername=$RDS_DB_SUPER_USERNAME
RDSDatabaseName=$RDS_DB_NAME
pg_dump -Fc ${RDSDatabaseName} -h ${RDSHostname} -U ${RDSUsername} --no-password | gzip -9 | \
s3cmd put - s3://${S3Bucket}/postgres.${RDSDatabaseName}.dump.${backupTime}.gz
Like I said this all works locally, and the puts
logging statements work. 就像我说的那样,这一切都在本地工作,而
puts
日志语句也可以工作。 On Heroku, the task runs, but the puts
statements are executed immediately, seeming to indicate that the system calls and the shell script are not being run. 在Heroku上,任务运行,但是
puts
语句立即执行,似乎表明系统调用和shell脚本未在运行。
I'm confused as to why this isn't working! 我很困惑为什么这不起作用!
UPDATE 7/15 更新7/15
I found that you can set the PGPASSWORD
environment variable and avoid creating the .pgpass
file. 我发现您可以设置
PGPASSWORD
环境变量,并避免创建.pgpass
文件。 The Rake task is still not executing the shell script. Rake任务仍未执行Shell脚本。
Heroku doesn't provide you with a traditional virtual private server, so I would not assume that you have access to write to the home directory. Heroku没有为您提供传统的虚拟专用服务器,因此我不认为您有权写入主目录。 It's very likely that you might be getting a permission denied error when creating the
.pgpass
file. 创建
.pgpass
文件时,很可能会收到拒绝权限的错误。
Try placing your file in the relative tmp/
directory of your rails project instead. 尝试将文件放置在rails项目的相对
tmp/
目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.