2018-07-09--记录一次gitlab迁移事件及遇到的问题

一、事情起因

    因机房服务器即将到期,需要将即将到期的服务器迁移至云上,迁移之前没有查看老环境的Gitlab是什么版本,直接装的Gitlab社区版,做数据导入时提示版本错误:

[root@vpn-server-001 devops]# gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=1531072861
Unpacking backup ... done
GitLab version mismatch:
  Your current GitLab version (11.0.2) differs from the GitLab version in the backup!
  Please switch to the following version and try again:
  version: 8.9.5


Hint: git checkout v8.9.5 

    此时去查看老环境的gitlab版本:

[root@git-server yum.repos.d]# gitlab-rake gitlab:env:info

System information
System:		
Current User:	git
Using RVM:	no
Ruby Version:	2.1.8p440
Gem Version:	2.5.1
Bundler Version:1.10.6
Rake Version:	10.5.0
Sidekiq Version:4.1.2

GitLab information
Version:	8.9.5                  #发现是8.9.5的
Revision:	f6ab19d
Directory:	/opt/gitlab/embedded/service/gitlab-rails
DB Adapter:	postgresql
URL:		http://gitlab.zlkjbj.cn
HTTP Clone URL:	http://gitlab.zlkjbj.cn/some-group/some-project.git
SSH Clone URL:	git@gitlab.zlkjbj.cn:some-group/some-project.git
Using LDAP:	no
Using Omniauth:	no

GitLab Shell
Version:	3.0.0
Repositories:	/data/git-data/repositories
Hooks:		/opt/gitlab/embedded/service/gitlab-shell/hooks/
Git:		/opt/gitlab/embedded/bin/git

查看新环境的Gitlab版本:

[root@server-001 ~]# gitlab-rake gitlab:env:info

System information
System:		
Current User:	git
Using RVM:	no
Ruby Version:	2.4.4p296
Gem Version:	2.7.6
Bundler Version:1.16.2
Rake Version:	12.3.1
Redis Version:	3.2.11
Git Version:	2.17.1
Sidekiq Version:5.1.3
Go Version:	unknown

GitLab information
Version:	11.0.2             #新环境的版本为11.0.2
Revision:	d9540ee
Directory:	/opt/gitlab/embedded/service/gitlab-rails
DB Adapter:	postgresql
URL:		http://114.115.181.98
HTTP Clone URL:	http://114.115.181.98/some-group/some-project.git
SSH Clone URL:	ssh://git@114.115.181.98:52113/some-group/some-project.git
Using LDAP:	no
Using Omniauth:	no

GitLab Shell
Version:	7.1.4
Repository storage paths:
- default: 	/var/opt/gitlab/git-data/repositories
Hooks:		/opt/gitlab/embedded/service/gitlab-shell/hooks
Git:		/opt/gitlab/embedded/bin/git

知道问题后,下面是将新环境的Gitlab替换为8.9.5的版本:

yum remove -y gitlab-ce               #卸载新环境的Gitlab
yum install -y gitlab-ce-8.9.5         #指定安装8.9.5的版本的gitlab

然后做导入操作(需要将备份文件放到指定的目录下):

# gitlab-rake gitlab:backup:restore BACKUP=1531072861       #1531072861为你需要恢复备份的时间戳,文件名为:1531072861_gitlab_backup.tar 这种形式

然后登陆Gitlab界面查看数据即可!!!

二、问题解决

迁移后访问首页没问题,但是访问项目时会报500的错误,是gitlab数据迁移时的一个缺陷。日志如下:

Started GET "/davidb/workflow-test2" for 127.0.0.1 at 2016-05-25 11:18:10 -0500
Processing by ProjectsController#show as HTML
  Parameters: {"namespace_id"=>"davidb", "id"=>"workflow-test2"}
Completed 500 Internal Server Error in 242ms (ActiveRecord: 7.4ms)

OpenSSL::Cipher::CipherError (bad decrypt):
  app/models/project.rb:379:in `import_url'
  app/models/project.rb:409:in `external_import?'
  app/models/project.rb:401:in `import?'
  app/models/project.rb:417:in `import_in_progress?'
  app/controllers/projects_controller.rb:93:in `show'
  lib/gitlab/middleware/go.rb:16:in `call'

         解决办法:

 

1、覆盖原来gitlab的 db_key_base 到新的gitlab 

db_key_base  位置在 /etc/gitlab/gitlab-secrets.json  

 

2、EE版本执行命令
sudo gitlab-rails runner "Project.where(mirror: false).where.not(import_url: nil).each { |p| p.import_data.destroy if p.import_data }"

CE版本执行命令
sudo gitlab-rails runner "Project.where.not(import_url: nil).each { |p| p.import_data.destroy if p.import_data }"

 

posted @ 2018-07-09 15:53  欧-阳  阅读(4964)  评论(0编辑  收藏  举报