Other

Docker Gitlab数据迁移之备份恢复

1,旧gitlab容器执行:

gitlab-rake gitlab:backup:create

会生成文件到默认路径如:

/var/opt/gitlab/backups/1562751885_2019_07_10_11.10.2_gitlab_backup.tar

2,旧宿主机执行:

docker cp gitlab:/var/opt/gitlab/backups/1562751885_2019_07_10_11.10.2_gitlab_backup.tar  .

从旧容器内将本分文件拷贝出来

3,将旧gitlab容器拷贝到新docker(如果新老gitlab版本一致可忽略此步骤):

# 提交保存旧容器(容器名:gitlab)
docker commit gitlab gitlab/gitlab-ce:11.0.2
# 从旧docker导出gitlab容器镜像
docker export gitlab > gitlab-ce-11.0.2.img
# 拷贝到新docker机器
scp gitlab-ce-11.0.2.img 10.0.0.162:/mnt/disk1
# 在新docker导入
docker import - gitlab/gitlab-ce:11.0.2 < /mnt/disk1/gitlab-ce-11.0.2.img
# 在新docker创建gitlab容器并运行
GITLAB_HOME=/mnt/disk1/gitlab
docker run -d --hostname gitlab --publish 5443:443 --publish 5080:80 --publish 5022:22 --name gitlab --restart always \
--volume $GITLAB_HOME/config:/etc/gitlab \
--volume $GITLAB_HOME/logs:/var/log/gitlab \
--volume $GITLAB_HOME/data:/var/opt/gitlab gitlab/gitlab-ce:11.0.2 /assets/wrapper

注:后面一定要加/assets/wrapper(可能是docker导出导入丢了启动命令,不然run报错)

4,新gitlab容器恢复(即迁移,注:版本一定要相同,上述第3步可解决):

进入新gitlab容器:

docker exec -it gitlab bash
停止相关数据连接服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
注,备份文件必须是git用户所有者(用root下导入才需要)
chown -R git:git /var/opt/gitlab/backups/1562751885_2019_07_10_11.10.2_gitlab_backup.tar

从1562751885_2019_07_10_11.10.2编号备份中恢复

gitlab-rake gitlab:backup:restore BACKUP=1562751885_2019_07_10_11.10.2
启动Gitlab
sudo gitlab-ctl start

FQA

1,HTTP 502: Whoops, GitLab is taking too much time to respond.
解决:
# gitlab-ctl stop

# vi /etc/gitlab/gitlab.rb   (取消注释并修改端口)
unicorn['port'] = 8801

# gitlab-ctl reconfigure  (重新生成配置)
# gitlab-ctl restart
# lsof -i:8081        (check whether unicorn has started properly)

有时候修改配置后要不断刷新才能生效 原因参考

2,点击项目Clone按钮,地址却是localhost(或主机名),如何改为域名?
vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
修改节点(注不包含http前缀):production.gitlab.host=git.xxx.com

留言

您的电子邮箱地址不会被公开。