1. 升级

gitlab不支持跨大版本升级,需要一步一步升级。

1.1 查看当前版本

cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

1.2 查看最新版本以及需要跨越的版本

查看升级计划

https://docs.gitlab.com/ee/update/index.html#upgrade-paths

不支持一步到位升级,所以需要按步升级,例如我的gitlab是11.8.1 当前最新的版本是13.8.4

则升级流程为

11.8.1->11.11.8->12.0.1->12.10.14->13.0.1->13.8.4

如果直接跨越大版本,比如从11.11.8升级到12.10.14,会提示

gitlab preinstall: It seems you are upgrading from major version 11 to major version 12.
gitlab preinstall: It is required to upgrade to the latest 12.0.x version first before proceeding.
gitlab preinstall: Please follow the upgrade documentation at https://docs.gitlab.com/ee/policy/maintenance.html#upgrade-recommendations
error: %pre(gitlab-ce-12.10.13-ce.0.el7.x86_64) scriptlet failed, exit status 1
Error in PREIN scriptlet in rpm package gitlab-ce-12.10.13-ce.0.el7.x86_64
	Verifying  : gitlab-ce-12.10.13-ce.0.el7.x86_64                           1/2
gitlab-ce-11.11.8-ce.0.el7.x86_64 was supposed to be removed but is not!
	Verifying  : gitlab-ce-11.11.8-ce.0.el7.x86_64                            2/2

Failed:
	gitlab-ce.x86_64 0:11.11.8-ce.0.el7    gitlab-ce.x86_64 0:12.10.13-ce.0.el7

1.3 升级命令

根据上面一步版本升级计划,依次执行升级命令,每次升级完成之后,需要测试下是否有问题。

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
yum install -y gitlab-ce-11.11.8-ce.0.el7
gitlab-ctl reconfigure
gitlab-ctl restart

升级参考文档:https://about.gitlab.com/update/#centos-7

2. 服务器迁移

2.1 备份文件

gitlab-rake gitlab:backup:create

备份文件会在目录/var/opt/gitlab/backups里面

2.2 复制到新的服务器

通过scp命令复制备份的文件到目标服务器

cd /var/opt/gitlab/backups/
scp root@xxx.xx.xx.xx:/var/opt/gitlab/backups/1613634657_2020_02_18_13.8.4_gitlab_backup.tar ./   #xxx.xxx.xxx.xx为旧服务器ip地址,然后输入你的密码就可以

2.3 新服务器恢复

首先设置权限,避免权限问题失败

chmod 777 1613634657_2020_02_18_13.8.4_gitlab_backup.tar

停止数据连接服务

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

文件恢复

gitlab-rake gitlab:backup:restore BACKUP=备份文件编号

备份文件编号规则为,比如我上面的文件1613634657_2020_02_18_13.8.4_gitlab_backup.tar 文件编号就是1613634657_2020_02_18_13.8.4

2.4 重启gitlab

gitlab-ctl start

查看数据。