【发布时间】:2015-03-21 23:21:45
【问题描述】:
我一直在使用 rake 任务将我的数据库从 heroku staging 快速转储并恢复到本地开发环境。
新的 pg:backups 破坏了任务,我不知道如何修复它。
旧的 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,它会返回一个备份 ID 表:
=== 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 任务来说似乎有点过头了。
【问题讨论】: