这是我以前发布在 yuque 的文章。是我刚来新公司的时候帮公司搬迁 git 记录下来的,如今看来去掉敏感部分直接发布也没啥问题啦,就搬家过来,我本身也方便查 XD .html
首先须要分几个步骤linux
我将老版本 这里是从 bitnami gitlab 上安装的 8.1.4 版本nginx
将这个版本下的全部如今有的数据进行备份。 使用git
找到
/opt/gitlab-7.x.x-x/apps/gitlab/htdocs/config/gitlab.yml
,将backup
一项的路径改成"/data/backups_gitlab"
,注意目录的权限更改。redis
这个路径下面能够找到咱们的 gitlab 配置文件,将 backup 的地址指定为咱们想要其备份的地址。spring
以后开始备份,使用数据库
cd /opt/gitlab-7.x.x-x/ ./use_gitlab cd /opt/gitlab-7.x.x-x/apps/gitlab/htdocs bundle exec bin/rake gitlab:backup:create RAILS_ENV=production
报错状况1:
You have already activated rake 0.9.2.2,but our Gemfile requires rake 10.1.0,Using bundle exec may solve this.
缘由是默认的path
路径不对,须要执行下bitnami
自带的环境变量设置脚本: 执行安装目录下use_gitlab
便可解决。 json
报错状况2:笔者使用的数据库为MySQL,报错
Can't connect to local MySQL server through socket
.
解决方法为用find指令找到MySQL实际使用的.sock
文件,在报错中的目录下创建软连接。centos
以后咱们就能在原来的机器上得到一个备份好的压缩包ruby
这里注意 backup 的时候不能停机,备份的时候可能会去尝试连接还在运行的数据库,若是服务 down 了会连接失败。
因为我要到新机器上部署个人新版本,因此我在另一台机器上下载好了跟以前 bitnami 同样的版本,这个版本是官方的 Omnibus 版本。我手动下载的 .rpm 包。
我这里采用手动安装:
sudo EXTERNAL_URL="http://127.0.0.1:8081" rpm -i gitlab-ee-9.5.2-ee.0.el7.x86_64.rpm
Installing the GitLab Package
With the desired package downloaded, use your systems package management tool to install it. For example:
DEB based (Ubuntu, Debian, Raspberry Pi):
sudo EXTERNAL_URL="http://gitlab.example.com" dpkg -i gitlab-ee-9.5.2-ee.0_amd64.deb
RPM based (CentOS, RHEL, Oracle, Scientific, openSUSE, SLES):
sudo EXTERNAL_URL="http://gitlab.example.com" rpm -i gitlab-ee-9.5.2-ee.0.el7.x86_64.rpm
Change
http://gitlab.example.com
to the URL at which you want to access your GitLab instance. Installation will automatically configure and start GitLab at that URL.
[root@iZ2ze9mbirr18cl7fb5ewtZ gitlab]# sudo EXTERNAL_URL="http://git.hundun.cn" rpm -i gitlab-ce-8.1.4-ce.0.el7.x86_64.rpm
gitlab: Thank you for installing GitLab!
gitlab: To configure and start GitLab, RUN THE FOLLOWING COMMAND:
sudo gitlab-ctl reconfigure
gitlab: GitLab should be reachable at http://iZ2ze9mbirr18cl7fb5ewtZ
gitlab: Otherwise configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
gitlab: And running reconfigure again.
gitlab:
gitlab: For a comprehensive list of configuration options please 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.
执行 sudo gitlab-ctl reconfigure 会开始配置下载好的 gitlab ,以后咱们就可使用 gitlab-ctl 来执行 gitlab 的 start|end|restart 等等命令了。
能够经过 ps -ef 查看 gitlab 的 nginx 读取哪儿的配置文件以下:
nginx: master process /opt/gitlab/embedded/sbin/nginx -p /var/opt/gitlab/nginx
因此咱们能够在 /var/opt/gitlab 下面找到最新的配置文件。
Next, install the GitLab package. Change `http://gitlab.example.com` to the URL at which you want to access your GitLab instance. Installation will automatically configure and start GitLab at that URL. HTTPS requires additional configuration after installation.
sudo EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ee
其实当咱们在安装的时候 让咱们设置的一个地址可让外部访问,那个地址会让 gitlab 自动生成一个 nginx 配置文件,监听的 server_name 就是咱们设置的地址,若是须要反向代理咱们可能须要去 gitlab 的 nginx 配置目录下面修改这个监听地址。若是没有反向代理,看上去直接设置以后就可使用了(这里通常都是须要定制的,感受 gitlab 这个也给自动设置有点过于优化了。不过也体现出人家尽可能提高用户体验的感受吧)。
拷贝备份到新机器上 这个简单 scp 一下就好了 like this
scp /home/a.txt root@192.168.0.8:/home/root
从本地 传输到 192.168.0.8
而后就是 restore
现将以前的复制包 拷贝到 omnibus 版本的 backup 目录
以后停掉其中两个服务而且 check 其状态。
恢复完毕以后让咱们 check 其状态。
sudo cp 11493107454_2018_04_25_10.6.4-ce_gitlab_backup.tar /var/opt/gitlab/backups/
Stop the processes that are connected to the database. Leave the rest of GitLab running:
sudo gitlab-ctl stop unicorn sudo gitlab-ctl stop sidekiq
Verify
sudo gitlab-ctl status
Next, restore the backup, specifying the timestamp of the backup you wish to restore:
This command will overwrite the contents of your GitLab database!
这里会重写数据库和内容,由于是恢复备份全部都会清掉因此特地让咱们注意。
sudo gitlab-rake gitlab:backup:restore BACKUP=1493107454_2018_04_25_10.6.4-ce
Next, restore /etc/gitlab/gitlab-secrets.json if necessary as mentioned above.
Restart and check GitLab:
sudo gitlab-ctl restart sudo gitlab-rake gitlab:check SANITIZE=true
If there is a GitLab version mismatch between your backup tar file and the installed version of GitLab, the restore command will abort with an error. Install the correct GitLab version and try again.
这里特别注意,全部的恢复迁移工做都是创建在备份的版本和安装的新版本相同的状况下。
经过官方渠道升级到最新版本。(未完待续)
# Debian/Ubuntu dpkg -i gitlab-ce-XXX.deb # CentOS/RHEL rpm -Uvh gitlab-ce-XXX.rpm
分别使用这两个包管理工具进行升级。
升级过于老旧的版本须要脚本放得很缓慢,基本上最多 3个 mirror 一升,不然就会出错。并且是没法挽回的错误又得重来。另外记得每次升级完成后 重启而后修改 nginx 参数。
完成升级以后能够留意一下 git 的 host 是否正常。例如若是你使用阿里云却不配置对外访问地址,那么git host 应该会出现很是奇怪的地址。因此须要配置 gitlab 配置文件将对外地址项改为域名。而后 gitlab-ctl reconfigure 一下生效便可。
虽然这里记录的东西最少,可是这里几乎最耗时,来来回回包括查资料差很少 8 小时吧。最开始还想一步到位升上去简直太天真了。
以后 linux 下删除软件尽可能使用对方提供的现成方法,而且找到全部的删掉可使用 find 方法。
find / -iname 'xxx'
QA:
Q: 卡在卸载gitlab而后再次安装执行sudo gitlab-ctl reconfigure的时候每每会出现:ruby_block[supervise_redis_sleep] action run,会一直卡没法往下进行!
A:
一、按住CTRL+C强制结束;
二、运行:sudo systemctl restart gitlab-runsvdir;
三、再次执行:sudo gitlab-ctl reconfigure
http://www.javashuo.com/article/p-zrucwakb-ge.html
Q: 数据库恢复密码丢了。
A: https://docs.gitlab.com/ee/security/reset_root_password.html#doc-nav
Reference:
https://packages.gitlab.com/app/gitlab/gitlab-ce/search gitlab 发布包地址
http://xlindo.com/2015/08/18/gitlab备份与恢复操做方法/ gitlab bitnami 备份恢复文档
https://community.bitnami.com/t/upgrade-bitnami-gitlab-ce-version/48641 bitnami 官方论坛关于升级问题
https://docs.gitlab.com.cn/omnibus/update/README.html#updating-from-gitlab-66-and-higher-to-the-latest-version gitlab 官方文档 -> Updating GitLab via omnibus-gitlab
https://docs.gitlab.com/ee/raketasks/backup_restore.html#restore restore for Omnibus
https://about.gitlab.com/installation/#centos-7 官方安装文档
https://docs.gitlab.com/ee/policy/maintenance.html#versioning 官方推荐升级路径
https://about.gitlab.com/blog/categories/releases/ 官方 relase 文档
https://www.jianshu.com/p/a86a1529d253 nginx反向代理 gitlab
https://docs.gitlab.com/omnibus/settings/smtp.html gitlab SMTP settings