迁移、升级(redmine、passenger、os、ruby)从(4.1.1、5.3、18.04、2.6.6)到(5.0.1、6.0.14、20.04、3.0.4)

迁移、升级(redmine、passenger、os、ruby)从(4.1.1、5.3、18.04、2.6.6)到(5.0.1、6.0.14、20.04、3.0.4)

我需要升级一些东西:

os (ubuntu)  18.04 => 20.04
ruby:        2.6.6 => 3.0.4
passenger:   5.3   => 6.0.14
redmine:     4.1.1 => 5.0.1

至少对于迁移来说,我可以保持不变的一件事是数据库,mysql 5.7

我启动了一个新的 VM(google 计算引擎),运行 ubuntu 20.04、ruby 3.0.4、passenger 6.0.14 和 redmine 5.0.1。

我已经从现有的redmine 4.1.1中卸载了所有插件。

我想知道是否有一种简单的方法可以将 redmine db 和外部文件转储并恢复到新系统上?我很确定文件部分很容易,只需将其打包并在新的 redmine 文件目录中解压即可。

是否有 rake 任务可以将数据库从 redmine 4.1.x 升级到 redmine 5.0.x?如果是这样,我不能简单地恢复 4.1.x mysql db,运行 rake 升级任务,然后启动 redmine 吗?

答案1

以下内容是根据我的笔记重建的;基本程序如下:

  On old system:
    Back out all plugins
    Save database
    Save db/schema.rb
    Save files subtree
  On new system:
    Create database
    Install redmine 
    Restore old database
    Copy saved schema.rb into db subdirectory
    Replace files directory with saved files
    Migrate database
    Install new versions of plugins as appropriate

请注意,此过程会丢失插件保存的所有数据;在我们的例子中,这不是什么大问题,因为我们使用的大多数插件没有与之关联的新数据库表或修改后的数据库表。

更详细地:

On old system:
  You may want to duplicate your redmine environment and work with that version:
    Set up a redmine of the same version, with the same plugins.
    Reload the database.
    Point the files subdir to the files, or duplicate them as well.
  Stop apache if it seems wise
    sudo apache2ctl stop
  sudo -i -u <rm-user>
    Save files subtree:
      mkdir rm_saved
      cd <rm-dir>
      tar cf ~/rm_saved/rm_files.tar files
    Uninstall all plugins:
      Be careful to uninstall in proper (reverse of installation) order,
        as some plugins may depend on others.
      cd ~/<rm-dir>
      For each plugin:
        bin/rake redmine:plugins:migrate NAME=<plugin-name> VERSION=0 RAILS_ENV=<rm-rails-env>
        rm -rf plugins/<plugin-name>
        touch tmp/restart.txt
        <make sure things still look ok>
          Note: at one point I had some display glitches,
          which disappeared when the last plugin was removed
    Dump the mysql database:
      cd ~/rm_saved
      /usr/bin/mysqldump -u <mysql-rm-user> -p<pw> <rm-db> --lock-tables --no-tablespaces >rm_mysql_data_noplugins.sql
    Save the db/schema.db file
      cp -p ~/<rm-dir>/db/schema.rb schema.rb_noplugins_rm4
    Make the saved files world (or whatever is appropriate for your environment) readable:
      chmod 444 *
      exit
  Restart apache if you stopped it
   sudo apache2ctl start
  Make sure you can sftp into this system from the new system.

配置新系统:

sudo -i
  install apache2 and configure
  install mysql 5.7
    This is non-trivial, as ubuntu 20 does not come with a mysql 5.7 package normally available
    see: https://www.vultr.com/docs/how-to-install-mysql-5-7-on-ubuntu-20-04
    create user for redmine
      mysql -u root -p
      mysql> create user '<rm-db-user>'@'localhost' identified by '<rm-db-user-pw>';
    create database for redmine
      mysql> create database <rm-db> character set utf8mb4;
      mysql> grant all privileges on <rm-db>.* to '<rm-db-user>'@'localhost';
      mysql> exit;
  install rvm (I originally had trouble I think because I was using chruby)
  install ruby 3.0.4 globally
  install passenger 6.0.14
  create the redmine admin user
    sudo adduser --debug --system --shell /bin/bash --gecos 'Redmine Admin' --group <rm-user>
    sudo passwd <rm-user>
  put the redmine user in the rvm group
    sudo usermod -a -G rvm <rm-user>
exit
as redmine admin user:
 Note that on this new system (i.e. using these instructions), redmine is running with a *per-user* ruby,
 not the global ruby.  The apache2 files need to include a PassengerRuby pointing at this ruby:
   PassengerRuby <rm-user-home>/.rvm/rubies/ruby-3.0.4/bin/ruby
sudo -i -u <rm-user>
  mkdir rm_saved
  cd rm_saved
  sftp to the old system and transfer the saved files:
    sftp ...
    cd rm_saved
    get rm_files.tar
    get rm_mysql_data_noplugins.sql
    get schema.rb_noplugins_rm4
    quit
  Install redmine 5
    I tried to match the original configuration as closely as possible;
    I don't know how important that is, since the db will be overwritten.
    I did use a different environment, (other than production, development, or test)
    although that is optional and requires configuring database.yml accordingly
  Start rm 5 and configure, without plugins
    Make sure it works.
  exit
Stop apache
  sudo apache2ctl stop
Restore the redmine 4 version of the db
  mysql -u root -p
  mysql> use <rm-db>;
  mysql> source <rm-user-home>/rm_saved/rm_mysql_data_noplugins.sql
  mysql> exit
As the redmine user:
sudo -i -u <rm-user>
  Restore the preserved files:
    cd ~/<rm-dir>
    mv files files_org
    tar xf ~/rm_saved/rm_files.tar
  Replace the schema.rb with the redmine 4 version that matches the restored database
    cd ~/<rm-dir>/db
    mv schema.rb schema.rb_rm5_org
    cp -p ~/rm_saved/schema.rb_noplugins_rm4 schema.rb
    chmod 664 schema.rb
  Migrate the db to the redmine 5 operational point
    cd ~/<rm-dir>
    bundle exec rake db:migrate RAILS_ENV=<rm-env>
  exit
restart apache
  sudo apache2ctl start

假设一切正常,您可以根据需要安装所需插件的新版本。请注意,插件使用的数据库表中的任何旧数据都将丢失。

相关内容