我一直在使用rake任务快速转储数据库,并将数据库从heroku暂存还原到本地dev环境。
新的pg:备份已经打破了任务,我不知道如何解决它。
旧db.rake:
namespace :db do
desc "Restore the DB from a production"
task :dump do
Bundler.with_clean_env {sh "heroku pgbackups:capture --expire --app myapp"}
Bundler.with_clean_env {sh "curl -o latest.dump `heroku pgbackups:url --app myapp`"}
puts `pg_restore --verbose --clean --no-acl --no-owner -h localhost -d #{Rails.configuration.database_configuration["development"]["database"]} latest.dump`
puts `rm latest.dump`
end
end新的(不起作用):
namespace :db do
desc "Restore the DB from a production"
task :new_dump do
Bundler.with_clean_env {sh "heroku pg:backups capture --app myapp"}
Bundler.with_clean_env {sh "curl -o latest.dump `heroku pg:backups public-url NEEDS_ID_OF_LAST_BACKUP_HERE --app myapp`"}
puts `pg_restore --verbose --clean --no-acl --no-owner -h localhost -d #{Rails.configuration.database_configuration["development"]["database"]} latest.dump`
puts `rm latest.dump`
end
end它不再起作用的原因是Heroku拒绝使用heroku pgbackups:url命令,该命令用于返回最新备份的URL。
每个https://devcenter.heroku.com/articles/heroku-postgres-backups最接近的等效值是运行heroku pg:backups,它返回一个备份is表:
=== Backups
ID Backup Time Status Size Database
---- ------------------------- ---------------------------------- ------ --------
b005 2015-03-21 23:04:16 +0000 Finished 2015-03-21 23:04:20 +0000 82.1kB VIOLET
b004 2015-03-21 22:55:33 +0000 Finished 2015-03-21 22:55:34 +0000 82.1kB VIOLET我知道我可以编写一个解析器来从表中提取ID,但是对于一个简单的rake任务来说,这似乎太过了。
发布于 2015-04-25 01:21:05
解决办法是超级成功,但有效.
Bundler.with_clean_env {sh "rake db:drop"}
Bundler.with_clean_env {sh "rake db:create"}
Bundler.with_clean_env {sh "heroku pg:backups capture --app #{heroku_server}"}
db_id = nil
Bundler.with_clean_env do
db_list = `heroku pg:backups -a #{heroku_server}`
res = db_list.split("\n")[3]
db_id = res.split(" ")[0].strip
p "Restoring backup with id #{db_id}"
restore_url = `heroku pg:backups public-url #{db_id} -a "#{heroku_server}"`
restore_url = URI.extract(restore_url)
restore_url = restore_url[0]
p `curl -o latest.dump "#{restore_url}"`
end
puts `pg_restore --verbose --clean --no-acl --no-owner -h localhost -d dbname-dev latest.dump`
puts `rm latest.dump`https://stackoverflow.com/questions/29189192
复制相似问题