我在使用 FileUtils#sh 的 Rails 4 应用程序中运行 Rake 命令时遇到问题。我使用 RVM 作为我的版本管理器,但似乎无法找出问题所在。我得到的错误是:
$ rake db:clone_production:to_local --trace
** Invoke db:clone_production:to_local (first_time)
** Execute db:clone_production:to_local heroku pgbackups:capture --expire -r production
Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0
rake aborted!
Command failed with status (18): [heroku pgbackups:capture --expire -r produ...]
/Users/trevor/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.1.0/lib/rake/file_utils.rb:54:in `block in create_shell_runner'
... Some more stack trace ...
其他 Rake 任务正常工作,$ rake db:migrate
但我似乎无法运行 shell 脚本。Rake 任务如下所示:
# ./lib/tasks/db.rake
namespace :db do
...
namespace :clone_production do
desc "Clone production database to local database"
task :to_local do
sh "heroku pgbackups:capture --expire -r production"
file = "tmp/db/backup_#{ Time.now.getutc.to_s.gsub(/ /, /_/) }.dump"
sh "curl -o #{ file } `heroku pgbackups:url -r production`"
sh "pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d myapp_development #{ file }"
end
end
end
我的 PATH 看起来不错:/Users/trevor/.rvm/gems/ruby-2.0.0-p195@myapp/bin:/Users/trevor/.rvm/gems/ruby-2.0.0-p195@global/bin:/Users/trevor/.rvm/rubies/ruby-2.0.0-p195/bin:/Users/trevor/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/X11/bin:/Users/trevor/workspace/adt-bundle-mac/sdk/tools:/Users/trevor/workspace/adt-bundle-mac/sdk/platform-tools
我正在使用这些版本Rake - 10.1.0
、Rails - 4.0.0
和ruby - 2.0.0-p195
。
#./.ruby-version
2.0.0-p195
#./.ruby-gemset
myapp