Jac*_*lla 17 ruby-on-rails heroku
我经常需要克隆生产数据来调查错误.即使有一个简单的数据库大小heroku db:拉(点击)需要5分钟以上,似乎很有可能失败.是否有另一种方法来提取数据库?
还将赞赏替代流程/文章的图书馆.
mik*_*son 23
查看pgbackups.它已经取代了Heroku bundle命令,并且会给你一个相当于mysqldump的postgres.对于大型数据集,这比Taps更加文明.
heroku pgbackups:capture
Run Code Online (Sandbox Code Playgroud)
将创建一个转储文件并存储它.要下载转储文件,您需要使用的URL
heroku pgbackups:url b001 (or whatever the id number of the backup is)
Run Code Online (Sandbox Code Playgroud)
这将返回一个url,您可以从中下载转储.如果你愿意,可以将它粘贴到Firefox中,或者像他们建议的那样使用curl/wget.使用pg_restore将转储文件加载到数据库中,如文档中所述:
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U test_user -d myapp_development /home/mike/Downloads/b001.dump
Run Code Online (Sandbox Code Playgroud)
pg_restore:连接到数据库以进行还原
Jac*_*lla 12
我创建了一个自动执行此过程的shell脚本(基于Mike Williamson的回答).
https://gist.github.com/921535
#!/bin/bash
# Best use case is to create a file "update_local_db.sh" in your project folder and then
# call the command with bash update_local_db
# Follow me: @jackkinsella
function LastBackupName () {
heroku pgbackups | tail -n 1 | cut -d"|" -f 1
}
# This part assumes you have a low limit on no. of backups allowed
old_backup=$(LastBackupName)
heroku pgbackups:destroy $old_backup
heroku pgbackups:capture
new_backup=$(LastBackupName)
curl $(heroku pgbackups:url $new_backup) > temporary_backup.dump
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U REPLACE_WITH_YOUR_USER -d REPLACE_WITH_YOUR_DB_NAME temporary_backup.dump
rm -f temporary_backup.dump
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3593 次 |
| 最近记录: |