GitLab迁移与恢复

gitlab-ee商业版
gitlab-ce社区版

目录

  • GitLab迁移与恢复
    • GitLab新服务器(CentOS7)上安装指定版本GitLab
    • GitLab的迁移及数据恢复
    • 样例-GitLab迁移的具体过程
    • gitlab-ctl常用命令介绍
    • 其他参考文章

GitLab迁移与恢复

GitLab新服务器(CentOS7)上安装指定版本GitLab

当我们在做gitlab服务器迁移的时候需要两台服务器中的gitlab相同,如果不同则不让回复git备份。这样我们就要安装指定版本的gitlab。
1 安装依赖软件

yum -y install policycoreutils openssh-server openssh-clients postfix

2 使用命令检查是否安装以上软件

rpm -qa|grep 软件名

3 设置postfix开机自启,并启动,postfix支持gitlab发信功能

systemctl enable postfix
systemctl start postfix

4 添加GitLab社区版Package

curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

5 安装gitlab社区版12.7.0

sudo yum install -y gitlab-ce-12.7.0

6 查看 GitLab 版本号

cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

7 修改配置文件,配置GitLab站点Url

sudo vi /etc/gitlab/gitlab.rb
将
external_url 'http://gitlab.example.com'
改成
external_url 'http://ip' 

8 重新配置GitLab并启动

sudo gitlab-ctl reconfigure

9 重启所有 gitlab 组件

sudo gitlab-ctl restart

GitLab的迁移及数据恢复

注意:
1.新服务器上的Gitlab的版本必须与创建备份时的Gitlab版本号相同.
比如新服务器安装的是较新版本的Gitlab, 那么迁移之前, 最好将老服务器的Gitlab 升级和新服务一致的版本再进行备份

2.安装gitlab的磁盘目录空间要足够,如果不够可考虑将gitlab的数据目录更改成其他空间足够的磁盘目录上 参考:更改GitLab默认数据存储目录

1 停止gitlab服务

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-ctl status

2 将老服务器/var/opt/gitlab/backups目录下的备份文件拷贝到新服务器上的/var/opt/gitlab/backups

此处老服务器的备份地址不是默认的/var/opt/gitlab/backups,已经更改过

scp /home/gitlab_backup/*gitlab_backup.tar 
[email protected]:/var/opt/gitlab/backups

3 转到备份目录,修改备份文件权限

cd /var/opt/gitlab/backups
chmod 777 11585185505_2020_03_26_12.7.0_gitlab_backup.tar

4 执行数据恢复

gitlab-rake gitlab:backup:restore BACKUP=11585185505_2020_03_26_12.7.0

5 再次启动GitLab

gitlab-ctl start
gitlab-ctl status

6 恢复命令完成后,check检查一下恢复情况

gitlab-rake gitlab:check SANITIZE=true

注意:
如果启动GitLab后,访问出现500,这是因为程序还没完全启动,需要等一会儿访问

7 可以登录gitlab地址进行验证,所有的数据都做了恢复

样例-GitLab迁移的具体过程

1585185505_2020_03_26_12.7.0_gitlab_backup.tar
[root@vl-bg-anaylsis02 backups]# chmod 777 1585185505_2020_03_26_12.7.0_gitlab_backup.tar
[root@vl-bg-anaylsis02 backups]# ls
1585185505_2020_03_26_12.7.0_gitlab_backup.tar
[root@vl-bg-anaylsis02 backups]# gitlab-rake gitlab:backup:restore BACKUP=1585185505
The backup file 1585185505_gitlab_backup.tar does not exist!
[root@vl-bg-anaylsis02 backups]# gitlab-rake gitlab:backup:restore BACKUP=1585185505_2020_03_26_12.7.0_gitlab_backup.tar
The backup file 1585185505_2020_03_26_12.7.0_gitlab_backup.tar_gitlab_backup.tar does not exist!
[root@vl-bg-anaylsis02 backups]# gitlab-rake gitlab:backup:restore BACKUP=1585185505_2020_03_26_12.7.0
Unpacking backup ... done
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
Removing all tables. Press `Ctrl-C` within 5 seconds to abort
2020-03-26 17:44:44 +0800 -- Cleaning the database ...
2020-03-26 17:44:48 +0800 -- done
2020-03-26 17:44:48 +0800 -- Restoring database ...
Restoring PostgreSQL database gitlabhq_production ... SET
SET
SET
SET
SET
 set_config
------------

(1 row)

SET
SET
SET
SET
ERROR:  relation "public.timelogs" does not exist
.........
ERROR:  table "alerts_service_data" does not exist
ERROR:  sequence "abuse_reports_id_seq" does not exist
ERROR:  table "abuse_reports" does not exist
ERROR:  must be owner of extension pg_trgm
ERROR:  must be owner of extension plpgsql
ERROR:  must be owner of schema public
ERROR:  schema "public" already exists
ALTER SCHEMA
ERROR:  must be owner of schema public
CREATE EXTENSION
ERROR:  must be owner of extension plpgsql
CREATE EXTENSION
ERROR:  must be owner of extension pg_trgm
.......
ALTER TABLE
ALTER TABLE
.......
WARNING:  no privileges were granted for "public"
GRANT
[DONE]
2020-03-26 17:44:58 +0800 -- done
2020-03-26 17:44:58 +0800 -- Restoring repositories ...
.........
2020-03-26 17:48:51 +0800 -- done
2020-03-26 17:48:51 +0800 -- Restoring uploads ...
2020-03-26 17:48:52 +0800 -- done
2020-03-26 17:48:52 +0800 -- Restoring builds ...
2020-03-26 17:48:52 +0800 -- done
2020-03-26 17:48:52 +0800 -- Restoring artifacts ...
2020-03-26 17:48:52 +0800 -- done
2020-03-26 17:48:52 +0800 -- Restoring pages ...
2020-03-26 17:48:52 +0800 -- done
2020-03-26 17:48:52 +0800 -- Restoring lfs objects ...
2020-03-26 17:48:52 +0800 -- done
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

Deleting tmp directories ... done
done
done
done
done
done
done
done
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need to restore these files manually.
Restore task is done.

[root@vl-bg-anaylsis02 backups]# vim /etc/gitlab/gitlab.rb
[root@vl-bg-anaylsis02 backups]# gitlab-ctl start
ok: run: alertmanager: (pid 88426) 1476s
ok: run: gitaly: (pid 88321) 1478s
ok: run: gitlab-exporter: (pid 88320) 1479s
ok: run: gitlab-workhorse: (pid 88300) 1479s
ok: run: grafana: (pid 88490) 1475s
ok: run: logrotate: (pid 87120) 1599s
ok: run: nginx: (pid 87079) 1605s
ok: run: node-exporter: (pid 88311) 1479s
ok: run: postgres-exporter: (pid 88469) 1476s
ok: run: postgresql: (pid 86337) 1700s
ok: run: prometheus: (pid 88356) 1478s
ok: run: redis: (pid 86093) 1713s
ok: run: redis-exporter: (pid 88343) 1478s
ok: run: sidekiq: (pid 97248) 0s
ok: run: unicorn: (pid 97254) 1s
[root@vl-bg-anaylsis02 backups]# gitlab-rake gitlab:check SANITIZE=true
Checking GitLab subtasks ...

Checking GitLab Shell ...

GitLab Shell: ... GitLab Shell version >= 11.0.0 ? ... OK (11.0.0)
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Internal API available: OK
Redis available via internal API: OK
gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Gitaly ...

Gitaly: ... default ... OK

Checking Gitaly ... Finished

Checking Sidekiq ...

Sidekiq: ... Running? ... yes
Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking Incoming Email ...

Incoming Email: ... Reply by email is disabled in config/gitlab.yml

Checking Incoming Email ... Finished

Checking LDAP ...

LDAP: ... LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab App ...

Git configured correctly? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config up to date? ... yes
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory exists? ... yes
Uploads directory has correct permissions? ... yes
Uploads directory tmp has correct permissions? ... yes
Init script exists? ... skipped (omnibus-gitlab has no init script)
Init script up-to-date? ... skipped (omnibus-gitlab has no init script)
Projects have namespace: ...
4/3 ... yes
1/4 ... yes
1/5 ... yes
1/8 ... yes
10/9 ... yes
10/10 ... yes
10/11 ... yes
13/12 ... yes
12/13 ... yes
12/14 ... yes
16/15 ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.5.3 ? ... yes (2.6.5)
Git version >= 2.22.0 ? ... yes (2.24.1)
Git user has default SSH configuration? ... yes
Active users: ... 29
Is authorized keys file accessible? ... yes

Checking GitLab App ... Finished


Checking GitLab subtasks ... Finished

[root@vl-bg-anaylsis02 backups]#

gitlab-ctl常用命令介绍

命令 说明
check-config 检查在gitlab中是否有任何配置。在指定版本中删除的rb
deploy-page 安装部署页面
diff-config 将用户配置与包可用配置进行比较
remove-accounts 删除所有用户和组
upgrade 升级
service-list 查看所有服务
once 如果GitLab服务停止了就启动服务,如果已启动就不做任何操作
restart 重启GitLab服务
start 如果GitLab服务停止了就启动服务,如果已启动就重启服务
stop 停止GitLab服务
status 查看GitLab服务状态
reconfigure 重新配置GitLab并启动

其他参考文章

https://about.gitlab.com/install/#centos-7
https://juejin.im/entry/5b7fa6fde51d4538a31b3f4a
清华大学开源软件镜像站
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/

你可能感兴趣的:(运维)