gitlab备份迁移

备份【原服务器】

#查看gitlab版本号

[root@wiki ~]# gitlab-rakegitlab:env:info

#备份命令【备份后的文件一般是位于/var/opt/gitlab/backups下】

[root@wiki ~]# gitlab-rakegitlab:backup:create RAILS_ENV=production

#查看备份情况

[root@wiki ~]# cd/var/opt/gitlab/backups

[root@wiki backups]# ls

1510134637_gitlab_backup.tar

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

迁移【新服务器】

#安装gitlab【和原服务器要求一个版本】

[root@gitlab ~]# yuminstall curl policycoreutils openssh-server openssh-clients postfix -y

[root@test-2 ]# rpm-ivh gitlab-ce-8.9.0-ce.0.el6.x86_64.rpm

Preparing...               ########################################### [100%]

  1:gitlab-ce             ########################################### [100%]

hostname: 未知的主机

gitlab: Thank you for installing GitLab!

gitlab: To configure and start GitLab, RUN THE FOLLOWINGCOMMAND:

 

sudo gitlab-ctl reconfigure

 

gitlab: GitLab should be reachable athttp://gitlab.example.com

gitlab: Otherwise configure GitLab for your system byediting /etc/gitlab/gitlab.rb file

gitlab: And running reconfigure again.

gitlab:

gitlab: For a comprehensive list of configuration optionsplease see the Omnibus GitLab readme

gitlab:https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

gitlab:

It looks like GitLab has not been configured yet;skipping the upgrade script.

 

[root@test-2 ]# gitlab-ctlreconfigure

#查看gitlab运行状况

[root@test-2 ]# gitlab-ctlstatus

run: gitlab-workhorse: (pid 33308) 22s; run: log: (pid30545) 443s

run: logrotate: (pid 30564) 431s; run: log: (pid 30563)431s

run: nginx: (pid 30551) 438s; run: log: (pid 30550) 438s

run: postgresql: (pid 30396) 679s; run: log: (pid 30395)679s

run: redis: (pid 30310) 700s; run: log: (pid 30309) 700s

run: sidekiq: (pid 30535) 451s; run: log: (pid 30534)451s

run: unicorn: (pid 30508) 457s; run: log: (pid 30507)457s

 

 

#将备份的文件直接拷贝到新的服务器的/var/opt/gitlab/backups目录下

可以利用scp进行直接拷贝.

scpusername@src_ip:/var/opt/gitlab/backups/1481529483_gitlab_backup.tar/var/opt/gitlab/backups

PS: username为原服务器的用户名,src_ip原服务器IP地址

#恢复备份数据

[root@ ~]# gitlab-rakegitlab:backup:restore RAILS_ENV=production BACKUP=1510134637

 

#登录【用原gitlab的可以登录】

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

迁移后问题【500】

【http://linuxerxy.blog.51cto.com/10707334/1865414】

从原服务器转移到新服务器时;其它页面都可以正常显示,但是一点击项目就会显示500,。查看/var/log/gitlab/gitlab-rails/production.log日志,发现错误 。

 

Completed 500 Internal Server Error in 98ms (ActiveRecord:40.9ms)

OpenSSL::Cipher::CipherError (bad decrypt):

 app/models/project.rb:456:in `import_url'

 app/models/project.rb:486:in `external_import?'

 app/models/project.rb:478:in `import?'

 app/models/project.rb:494:in `import_in_progress?'

 app/controllers/projects_controller.rb:93:in `show'

 lib/gitlab/middleware/go.rb:16:in `call

通过搜索知道,这是gitlab数据迁移时的一个缺陷。解决方法:

1、拷贝原服务器gitlab的【db_key_base】到新服务器gitlab【db_key_base】位置在/etc/gitlab/gitlab-secrets.json  

 

2、

EE版本执行

gitlab-rails runner "Project.where(mirror:false).where.not(import_url: nil).each { |p| p.import_data.destroy ifp.import_data }"

 

CE版本执行

gitlab-rails runner"Project.where.not(import_url: nil).each { |p| p.import_data.destroy ifp.import_data }"

 

重启gitlab,发现500错误不见,项目能访问到。

 

 

#CE版本执行

[root@rabbit-test-2 gitlab]# gitlab-railsrunner "Project.where.not(import_url: nil).each { |p|p.import_data.destroy if p.import_data }"

/opt/gitlab/embedded/lib/ruby/gems/2.1.0/gems/bundler-1.10.6/lib/bundler/shared_helpers.rb:78:warning: Insecure world writable dir /opt/gitlab/bin in PATH, mode 040777

/opt/gitlab/embedded/lib/ruby/gems/2.1.0/gems/bundler-1.10.6/lib/bundler/shared_helpers.rb:78:warning: Insecure world writable dir/opt/gitlab/embedded/service/gem/ruby/2.1.0/bin in PATH, mode 040777

/opt/gitlab/embedded/lib/ruby/gems/2.1.0/gems/bundler-1.10.6/lib/bundler/shared_helpers.rb:78:warning: Insecure world writable dir/opt/gitlab/embedded/service/gem/ruby/2.1.0/bin in PATH, mode 040777

#停止gitlab

[root@rabbit-test-2 gitlab]# gitlab-ctlstop

ok: down: gitlab-workhorse: 0s, normally up

ok: down: logrotate: 0s, normally up

ok: down: nginx: 0s, normally up

ok: down: postgresql: 0s, normally up

ok: down: redis: 0s, normally up

ok: down: sidekiq: 0s, normally up

ok: down: unicorn: 0s, normally up

#启动gitlab

[root@rabbit-test-2 gitlab]# gitlab-ctlstart

ok: run: gitlab-workhorse: (pid 37758) 0s

ok: run: logrotate: (pid 37760) 0s

ok: run: nginx: (pid 37762) 0s

ok: run: postgresql: (pid 37773) 1s

ok: run: redis: (pid 37781) 0s

ok: run: sidekiq: (pid 37785) 1s

ok: run: unicorn: (pid 37789) 0s

 

 

登录gitlab测试【成功】

 

 

 

 

#修改访问方式为IP

[root@rabbit-test-2 gitlab]# vim/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

  gitlab:

    ## Web server settings (note: host is theFQDN, do not include http://)

    host: 192.168.30.22

    port: 80

    https: false

 

 

 

 

 

 

 

 

猜你喜欢

转载自blog.csdn.net/weixin_37934134/article/details/79654670