GitLab使用Docker安装,挂载出三个目录到主机磁盘。由于主机GitLab数据所在的磁盘满了,要迁移GitLab到其他服务器上。
环境描述
服务器 | 描述 |
---|---|
A服务器 | 使用Docker安装了GitLab,并挂在出三个数据目录到主机GitLab数据所在的磁盘满了 |
B服务器 | 新GitLab服务器 |
实现方法
A服务器
- 保存GitLab镜像
1
docker save -o gitlab-images.tar container-backup:latest
- 停止GitLab服务
1
docker stop gitlab
- 备份数据目录
1
2
3
4# 进入GitLab数据目录
cd /srv/gitlab
# 压缩成tar,方便传输
tar -cvf gitlab-data-20200929.tar * - 生成B服务器的免密登录
因为备份文件太大,想用setsid后台传输文件。1
2
3
4
5# 在本地生成公私钥
ssh-keygen
# 回车直接确认...
# 复制公钥到远程服务器,root换成远程的用户名,ip换成B服务器的ip
ssh-copy-id -i ~/.ssh/id_rsa.pub [root]@[ip] - 发送GitLab镜像到B服务器
1
setsid scp gitlab-backup.tar [root]@[ip]:~
- 发送数据目录到B服务器
1
setsid scp gitlab-data-20200929.tar [root]@[ip]:~
B服务器
- 安装Docker
1
curl -fsSL get.docker.com -o get-docker.sh && sudo sh get-docker.sh --mirror Aliyun && sudo systemctl start docker && sudo systemctl enable docker
- 加载GitLab镜像
1
docker load -i gitlab-images.tar
- 解压数据目录
1
2
3mkdir -p /home/gitlab
# 解压
tar -vxf ~/gitlab-data-20200929.tar -C /home/gitlab - 启动
1
sudo docker run --detach --publish 443:443 --publish 80:80 --publish 23:22 --name gitlab --restart always --volume /home/gitlab/config:/etc/gitlab --volume /home/gitlab/logs:/var/log/gitlab --volume /home/gitlab/data:/var/opt/gitlab --privileged=true gitlab-images