Migration

Redmine 數據遷移中斷安裝(錯誤 500)

  • February 12, 2015

我正在嘗試遷移舊的安裝:

Environment:
 Redmine version                          2.2.3.stable
 Ruby version                             1.9.3 (x86_64-linux)
 Rails version                            3.2.12
 Environment                              production
 Database adapter                         Mysql2
Redmine plugins:
 no plugin installed

到新機器:

Environment:
 Redmine version                2.6.1.stable
 Ruby version                   1.9.3-p194 (2012-04-20) [x86_64-linux]
 Rails version                  3.2.21
 Environment                    production
 Database adapter               Mysql2
SCM:
 Subversion                     1.6.17
 Mercurial                      2.2.2
 Bazaar                         2.6.0
 Git                            1.7.10.4
 Filesystem                     
Redmine plugins:
 redmine_dmsf                   1.4.9 stable

我在舊伺服器上做了一個簡單的備份:

root@redmine www/redmine# /usr/bin/mysqldump -u root -p"...redmine" redmine_production | gzip > redmine_`date +%y_%m_%d`.gz
root@redmine www/redmine# tar cjf files.tar.bz2 files

並試圖在新的(工作的,但空的)機器中恢復它:

root@redmine ~# cd /var/www/redmine/
root@redmine www/redmine# scp mcon@syno0:files.tar.bz2 .
files.tar.bz2                                         100% 4229     4.1KB/s   00:00
root@redmine www/redmine# scp mcon@syno0:redmine_15_02_12.gz .
redmine_15_02_12.gz                                   100%   11KB  11.2KB/s   00:00

*** here Redmine server is STILL working ***

root@redmine www/redmine# service apache2 stop
[ ok ] Stopping web server: apache2 ... waiting .
root@redmine www/redmine# tar xjf files.tar.bz2
root@redmine www/redmine# zcat redmine_15_02_12.gz | mysql --user=root --password=...redmine     redmine_production
root@redmine www/redmine# rake db:migrate
==  Setup: migrating ==========================================================
-- create_table("attachments", {:force=>true})
  -> 0.0082s
-- create_table("auth_sources", {:force=>true})
  -> 0.0043s
-- create_table("custom_fields", {:force=>true})
  -> 0.0041s
-- create_table("custom_fields_projects", {:id=>false, :force=>true})
  -> 0.0043s
-- create_table("custom_fields_trackers", {:id=>false, :force=>true})
  -> 0.0037s
-- create_table("custom_values", {:force=>true})
  -> 0.0049s
-- create_table("documents", {:force=>true})
  -> 0.0041s
-- add_index("documents", ["project_id"], {:name=>"documents_project_id"})
  -> 0.0127s
-- create_table("enumerations", {:force=>true})
  -> 0.0052s
-- create_table("issue_categories", {:force=>true})
  -> 0.0036s
-- add_index("issue_categories", ["project_id"], {:name=>"issue_categories_project_id"})
  -> 0.0158s
-- create_table("issue_histories", {:force=>true})
  -> 0.0191s
-- add_index("issue_histories", ["issue_id"], {:name=>"issue_histories_issue_id"})
  -> 0.0143s
-- create_table("issue_statuses", {:force=>true})
  -> 0.0046s
-- create_table("issues", {:force=>true})
  -> 0.0045s
-- add_index("issues", ["project_id"], {:name=>"issues_project_id"})
  -> 0.0149s
-- create_table("members", {:force=>true})
  -> 0.0062s
-- create_table("news", {:force=>true})
  -> 0.0052s
-- add_index("news", ["project_id"], {:name=>"news_project_id"})
  -> 0.0139s
-- create_table("permissions", {:force=>true})
  -> 0.0044s
-- create_table("permissions_roles", {:id=>false, :force=>true})
  -> 0.0059s
-- add_index("permissions_roles", ["role_id"], {:name=>"permissions_roles_role_id"})
  -> 0.0168s
-- create_table("projects", {:force=>true})
  -> 0.0582s
-- create_table("roles", {:force=>true})
  -> 0.0045s
-- create_table("tokens", {:force=>true})
  -> 0.0044s
-- create_table("trackers", {:force=>true})
  -> 0.0037s
-- create_table("users", {:force=>true})
  -> 0.0048s
-- create_table("versions", {:force=>true})
  -> 0.0112s
-- add_index("versions", ["project_id"], {:name=>"versions_project_id"})
  -> 0.0428s
-- create_table("workflows", {:force=>true})
  -> 0.0059s
==  Setup: migrated (0.4712s) =================================================

**** MANY LINES, APPARENTLY WITHOUT ERROR ****

==  ChangeChangesetsCommentsLimit: migrating ==================================
-- change_column(:changesets, :comments, :text, {:limit=>16777216})
  -> 0.0081s
==  ChangeChangesetsCommentsLimit: migrated (0.0085s) =========================

==  AddPasswordChangedAtToUser: migrating =====================================
-- add_column(:users, :passwd_changed_on, :datetime)
  -> 0.0104s
==  AddPasswordChangedAtToUser: migrated (0.0108s) ============================

==  InsertBuiltinGroups: migrating ============================================
==  InsertBuiltinGroups: migrated (0.1441s) ===================================

root@redmine www/redmine# service apache2 start
[ ok ] Starting web server: apache2.
root@redmine www/redmine#

在此之後 Redmine 不再工作。嘗試連接會導致:

Internal error

An error occurred on the page you were trying to access.
If you continue to experience problems please contact your Redmine administrator for assistance.

If you are the Redmine administrator, check your log files for details about the error.

Back

我得到以下日誌:

...
Connecting to database specified by database.yml
Creating scope :system. Overwriting existing method Enumeration.system.
Creating scope :sorted. Overwriting existing method User.sorted.
Creating scope :sorted. Overwriting existing method Group.sorted.
Started GET "/" for 192.168.7.114 at 2015-02-12 14:41:57 +0000
Processing by WelcomeController#index as HTML
 Current user: admin (id=1)
Completed 500 Internal Server Error in 75.0ms

NoMethodError (undefined method `passwd_changed_on' for #<User:0x00000006696f80>):
 app/controllers/application_controller.rb:150:in `force_logout_if_password_changed'

我究竟做錯了什麼?

對我感到羞恥:

事實證明,我錯誤地期望rake db:migrate對 採取行動production ENV,但事實並非如此。

正確的命令是:rake db:migrate RAILS_ENV="production".

當您盲目地複制和粘貼時,就會發生這種情況。

抱歉打擾了(版主可以刪除此問答,如果他們認為它可能有用)。

作為記錄:您還需要在進行還原之前刪除 redmine_production 中的所有表,否則rake ...命令將失敗並出現錯誤:

Mysql2::Error: Table 'queries_roles' already exists: CREATE TABLE `queries_roles` (`query_id` int(11) NOT NULL, `role_id` int(11) NOT NULL) ENGINE=InnoDB/var/lib/gems/1.9.1/gems/activerecord-3.2.21/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `query'

引用自:https://serverfault.com/questions/667118