Git - 记一次完整的新旧Gitlab迁移

本文详细介绍了如何迁移GitLab的群组和项目,包括使用UI界面和命令行方式,特别推荐使用命令行的--mirror方式进行项目迁移,以保留完整分支和提交历史。同时,文章还涉及到了设置个人访问令牌以解决访问权限问题以及处理SSL证书错误的方法。

在这里插入图片描述


要求

  • 保留完整的分支
  • 保留提交记录

在这里插入图片描述


群组迁移

两种方式, 如果多就迁移,如果少,就新建。

原GitLab_群组导出

在这里插入图片描述


新GitLab_群组导入

在这里插入图片描述


Project迁移(UI方式)

原GitLab_项目导出

在这里插入图片描述

选择 【下载导出】

在这里插入图片描述

新GitLab_项目导入

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述


Project迁移(command方式)【推荐】

核心

#从老gitlib拉取裸仓库,并在本地文件系统创建gitbook-demo.git文件夹
git clone --bare ssh://git@oldgitlab:port/group1/gitproject-demo.git
#进入代码目录
cd gitproject-demo.git
#向新git推送镜像
git push --mirror ssh://git@newgitlab:port/group1/gitproject-demo.git
  • --bare是裸仓库的意思,区别与git clone,他不是一个工作空间,不可以在目录下进行变更操作,即使操作了也不被接受, 执行命令后会复制全部的分支、标签,并且在命令执行过程中的所有远端的变动均被忽略。

–bare
Make a bare Git repository. That is, instead of creating <directory> and placing the administrative files in <directory>/.git, make the <directory> itself the $GIT_DIR. This obviously implies the --no-checkout because there is nowhere to check out the working tree. Also the branch heads at the remote are copied directly to corresponding local branch heads, without mapping them torefs/remotes/origin/. When this option is used, neither remote-tracking branches nor the related configuration variables are created.

  • --mirror镜像代码仓库,完完整整

Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not
limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository.
Newly created local refs will be pushed to the remote end, locally updated refs will be force
updated on the remote end, and deleted refs will be removed from the remote end. This is the
default if the configuration option remote..mirror is set.

在这里插入图片描述


原Gitlab Clone bare

ysw@DESKTOP-T7NDJ0A MINGW64 /d/codeMerge
$ git clone --bare  http://ip:port/xxxx/yyy.git
Cloning into bare repository 'uomSM.git'...
remote: Enumerating objects: 1438, done.
remote: Total 1438 (delta 0), reused 0 (delta 0), pack-reused 1438
Receiving objects: 100% (1438/1438), 872.14 MiB | 32.58 MiB/s, done.
Resolving deltas: 100% (420/420), done.

ysw@DESKTOP-T7NDJ0A MINGW64 /d/codeMerge

在这里插入图片描述

在这里插入图片描述

新的Gitlab创建新子群组(可选)

按需选择

在这里插入图片描述


推送bare版本到新Gitlab

```java
ysw@DESKTOP-T7NDJ0A MINGW64 /d/codeMerge
$ pwd
/d/codeMerge

ysw@DESKTOP-T7NDJ0A MINGW64 /d/codeMerge
$ cd uomSM.git/


- uom子群组名
- yyy自定义项目名称,我一般保持和旧的项目一致
$ git push --mirror https://新git地址/xxxx/uom/yyy.git

查看新Gitlab中的工程

在这里插入图片描述

OK,分支正常,提交日志正常。

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

设置个人访问令牌

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

记住该令牌

IDEA Clone Project

git clone https://xxxx/xx/xxx/xxxxx.git

输入 账号和个人访问令牌

在这里插入图片描述

常见问题

SSL certificate problem: self signed certificate in certificate chain

执行 git config --global http.sslverify false


remote: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of a password. See

请按照 《设置个人访问令牌》章节设置密码,并保存该密码,使用该密码访问Gitlab


如果设置完,不弹框,请按照如下步骤

1、配置用户信息

git config --global user.name [username]

git config --global user.email [email]

2、查询用户信息

git config --list

3、如果密码错误,会报这个错误fatal: Authentication failed for xxx ,请执行如下命令:

git config --system --unset credential.helper 

再次执行git命令,即可,亲测可用,无坑。
在这里插入图片描述

GitLab 容器版本升级过程中,使用相同数据卷是否可以避免数据同步或迁移,取决于多个因素,包括 GitLab 版本之间的兼容性、数据卷的挂载方式以及容器的配置方式。 ### 数据卷与版本兼容性 GitLab 容器化部署通常使用数据卷(volume)来持久化存储配置、日志、备份等数据。如果新旧版本GitLab 容器挂载了相同的数据卷,并且新版本与旧版本的数据结构兼容,则可以避免手动执行数据迁移操作。例如,在升级 GitLab 时,只要新版本支持旧版本的数据格式,GitLab 会自动完成数据的兼容性处理。 ### 数据卷的挂载方式 在 Docker 中,GitLab 通常会挂载以下关键目录: - `/etc/gitlab`:存储配置文件。 - `/var/opt/gitlab`:存储运行时数据,包括 Git 仓库、数据库等。 - `/var/log/gitlab`:存储日志文件。 如果新版本GitLab 容器继续使用这些相同的挂载点,并且数据格式未发生重大变化,则可以直接通过更新容器镜像并重启容器完成升级,而无需额外的数据迁移步骤 [^3]。 ### 版本兼容性要求 GitLab 官方建议,在升级 GitLab 容器版本时,应确保新版本与旧版本在数据结构和配置上兼容。例如,如果从 GitLab 13.3.2 升级到更高版本,需要确认新版本支持从 13.3.2 升级。如果版本之间存在不兼容的变更,则需要手动执行升级脚本或迁移操作 [^4]。 ### 数据备份的重要性 即使使用相同的数据卷进行升级,也建议在升级前执行完整的数据备份。可以通过 GitLab 自带的备份工具 `gitlab-rake gitlab:backup:create` 进行备份,以防止升级失败或数据损坏 [^2]。 ### 示例:升级 GitLab 容器并使用相同数据卷 ```bash # 停止当前 GitLab 容器 docker stop gitlab # 删除旧容器(保留数据卷) docker rm gitlab # 拉取新版本GitLab 镜像 docker pull gitlab/gitlab-ce:latest # 启动新版本容器,挂载相同的数据卷 docker run --name gitlab \ -d \ --restart always \ -p 80:80 -p 443:443 -p 22:22 \ -v /srv/gitlab/config:/etc/gitlab \ -v /srv/gitlab/data:/var/opt/gitlab \ -v /srv/gitlab/logs:/var/log/gitlab \ gitlab/gitlab-ce:latest ``` ### 总结 如果 GitLab 容器的新版本与旧版本兼容,并且使用相同的数据卷挂载方式,则可以避免手动数据迁移。然而,为了确保数据安全,建议在升级前执行完整的数据备份,并验证新版本的兼容性 [^5]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小工匠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值