gitlab数据迁移

1 前提条件

新服务器上安装的gitlab最好与旧服务器上版本一致,版本不一致在新服务器恢复数据时可能会发生错误,查看gitlab版本的命令为

gitlab-rake gitlab:env:info

2 数据迁移步骤

2.1 旧服务器上备份数据

gitlab-rake gitlab:backup:create RAILS_ENV=production

备份后的文件一般是位于/var/opt/gitlab/backups下, 自动生成文件名如1599223012_gitlab_backup.tar,其中1599223012为备份的时间点。自动生成文件名可能也为1599223012_2020_09_04_13.2.3_gitlab_backup.tar,其中2020_09_04为备份的日期,13.2.3为gitlab的版本号。

2.2 迁移备份到新服务器

拷贝将生成的tar备份文件拷贝到新服务器上相应的目录下,可以利用scp进行直接拷贝,新服务器上目录一般是/var/opt/gitlab/backups

2.3 新服务器上恢复数据

恢复数据前,备份文件必须有运行权限,否则将会出错

chmod 755 1599223012_gitlab_backup.tar

恢复数据的命令为

gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=1599223012

注意:BACKUP后面的时间点必须与原服务器备份后文件名中的时间点一致。

恢复数据过程中两步确认均选择yes

Before restoring the database, we will remove 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
This task will now rebuild the authorized_keys file.
You will lose any data stored in the authorized_keys file.
Do you want to continue (yes/no)? yes

如果备份文件名为1599223012_2020_09_04_13.2.3_gitlab_backup.tar,恢复数据时可能提示找不到1599223012_gitlab_backup.tar文件,这是只需要对备份文重命名后恢复数据即可

mv 1599223012_2020_09_04_13.2.3_gitlab_backup.tar 1599223012_gitlab_backup.tar
gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=1599223012

2.4 新服务器上重启服务

gitlab-ctl restart

3 数据迁移后可能存在的问题

3.1 删除project失败

错误信息:500 Whoops,something went wrong on our end.
解决方案:

  • 进入DB控制台
[root@VM_1_17_centos ~]# gitlab-rails dbconsole
psql (10.7)
Type "help" for help.

gitlabhq_production=> 
  • Reset CI/CD variables
    Check the ci_group_variables and ci_variables tables:
    Those are the variables that you need to delete.
gitlabhq_production=> SELECT * FROM public."ci_group_variables";
 id | key | value | encrypted_value | encrypted_value_salt | encrypted_value_iv | group_id | protected | created_at | updated_at | masked | variable_type 
----+-----+-------+-----------------+----------------------+--------------------+----------+-----------+------------+------------+--------+---------------
(0 rows)

gitlabhq_production=> SELECT * FROM public."ci_variables";
 id | key | value | encrypted_value | encrypted_value_salt | encrypted_value_iv | project_id | protected | environment_scope | masked | variable_type 
----+-----+-------+-----------------+----------------------+--------------------+------------+-----------+-------------------+--------+---------------
(0 rows)
  • Reset Runner registration tokens
    Clear all the tokens for projects, groups, and the whole instance:
gitlabhq_production=> UPDATE projects SET runners_token = null, runners_token_encrypted = null;
UPDATE 16
gitlabhq_production=> UPDATE namespaces SET runners_token = null, runners_token_encrypted = null;
UPDATE 27
gitlabhq_production=> UPDATE application_settings SET runners_registration_token_encrypted = null;
UPDATE 1
gitlabhq_production=> UPDATE ci_runners SET token = null, token_encrypted = null;
UPDATE 0
  • 退出DB控制台
gitlabhq_production=> exit
  • 重启服务
gitlab-ctl restart

3.2 Web-IDE打不开

错误信息:Error while loading project data. please try again.
错误原因:api/v4/projects/${user}%2F${project} 500 (Internal Server Error)
解决方案:同3.1。

3.3 点击admin area的任何设定时报错

错误信息:500 Whoops,something went wrong on our end.
解决方案:同3.1。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Janloinge

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

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

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

打赏作者

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

抵扣说明:

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

余额充值