Herokuのデータベースを吹き飛ばした話
Herokuのデータを定期バックアップ依頼されたのでやってみたらデータベースが死んでしまいました。
まず落としてくる
heroku db:pull sqlite://backup [17:53:12] Loaded Taps v0.3.24 Warning: Data in the database 'sqlite://backup' will be overwritten and will not be recoverable. ! WARNING: Destructive Action ! This command will affect the app: APP_NAME ! To proceed, type "APP_NAME" or re-run this command with --confirm APP_NAME > APP_NAME Receiving schema Schema: 0% | | ETA: --:--:-- Schema: 20% |======== | ETA: 00:00:07 Schema: 40% |================ | ETA: 00:00:05 Schema: 60% |========================= | ETA: 00:00:03 Schema: 80% |================================= | ETA: 00:00:01 Schema: 100% |==========================================| Time: 00:00:08 Receiving indexes schema_migrat: 0% | | ETA: --:--:-- schema_migrat: 100% |==========================================| Time: 00:00:00 months: 0% | | ETA: --:--:-- months: 50% |===================== | ETA: 00:00:00 months: 100% |==========================================| Time: 00:00:01 reports: 0% | | ETA: --:--:-- reports: 100% |==========================================| Time: 00:00:00 users: 0% | | ETA: --:--:-- users: 50% |===================== | ETA: 00:00:00 users: 100% |==========================================| Time: 00:00:01 notes: 0% | | ETA: --:--:-- notes: 100% |==========================================| Time: 00:00:00 Receiving data 5 tables, 1,000 records schema_migrat: 100% |==========================================| Time: 00:00:01 months: 100% |==========================================| Time: 00:00:02 reports: 100% |==========================================| Time: 00:00:01 users: 100% |==========================================| Time: 00:00:01 notes: 100% |==========================================| Time: 00:00:01 Resetting sequences
入れる
落としてきたのが入るのか確認してみた。それがいかんかった。
heroku db:push sqlite://backup [17:57:22] Loaded Taps v0.3.24 Warning: Data in the app 'APP_NAME' will be overwritten and will not be recoverable. ! WARNING: Destructive Action ! This command will affect the app: APP_NAME ! To proceed, type "APP_NAME" or re-run this command with --confirm APP_NAME > APP_NAME Sending schema Schema: 100% |==========================================| Time: 00:00:10 Sending indexes schema_migrat: 100% |==========================================| Time: 00:00:01 months: 100% |==========================================| Time: 00:00:04 reports: 100% |==========================================| Time: 00:00:01 users: 100% |==========================================| Time: 00:00:02 notes: 100% |==========================================| Time: 00:00:01 Sending data 5 tables, 83 records schema_migrat: 100% |==========================================| Time: 00:00:00 months: 0% | | ETA: --:--:-- Saving session to push_201304040158.dat.. !!! Caught Server Exception HTTP CODE: 500 Taps Server Error: PGError: ERROR: time zone displacement out of range: "2013-04-01 12:00:00.000000+5895321600" LINE 1: ...d_at") VALUES (157, '2013-04', NULL, 3, 1, 0, 15, '2013-04-0... ^
ローカルの開発マシンはmysqlを使ってのだけどファイルとしてバックアップがとれるsqliteに惹かれたのだ。
たぶん原因は、sqliteで使える型にdatetimeがないからのような気がしている。
$ heroku pg [18:00:02] === HEROKU_POSTGRESQL_YELLOW_URL (DATABASE_URL) Plan: Dev Status: available Connections: 2 PG Version: 9.1.9 Created: 2013-03-22 06:05 UTC Data Size: 6.2 MB Tables: 5 Rows: 0/10000 (In compliance) Fork/Follow: Unsupported
死亡確認
ロールバックしてくれるからものだと思ってた。なにがHerokuだ。
こっちでバックアップをとるべきだった。
http://qiita.com/items/b68acc78afad68a9dc8b