Gitlab全量迁移

35 篇文章 0 订阅

背景

公司研发使用的Gitlab由于服务器下架需要迁移到新的Gitlab服务器上。Gitlab官方推荐了先备份然后再恢复的方法。个人觉得这个方案不是很友好,故采用官方的另外一种方法,百度后发现这个方法还没有人记录,就写这篇文章给需要的小伙伴参考。

源Gitlab: http://old.mygitlab.com #地址需更换为自己的gitlab地址

目标Gitlab: http://new.mygitlab.com

前提条件

1. Linux主机一台并安装Docker

2. 服务器磁盘需要能够存储源Gitlab的代码,迁移工具会先把代码全部拉到本地,然后再推送到目标Gitlab

步骤

1. root 账号登录Linux服务器,并拉取迁移工具的镜像

docker pull registry.cn-hangzhou.aliyuncs.com/dockerforkevin/congregate:centos-20220312

2. 依次运行以下命令

#获取镜像id
[root@minikube ~]# docker images|grep congregate
registry.cn-hangzhou.aliyuncs.com/dockerforkevin/congregate                                  centos-20220312   4bd6a78c0a68   2 months ago   2.3GB

#运行容器,并在容器中修改/var/run/docker.sock权限
[root@minikube ~]#docker run 

-v /var/run/docker.sock:/var/run/docker.sock
-v /etc/hosts:/etc/hosts
-p 8000:8000
-it 4bd6a78c0a68
/bin/bash

#容器内部命令
[ps-user@a4e8ef2730ed congregate]$sudo chmod 666 /var/run/docker.sock
#按Ctrl+D退出容器

#再次启动容器
docker start <container-id>

3. 进入容器中添加配置文件

#Linux主机
[root@minikube ~]# docker exec -it <container-id> /bin/bash 
#Docker容器中
[ps-user@a4e8ef2730ed congregate]$ mkdir -p data
[ps-user@a4e8ef2730ed congregate]$vi data/congregate.conf 

congregate.conf文件内容

[DESTINATION]
dstn_hostname = http://new.mygitlab.com  #目标Gitlab仓库地址
dstn_access_token = ek04Xy1RbzVpVk5IWnFYYVY3enM= #目标Gitlab管理员Token
import_user_id = 4
shared_runners_enabled = True
project_suffix = False
max_import_retries = 3
username_suffix = gd
mirror_username = 
max_asset_expiration_time = 24

[SOURCE]
src_type = GitLab
src_hostname = http://old.mygitlab.com #源Gitlab仓库地址
src_access_token = aW9uQ3B2TlhkWVpwRnNQV2h5SC0= #源Gitlab管理员Token
src_tier = core
export_import_timeout = 300 #这个时间很重要,控制导入和导出的超时时间,如果仓库很大,可以把这个时间调长一点,单位是秒

[EXPORT]
location = filesystem
filesystem_path = /opt/congregate

[USER]
keep_inactive_users = False
reset_pwd = False
force_rand_pwd = False

[APP]
export_import_status_check_time = 10
wave_spreadsheet_path = wave
mongo_host = localhost
mongo_port = 27017
ui_port = 8000
processes = 4

4. 获取源仓库的元数据(MetaData)

#获取源仓库的元数据
[ps-user@a4e8ef2730ed congregate]$./congregate.sh list

5. 通过UI方式创建需要迁移的对象的列表

[ps-user@a4e8ef2730ed congregate]$./congregate.sh ui &

浏览器方式访问本地:8000端口,Projects是Git仓库,全选然后点击"Stage"按钮,切换到Groups(项目组),全选然后点击“Stage”,切换到Users(用户),全选然后点击“Stage”

所有的按钮点击完成以后,会在data目录下生成3个json文件

[ps-user@a4e8ef2730ed congregate]$ ls -ltr data/staged_*.json
-rw-rw-r-- 1 ps-user ps-user  70439 Mar 12 10:19 data/staged_groups.json
-rw-rw-r-- 1 ps-user ps-user 322311 Mar 12 10:19 data/staged_projects.json
-rw-rw-r-- 1 ps-user ps-user  61408 Mar 12 10:19 data/staged_users.json

6. 执行迁移

#先迁移Gitlab账户
[ps-user@a4e8ef2730ed congregate]$./congregate.sh migrate --skip-group-export --skip-group-import --skip-project-export --skip-project-import --commit
#再迁移Gitlab项目组
[ps-user@a4e8ef2730ed congregate]$./congregate.sh migrate --skip-users --skip-project-export --skip-project-import --commit
#最后迁移Gitlab仓库(也叫项目),这个比较耗时间,视源仓库代码量的多少
[ps-user@a4e8ef2730ed congregate]$./congregate.sh migrate --skip-users --skip-group-export --skip-group-import --commit

7. 我的仓库共计246个,全部都迁移完成了,花了1个多小时

参考文章:

docs/using-congregate.md · master · GitLab.org / Professional Services Automation / Tools / Migration / Congregate · GitLab

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于gitlab项目的迁移,可以通过以下步骤来实现。首先,在迁移前需要cd进入clone到本地的项目,然后使用命令`git remote add gitlab git@gitlab.xxxxxx`(新的项目地址,即迁移后的地址),将新项目地址添加为远程库。接下来,可以使用git的方式进行数据迁移。这是一种简单且机械的方式,不需要考虑多到单、单到单、全量迁移、增量迁移等问题。可以使用命令`git clone Gitlab-A / Gitlab-B`将原项目克隆到本地,然后使用`git push`命令将项目推送到新的Gitlab项目中。另外,还可以使用Rake tasks来导入裸仓库到GitLab实例中。如果是从现有的GitLab实例迁移,并且要保留用户及其命名空间的所有权,请使用基于项目的导入/导出方式。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Gitlab项目迁移](https://blog.csdn.net/QQ1210611769/article/details/116235581)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Gitlab之间数据迁移的5种方式](https://blog.csdn.net/CBGCampus/article/details/126519464)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值