新しいプランのサーバで Rails アプリが一応動くようになったので、旧プランのサーバからデータを移行する。
まずは mysqldump
コマンドで旧プランのデータベースを取り出す。
[[email protected] ~]$ mysqldump -u lathercraft -p lathercraft_production > lcp-20170505.sql [[email protected] ~]$ tar czf lcp-20170505.sql.tgz lcp-20170505.sql
ファイルをローカルにダウンロード。
[email protected] $ scp -P xxxxx [email protected]:lcp-20170505.sql.tgz . lcp-20170505.sql.tgz 100% 10MB 10.1MB/s 00:01
ダウンロードしたファイルを新プランのサーバにアップロード。
[email protected] $ scp -P 60000 lcp-20170505.sql.tgz [email protected]: lcp-20170505.sql.tgz 100% 10MB 10.1MB/s 00:01
新プランのサーバにログインして、.tgz ファイルを展開。
[email protected] $ ssh -p 60000 [email protected] Last login: Fri May 5 11:06:46 2017 from fntsitm001026.sitm.fnt.ngn.ppp.infoweb.ne.jp SAKURA Internet [Virtual Private Server SERVICE] [[email protected] ~]$ ls lcp-20170505.sql.tgz [[email protected] ~]$ tar xzf lcp-20170505.sql.tgz [[email protected] ~]$ ls lcp-20170505.sql lcp-20170505.sql.tgz
データベースにリストアする。
[[email protected] ~]$ mysql -u lathercraft -p lathercraft_production < lcp-20170505.sql Enter password:
アプリを立ち上げて確認。
[[email protected] lathercraft]# export SECRET_KEY_BASE=bundle exec rake secret [[email protected] lathercraft]# bundle exec rails s -e production -b 0.0.0.0 => Booting WEBrick => Rails 4.2.8 application starting in production on http://0.0.0.0:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server DEPRECATION WARNING: The configuration option `config.serve_static_assets` has been renamed to `config.serve_static_files` to clarify its role (it merely enables serving everything in the `public` folder and is unrelated to the asset pipeline). The `serve_static_assets` alias will be removed in Rails 5.0. Please migrate your configuration files accordingly. (called from block inat /var/lathercraft/config/environments/production.rb:23) [2017-05-05 11:18:51] INFO WEBrick 1.3.1 [2017-05-05 11:18:51] INFO ruby 2.3.3 (2016-11-21) [x86_64-linux] [2017-05-05 11:18:51] INFO WEBrick::HTTPServer#start: pid=12500 port=3000
ブラウザでも確認出来てOK。
ところでうえで気がついたんだけど、アプリを /var/www/lathercraft 以下に置くつもりが /var/lathercraft 以下においてしまっている。なので移動する。
[[email protected] var]# cp -r -a lathercraft www/lathercraft [[email protected] var]# cd www/lathercraft [[email protected] lathercraft]# ls Gemfile README.rdoc app config db log test vendor Gemfile.lock Rakefile bin config.ru lib public tmp
再度アプリを立ち上げて確認。
[[email protected] lathercraft]# bundle exec rails s -e production -b 0.0.0.0
OK。