LoginSignup
12
11

More than 5 years have passed since last update.

HerokuでStaging環境のデータベースをProduction環境にコピーする手順

Posted at

事前準備

remoteオプションを追加する

--remote staging --remote productionのようなオプションで、Staging環境とProduction環境を使い分けられるようにしておきます。
詳細は以下のブログ記事を参照してください。

PG Backupsアドオンを追加する

Staging, ProductionともにHerokuのPG Backupsアドオンを追加します。(無料)

手順

PG Backupsのcaptureとrestoreを使って、データをトランスファーします。
間違って逆方向にコピーしたりしないよう、二人で作業することを推奨します。

# サイトにメンテナンスモードに変更
$  heroku maintenance:on --remote staging
$  heroku maintenance:on --remote production

# Staging環境のバックアップ状況を確認
$  heroku pgbackups --remote staging

# Staging環境のデータをコピー(バックアップ)
$  heroku pgbackups:capture --remote staging

# バックアップが増えたことを確認
$  heroku pgbackups --remote staging

# Staging => Productionへのコピー(リストア)を実施
$  heroku pgbackups:restore DATABASE `heroku pgbackups:url --remote staging` --remote production

# Production環境に接続してデータがちゃんとコピーされたことを確認
$  heroku console --remote production

# サイトのメンテナンスモードを解除
$  heroku maintenance:off --remote production
$  heroku maintenance:off --remote staging

参考

PG Backupsのコマンドマニュアル
https://devcenter.heroku.com/articles/pgbackups

12
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
11