gitlab数据迁移

gitlab数据迁移

  • 1 前提条件
  • 2 数据迁移步骤
    • 2.1 旧服务器上备份数据
    • 2.2 迁移备份到新服务器
    • 2.3 新服务器上恢复数据
    • 2.4 新服务器上重启服务
  • 3 数据迁移后可能存在的问题
    • 3.1 删除project失败
    • 3.2 Web-IDE打不开
    • 3.3 点击admin area的任何设定时报错

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。

你可能感兴趣的:(gitlab,gitlab,linux,服务器,运维)