容器自动化部署--gitlab迁移

本文详细阐述了如何在GitLab版本一致的前提下,从旧服务器创建备份,迁移至新服务器,并通过恢复命令无缝还原数据库,确保服务一致性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前提:迁移机器和被迁移机器的gitlab版本必须一致。

 

浏览器输入:http://localhost/help即可查看

或者点击这个小扳手

 

1、Gitlab 创建备份


1.1 创建备份文件


首先需要把老服务器上的Gitlab整体备份,使用Gitlab一键安装包安装Gitlab非常简单, 同样的备份恢复与迁移也比较简单,使用一条命令即可创建完整的Gitlab备份。

gitlab-rake gitlab:backup:create

使用以上命令会在/var/opt/gitlab/backups目录下创建一个名称类似为1624434930_2021_06_23_13.12.3_gitlab_backup.tar的压缩包, 这个压缩包就是Gitlab整个的完整部分, 其中开头的1624434930_2021_06_23_13.12.3是备份创建的日期和gitlab的版本号

/etc/gitlab/gitlab.rb 配置文件须备份
/var/opt/gitlab/nginx/conf nginx.conf配置文件
/etc/postfix/main.cf 邮件配置备份

# 更改Gitlab备份目录

 

通过修改/etc/gitlab/gitlab.rb配置文件来修改默认存放备份文件的目录

gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"


默认是带有#的,表示默认的位置为:/var/opt/gitlab/backups修改为你想存放备份的目录即可,去掉#后修改为想要的位置即可,如下:

gitlab_rails['backup_path'] = '/mnt/backups'

# 修改完成后重载配置文件即可:

gitlab-ctl reconfigure

2、 Gitlab迁移

 

将gitlab老服务器上生成的备份文件想办法拷贝到gitlab新服务器上,这里我是用的scp命令,第一次执行会提示是否连接,输入yes即可。

[root@localhost ~]# scp /var/opt/gitlab/backups/1624436184_2021_06_23_13.12.3_gitlab_backup.tar root@192.168.6.12:/var/opt/gitlab/backups/
The authenticity of host '192.168.6.12 (192.168.6.12)' can't be established.
ECDSA key fingerprint is SHA256:Q3fO68CJgJqgqDRcqp2Hxm/T0eUMa06PxbBBhf7ZK94.
ECDSA key fingerprint is MD5:24:5f:f9:9c:f6:23:4b:12:43:24:d1:fc:7f:53:07:23.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.6.12' (ECDSA) to the list of known hosts.
root@192.168.6.12's password: 
1624436184_2021_06_23_13.12.3_gitlab_backup.tar                                                                                                                                                                100% 8951MB  63.0MB/s   02:22    

复制完成后到新机器上查看:

[root@localhost ~]# clear
[root@localhost ~]# cd /var/opt/gitlab/backups/
[root@localhost backups]# ls 
1624436184_2021_06_23_13.12.3_gitlab_backup.tar

这时候再授予该压缩文件可执行权:

chmod 755 1624436184_2021_06_23_13.12.3_gitlab_backup.tar

3、执行命令停止相关数据连接服务

# 停止相关数据连接服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

 

4、执行命令从备份文件中恢复Gitlab

 

执行命令从备份文件中恢复Gitlab;格式如下:gitlab-rake gitlab:backup:restore BACKUP=备份文件编号

[root@localhost backups]# gitlab-rake gitlab:backup:restore BACKUP=1624436184_2021_06_23_13.12.3

敲完命令后,出现第一个交互页面,

[root@localhost backups]# gitlab-rake gitlab:backup:restore BACKUP=1624436184_2021_06_23_13.12.3
Unpacking backup ... done
Before restoring the database we recommend removing all existing
tables to avoid future upgrade problems. Be aware that if you have
custom tables in the GitLab database these tables and all data will be
removed.

Do you want to continue (yes/no)? 

输入“yes”继续。

出现第二个交互页面,

Put GitLab hooks in repositories dirs [DONE]
done
Restoring uploads ... 
done
Restoring builds ... 
done
Restoring artifacts ... 
done
Restoring pages ... 
done
Restoring lfs objects ... 
done
This will rebuild an authorized_keys file.
You will lose any data stored in authorized_keys file.
Do you want to continue (yes/no)? 

输入“yes”继续。

 

启动Gitlab

sudo gitlab-ctl start

打开迁移后的Gitlab,进行对比

老Gitlab服务器截图

新Gitlab服务器截图

对比,可以发现,两台服务器除了IP地址不一样之外,其他的内容完全一模一样,迁移成功!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值