新服务器上安装的gitlab最好与旧服务器上版本一致,版本不一致在新服务器恢复数据时可能会发生错误,查看gitlab版本的命令为
gitlab-rake gitlab:env:info
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的版本号。
拷贝将生成的tar备份文件拷贝到新服务器上相应的目录下,可以利用scp进行直接拷贝,新服务器上目录一般是/var/opt/gitlab/backups
恢复数据前,备份文件必须有运行权限,否则将会出错
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
gitlab-ctl restart
错误信息:500 Whoops,something went wrong on our end.
解决方案:
[root@VM_1_17_centos ~]# gitlab-rails dbconsole
psql (10.7)
Type "help" for help.
gitlabhq_production=>
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)
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
gitlabhq_production=> exit
gitlab-ctl restart
错误信息:Error while loading project data. please try again.
错误原因:api/v4/projects/${user}%2F${project} 500 (Internal Server Error)
解决方案:同3.1。
错误信息:500 Whoops,something went wrong on our end.
解决方案:同3.1。