3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pgbackup の仕組み

Posted at

手動バックアップ

pg:backupsコマンドで実行される。アプリケーションのDATABASE_URL設定がデータベース選択の基準となる。

$ heroku pg:backups capture -a sushi
Hit Ctrl-C at any time to stop watching progress; the backup will
continue running. Stop a running backup with heroku pg:backups cancel.

HEROKU_POSTGRESQL_BLACK (DATABASE_URL)  ----backup--->  b251

Running... done

プランによって保持可能なバックアップの数が違う。
保有可能なバックアップ数を越えた場合、自動で古いものから順に削除されていく。

Plan 保有可能なバックアップ数
Hobby-Dev 2
Hobby-Basic 5
Standard-* 25
Premium-* 50
Enterprise 50

スケジュールの設定

定期的にバックアップを取りたい場合、スケジューラから設定可能。

$ heroku pg:backups schedule DATABASE_URL --at '02:00 Asia/Tokyo' -a sushi

時刻は00分で指定しないとエラーになって怒られる。
スケジューラの設定は一つのみ有効で、新しく設定を追加した際には前のスケジュールが削除されるっぽい。

スケジューラの解除はunscheduleコマンドで。

$ heroku pg:backups unschedule DATABASE_URL --app sushi

現在のスケジュール一覧はschedulesコマンドで確認する(こっちは複数形)。

$ heroku pg:backups schedules --app sushi
Current backup schedules:
RED: daily at 2:00 (America/Los_Angeles)

バックアップの管理

バックアップの一覧はpg:backupsコマンドで確認できる。

$ heroku pg:backups --app sushi
=== Backups
ID    Backup Time                Status                              Size    Database
----  -------------------------  ----------------------------------  ------  --------
b013  2015-03-18 19:03:16 +0000  Running                                     IVORY
b011  2015-02-18 17:55:38 +0000  Finished 2015-02-18 17:55:39 +0000  1.9GB   IVORY
b010  2015-02-17 19:14:43 +0000  Finished 2015-02-17 19:14:48 +0000  1.9GB   IVORY
b004  2015-02-11 19:00:55 +0000  Finished 2015-02-17 19:14:48 +0000  1.9GB   IVORY

==== Restores
ID    Restore Time               Status                              Size    Database
----  -------------------------  ----------------------------------  ------  --------
r002  2015-03-16 17:33:19 +0000  Finished 2015-03-16 17:33:19 +0000  1.9GB   IVORY
r001  2015-03-15 12:13:44 +0000  Failed 2015-03-15 12:13:47 +0000    1.7GB   IVORY

各バックアップのダウンロードURLは public-urlサブコマンドで取得する。

$ heroku pg:backups public-url b001 -a sushi
The following URL will expire at 2015-04-07 18:35:50 +0000:
"http://s3.amazonaws.com/xkpgbackups/app1234567@heroku.com/b004.dump?AWSAccessKeyId=ABCD1234&Expires=1289261668&Signature=3mMBeKISewgEUDT%2FL5mRz4EYS4M%3D"

ここで与えられるURLは一次的なURLなので、永続的なバックアップとして利用する場合には、ドコかしらに転送する必要がある。
もちろん、URLの発行は何度でも行えるのだが、先に述べたバックアップ保持個数の制限があるため、必要な特定の世代は別途保管をおすすめします。

スクリプト等で利用するときなど、URLだけほしい時は

$ heroku pg:backups public-url b001 -a sushi | cat

などのようにして、パイプでcatに繋げればいいらしい。

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?