heroku db:push postgres://postgres_id:postgres_password@localhost/database_name
SyntaxHighlighter
2012年3月25日日曜日
ローカルのPostgresの内容を、Herokuの共有DB(Postgres)にPushする
この前の逆。すぐに忘れるのでメモ
2012年3月22日木曜日
Herokuの共有DB(Postgres)の内容をローカルのPostgresにPushする
tapsを使うことで、可能となるのだ!
ちなみに今回はOSXの雪豹でやりました。WindowsはTapsのインストールで断念した(笑)
まずはtapsをインストール
次にHerokuからDBをPullします。その際sqlite形式で落としました。
アプリ名を聞かれるのでそのままアプリ名を入力してください。
PULLが完了したので、ローカルのPostgresにPushするのですが、
sqlite形式で落としたためtapsを中継サーバとして利用します。
Push先のPostgresサーバを指定して、tapsサーバを起動。
最後のパラメータのユーザ/パスワートは今立ち上げたtapsサーバのものですので
適当なものでオッケーです。
あとは、sqlite形式のデータをtaps経由でいれるだけです。
上記コマンドはフォアグラウンドでサーバ起動していますので別のコンソールを開いて作業した方が簡単でしょう。
というわけで新しいコンソールで以下を実行
エラーがでなければ完了です♪
参考
herokuで使用しているDBのデータをエクスポートしてローカルのDBにインポート
ほとんどまんまですね。感謝!
ちなみに今回はOSXの雪豹でやりました。WindowsはTapsのインストールで断念した(笑)
まずはtapsをインストール
gem install taps
次にHerokuからDBをPullします。その際sqlite形式で落としました。
アプリ名を聞かれるのでそのままアプリ名を入力してください。
heroku db:pull sqlite://20120312.sqlite
PULLが完了したので、ローカルのPostgresにPushするのですが、
sqlite形式で落としたためtapsを中継サーバとして利用します。
Push先のPostgresサーバを指定して、tapsサーバを起動。
最後のパラメータのユーザ/パスワートは今立ち上げたtapsサーバのものですので
適当なものでオッケーです。
taps server postgres://postgres_id:postgres_password@localhost/database_name taps_user taps_password
あとは、sqlite形式のデータをtaps経由でいれるだけです。
上記コマンドはフォアグラウンドでサーバ起動していますので別のコンソールを開いて作業した方が簡単でしょう。
というわけで新しいコンソールで以下を実行
taps push sqlite://20120312.sqlite http://taps_user:taps_password@localhost:5000
エラーがでなければ完了です♪
参考
herokuで使用しているDBのデータをエクスポートしてローカルのDBにインポート
ほとんどまんまですね。感謝!
2012年3月18日日曜日
Herokuアカウントを複数使いたい!
今までマシン毎にHerokuアカウントを登録してたんだけど、いい加減めんどうになったので
MacMiniに統一したくて。
Heroku Accountsなるプラグインを導入します。
参考
herokuコマンドで複数アカウントを使いわける
おおむね、参考サイトのどおりです。
自分の場合~/.ssh/configがなかったので新規作成しました。
一点注意点だけ。
Herokuからcloneする場合はサーバ指定が~/.ssh/configに書いた内容で指定する
# git clone git@heroku.xxx:myapp.git
MacMiniに統一したくて。
Heroku Accountsなるプラグインを導入します。
参考
herokuコマンドで複数アカウントを使いわける
おおむね、参考サイトのどおりです。
自分の場合~/.ssh/configがなかったので新規作成しました。
一点注意点だけ。
Herokuからcloneする場合はサーバ指定が~/.ssh/configに書いた内容で指定する
# git clone git@heroku.xxx:myapp.git
OSX 10.6.8(Snow Leopard) でRVM環境+Ruby1.9.2のインストール
RVMいれたいなー。
てなわけで、下記を参考にインストール開始
てなわけで、下記を参考にインストール開始
参照
Mac OS XでRVM環境のセッティング(依存ライブラリ周り)
$ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer) $ rvm pkg install ree_dependencies結果、下記のエラーが出ていたけど、ncursesなので、無視して続行します。
Installing ncurses to /Users/xxx/.rvm/usr Error running 'make install', please read /Users/xxx/.rvm/log/ncurses/make.install.logんで下記を実行
$ rvm install 1.9.2 ... Installing yaml to /Users/xxxxx/.rvm/usr The provided compiler '/usr/bin/gcc' is LLVM based, it is not yet fully supported by ruby and gems, please read `rvm requirements`.あら、トラブルさん、こんにちは。今日はお早いお付きですね。 ってなわけでググると、Xcode4.2入れたらおかしくなるよと。Xcodeの環境も壊したくなかったので下記を参考にGCC入れ替えましょう!
参照 Mac OS X LionにXcode 4.2を入れてrvmによりRuby 1.8.xをinstallするとgem installで落ちる問題をXcode 4.2を残したまま解決
・・・って、homebrewなんて入ってない。MacPortsは入ってるけどなんか新しいみたいなので そっちも入れてみます。公式を参考に下記で。$ /usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"はいったよ。
ln: dir: File exists Error: The linking step did not complete successfully The formula built, but is not symlinked into /usr/local You can try again using `brew link gcc' ==> Summary /usr/local/Cellar/gcc/4.6.2: 239 files, 28M, built in 41.1 minutesエラーがでたけど、指示通り
# brew link gccでオッケーかな? 再挑戦!
$ rvm install 1.9.2 ... Install of ruby-1.9.2-p318 - #completeおっけー☆フフッ
2012年2月29日水曜日
GitでCommitを取り消す+Pushを取り消す
取り消すよ。
ローカルのcommitを取り消し
Pushを取り消し(originとmaster)
ローカルのcommitを取り消し
git reset --soft HEAD^
Pushを取り消し(originとmaster)
git push -f origin HEAD^:master
2012年2月2日木曜日
HerokuでDBIだ!
とりあえずHeroku上にてHelloWorldの儀式はすんでいる状況からスタート!
サンプルは下記の状態でとします。
まずはローカルのPostgresqlで動くように修正
Gemfileを編集したのでGemfile.lockを作り直す
ローカルで動かしてみる。
きちんと動くのを確認!
次はHeroku側の接続情報を取得。
ここを参照。
SHARED_DATABASE_URLを参考にRubyソースを編集
サーバで動かしてみる。
うごいた!だめなら heroku logs
サンプルは下記の状態でとします。
#ls Gemfile Gemfile.lock config.ru hello.rb #cat Gemfile source :rubygems gem 'sinatra' #cat config.ru require './hello' run Sinatra::Application #cat hello.rb require 'rubygems' require 'sinatra' get '/' do "Hello World!" end
まずはローカルのPostgresqlで動くように修正
#cat Gemfile
source :rubygems
gem 'sinatra'
gem 'dbi'
gem 'dbd-pg'
#cat hello.rb
require 'rubygems'
require 'sinatra'
require 'dbi'
get '/' do
dbh = DBI.connect('dbi:Pg:dozaemon:localhost', 'dozaemon', '')
version = dbh.select_one('select version()')
"Postgresql version is #{version}"
end
Gemfileを編集したのでGemfile.lockを作り直す
bundle install
ローカルで動かしてみる。
#rackup config.ru
きちんと動くのを確認!
次はHeroku側の接続情報を取得。
ここを参照。
#heroku config BUNDLE_WITHOUT => development:test DATABASE_URL => postgres://username:password@hostname/database LANG => en_US.UTF-8 RACK_ENV => production SHARED_DATABASE_URL => postgres://username:password@hostname/database
SHARED_DATABASE_URLを参考にRubyソースを編集
#cat hello.rb
require 'rubygems'
require 'sinatra'
require 'dbi'
get '/' do
dbh = DBI.connect('dbi:Pg:database:hostname', 'username', 'password')
version = dbh.select_one('select version()')
"Postgresql version is #{version}"
end
サーバで動かしてみる。
#git add . #git commit -m 'db test' #git push heroku master #heroku open
うごいた!だめなら heroku logs
2012年1月31日火曜日
さくらVPS(CentOS5.7)でRubyだDBIだdbd-pgだ
男は黙ってDBI。
試してみる。
#昨日のセットアップのままだとパスワードはいらないっす。
# gem install dbi Fetching: deprecated-2.0.1.gem (100%) Fetching: dbi-0.4.5.gem (100%) Successfully installed deprecated-2.0.1 Successfully installed dbi-0.4.5 2 gems installed Installing ri documentation for deprecated-2.0.1... Installing ri documentation for dbi-0.4.5... Installing RDoc documentation for deprecated-2.0.1... Installing RDoc documentation for dbi-0.4.5...楽勝。次、dbd-pgだ。
# gem install dbd-pg
Fetching: pg-0.12.2.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing dbd-pg:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/pg-0.12.2 for inspection.
Results logged to /usr/lib/ruby/gems/1.9.1/gems/pg-0.12.2/ext/gem_make.out
ぐぬぬ。libpq-fe.hがないって?あーん?develいれてなかったから入れてみる。#yum install postgresql91-devel.x86_64 Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.nara.wide.ad.jp * epel: ftp.kddilabs.jp * extras: ftp.nara.wide.ad.jp * updates: ftp.nara.wide.ad.jp Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package postgresql91-devel.x86_64 0:9.1.2-1PGDG.rhel5 set to be updated --> Finished Dependency Resolution Dependencies Resolved ========================================================================================== Package Arch Version Repository Size ========================================================================================== Installing: postgresql91-devel x86_64 9.1.2-1PGDG.rhel5 pgdg91 1.6 M Transaction Summary ========================================================================================== Install 1 Package(s) Upgrade 0 Package(s) Total download size: 1.6 M Is this ok [y/N]: y Downloading Packages: postgresql91-devel-9.1.2-1PGDG.rhel5.x86_64.rpm | 1.6 MB 00:01 Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing : postgresql91-devel 1/1 Installed: postgresql91-devel.x86_64 0:9.1.2-1PGDG.rhel5 Complete!うっし、もう一回!
# gem install dbd-pg
Building native extensions. This could take a while...
ERROR: Error installing dbd-pg:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/pg-0.12.2 for inspection.
Results logged to /usr/lib/ruby/gems/1.9.1/gems/pg-0.12.2/ext/gem_make.out
ぐぎぎぎぎ。pg_configがないって?見落としてた。言われるままに再チャレンジ!#gem install dbd-pg -- --with-pg_config=/usr/pgsql-9.1/bin/pg_config Building native extensions. This could take a while... Fetching: dbd-pg-0.3.9.gem (100%) Successfully installed pg-0.12.2 Successfully installed dbd-pg-0.3.9 2 gems installed Installing ri documentation for pg-0.12.2... Installing ri documentation for dbd-pg-0.3.9... Installing RDoc documentation for pg-0.12.2... Installing RDoc documentation for dbd-pg-0.3.9...お、うまくいったっぽい?
試してみる。
# irb
irb(main):001:0> require 'dbi'
=> true
irb(main):002:0> dbh = DBI.connect('dbi:Pg:dozaemon:localhost','dozaemon','')
=> #<DBI::DatabaseHandle:0x00・・・以下略>
irb(main):003:0> dbh.select_one('select version()')
=> ["PostgreSQL 9.1.2 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-51), 64-bit"]
irb(main):004:0> exit
でけた!#昨日のセットアップのままだとパスワードはいらないっす。
登録:
投稿 (Atom)