Gitlab 升级备份迁移
2019-03-14 本文已影响0人
Evan_Vivian
公司老的服务器即将到期,且不准备续期(打算在公司账号下新买ECS服务器,旧的服务器是在个人账号下购买的),旧服务器上的gitlab服务需要迁移到新的服务器上。
由于Gitlab自身的兼容性问题,高版本的Gitlab无法恢复低版本gitlab备份的数据。要么新服务器安装和旧服务器一样版本的gitlab,部署好环境后开始备份和数据迁移;要么旧服务器上的gitlab按步骤升级到最新版本后再备份,新服务器上直接安装最新版本,并恢复对应版本的数据。
强迫症用户肯定选择升级到最新版啊。gitlab的版本升级也比较个性,下边请看我慢慢道来:
安全起见,旧服务器升级Gitlab前,建议先备份数据(虽然是老版本的,但总比丢失了的好)。
查询版本及备份
查看gitlab版本(二选一):
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
gitlab-rake gitlab:env:info
备份10.3.3版本数据
gitlab-rake gitlab:backup:create RAILS_ENV=production
备份后的文件一般是位于/var/opt/gitlab/backups下, 自动生成文件名文件名如1541739348_2018_11_09_10.3.3_gitlab_backup.tar
升级路线 10.3.3 ---> 10.8.7 ---> 11.4.5 (10.8.7是版本10中的最后一个版本)
创建升级所需文件 touch /etc/gitlab/skip-auto-migrations
yum install gitlab-ce
#直接升级最新版本报错如下
gitlab preinstall: It seems you are upgrading from 10.x version series
gitlab preinstall: to 11.x series. It is recommended to upgrade
gitlab preinstall: to the last minor version in a major version series first before
gitlab preinstall: jumping to the next major version.
gitlab preinstall: Please follow the upgrade documentation at https://docs.gitlab.com/ee/policy/maintenance.html#upgrade-recommendations
gitlab preinstall: and upgrade to 10.8 first.
error: %pre(gitlab-ce-11.4.5-ce.0.el7.x86_64) scriptlet failed, exit status 1
Error in PREIN scriptlet in rpm package gitlab-ce-11.4.5-ce.0.el7.x86_64
gitlab-ce-10.3.3-ce.0.el7.x86_64 was supposed to be removed but is not!
Verifying : gitlab-ce-10.3.3-ce.0.el7.x86_64 1/2
Verifying : gitlab-ce-11.4.5-ce.0.el7.x86_64 2/2
Failed:
gitlab-ce.x86_64 0:10.3.3-ce.0.el7 gitlab-ce.x86_64 0:11.4.5-ce.0.el7
Complete!
旧服务器上安装的gitlab版本是10.3.3,最新的gitlab版本是11.4.5,要从10.版本升级到11.版本需要先升级到10.*的最后一个版本官方是这么规定的。
yum install gitlab-ce-10.8.7
#从10.3.3先升级到10.8.7 升级成功 信息如下
Running handlers:
Running handlers complete
Chef Client finished, 0/1 resources updated in 07 seconds
Checking PostgreSQL executables: OK
Found /etc/gitlab/skip-auto-migrations, exiting...
_______ __ __ __
/ ____(_) /_/ / ____ _/ /_
/ / __/ / __/ / / __ `/ __ \
/ /_/ / / /_/ /___/ /_/ / /_/ /
\____/_/\__/_____/\__,_/_.___/
Upgrade complete! If your GitLab server is misbehaving try running
sudo gitlab-ctl restart
before anything else.
If you need to roll back to the previous version you can use the database
backup made during the upgrade (scroll up for the filename).
Verifying : gitlab-ce-10.8.7-ce.0.el7.x86_64 1/2
Verifying : gitlab-ce-10.3.3-ce.0.el7.x86_64 2/2
Updated:
gitlab-ce.x86_64 0:10.8.7-ce.0.el7
Complete!
升级到10.8.7后重新初始化一下配置并重启gitlab
gitlab-ctl reconfigure
gitlab-ctl restart
访问重启后的gitlab,查看是否成功;继而升到最新版本(11.4.5)
yum install gitlab-ce
#10.8.7升级11.4.5 成功 信息如下
Running handlers:
Running handlers complete
Chef Client finished, 0/1 resources updated in 10 seconds
Checking PostgreSQL executables: OK
Found /etc/gitlab/skip-auto-reconfigure, exiting...
_______ __ __ __
/ ____(_) /_/ / ____ _/ /_
/ / __/ / __/ / / __ `/ __ \
/ /_/ / / /_/ /___/ /_/ / /_/ /
\____/_/\__/_____/\__,_/_.___/
Upgrade complete! If your GitLab server is misbehaving try running
sudo gitlab-ctl restart
before anything else.
If you need to roll back to the previous version you can use the database
backup made during the upgrade (scroll up for the filename).
Verifying : gitlab-ce-11.4.5-ce.0.el7.x86_64 1/2
Verifying : gitlab-ce-10.8.7-ce.0.el7.x86_64 2/2
Updated:
gitlab-ce.x86_64 0:11.4.5-ce.0.el7
Complete!
升级到11.4.5 执行gitlab-ctl reconfigure
再次初始化配置,报错如下
Deprecations:
== Prometheus ==
Detected Prometheus version 1.x. Version 1.x has been deprecated and support will be removed in GitLab version 12.0.
To upgrade to Promtheus 2.x, use `gitlab-ctl prometheus-upgrade` command.
Running this command will migrate all your existing data to format supported by Prometheus 2.x.
This can be a time consuming operation. To skip migrating the data, and instead remove and start fresh, run `gitlab-ctl prometheus-upgrade --skip-data-migration`.
Check https://docs.gitlab.com/omnibus/update/gitlab_11_changes.html#11-4 for details.
---
gitlab Reconfigured!
按照给出的信息升级gitlab-ctl prometheus-upgrade
并重启gitlab-ctl restart
,应该就可正常访问11.4.5版本的gitlab了。
gitlab-rake gitlab:backup:create RAILS_ENV=production
#再次备份最新版本的数据,并查看相应文件
ll /var/opt/gitlab/backups
total 152K
-rw------- 1 git git 80K Nov 8 19:51 1541677863_2018_11_08_11.4.5_gitlab_backup.tar
-rw-r--r-- 1 root root 70K Nov 8 18:56 1541739348_2018_11_09_10.3.3_gitlab_backup.tar
数据迁移
新的服务器上安装最新(11.4.5)版本的gitlab,CentOS7安装请参考。
scp -pr 1541677863_2018_11_08_11.4.5_gitlab_backup.tar root@10.211.55.12:/var/opt/gitlab/backups
#把对应版本的数据从旧服务器上拷贝到新服务器的gitlab备份目录里
#新服务器执行恢复命令
chown -R git.git /var/opt/gitlab/backups/
gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=1541677863_2018_11_08_11.4.5
注意:这里没有后面的_gitlab_backup.tar名字
一路yes,恢复是会先删除新服务器上所有gitlab数据的。