最近我们公司迁移了代码仓库,我们用的gitlab当作代码仓库,记录下来迁移过程分享给需要的朋友。
基础环境:
1,新旧服务器的系统环境都是:CentOS 7
2,gitlab 都是用 Omnibus 方式安装的
备份旧的gitlab
1,先在安全组上做权限控制,禁止别人访问gitlab,防止再有写入操作。
2,执行 /opt/gitlab/bin/gitlab-rake gitlab:backup:create 开始备份。
![2fe67b8b973457cfe8ee2759431b6d75.png](https://i-blog.csdnimg.cn/blog_migrate/f610274667c8ddcc933ed1dd7c198460.jpeg)
注意图中的红色部分:
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data and are not included in this backup. You will need these files to restore a backup.Please back them up manually. #意思就是说,你用这种方式备份,并没有备份 gitlab.rb 和 gitlab-secrets.json 这两个重要文件。 #需要我们自己去备份配置文件。#如果gitlab 是12.3 以上的版本可以执行 gitlab-ctl backup-etc 备份配置文件 ,会备份到 /etc/gitlab/config_backup# 我的旧gitlab 版本低,只能先手动备份一下
恢复到新的gitlab
#确保 新的服务器上已经安装 gitlab #先停止相关数据连接服务gitlab-ctl stop unicorngitlab-ctl stop sidekiq #开始恢复1,把刚才备份的那两个配置文件 gitlab.rb 和 gitlab-secrets.json,覆盖到新的服务器 /etc/gitlab 目录下 。并重载配置文件 gitlab-ctl reconfigure 2,把数据备份 1591175893_2020_06_03_12.0.2_gitlab_backup.tar 放到新服务器上的 /var/opt/gitlab/backups/ 目录下。 3,授权 chown git:git /var/opt/gitlab/backups/1591175893_2020_06_03_12.0.2_gitlab_backup.tar 4,恢复 gitlab-rake gitlab:backup:restore BACKUP=1591175893_2020_06_03_12.0.2 #重新启动新的gitlab sudo gitlab-ctl restart
然后尝试登录一下,又看到了熟悉的界面
![c6224ce6e705bffbd190385b05b68ee4.png](https://i-blog.csdnimg.cn/blog_migrate/2aad435e86b86f9aa45734e994978abf.jpeg)
我新的gitlab 版本是 13.0.3 ,相当于迁移和升级了。
定时备份gitlab和配置文件
#添加定时任务 crontab -e#备份gitlab30 00 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create ;/opt/gitlab/bin/gitlab-ctl backup-etc # 备份路径可以去配置文件中修改