最近一直在折腾gitlab 代码管理系统
采用docker搭建 镜像网址 https://hub.docker.com/
技术交流 http://idea.coderyj.com/
docker-ce的12.0.9
的镜像docker pull gitlab/gitlab-ce:12.0.9-ce.0
docker run -itd -p 9980:80 -p 9922:22 -u root -v $PWD/data/log:/var/log/gitlab -v $PWD/data/opt:/var/opt/gitlab -v $PWD/data/etc:/etc/gitlab --privileged=true --name=gitlab --restart always gitlab/gitlab-ce:12.0.9-ce.0
# 放在/data/gitlab 目录下面了 里面的子目录它会自己创建
docker run -itd -p 9980:80 -p 9922:22 -u root -v /data/gitlab/log:/var/log/gitlab -v /data/gitlab/opt:/var/opt/gitlab -v /data/gitlab/etc:/etc/gitlab --privileged=true --name=gitlab --restart always gitlab/gitlab-ce:12.0.9-ce.0
docker exec gitlab gitlab-ctl status
恢复的版本必须和安装的版本保持一致
1.数据库+代码文件 gitlab_backup.tar
2.配置文件 gitlab.rb
3.数据库秘钥,用于解密 gitlab-secrets.json
gitlab._backup.tar
文件上传到 /data/gitlab/opt/backups
目录下gitlab.rb, gitlab-secrets.json
文件上传到 /data/gitlab/etc
目录下# 进入容器
docker exec -it gitlab /bin/bash
# 关闭数据库连接
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
# 进入备份目录 `/var/opt/gitlab/backups/`
cd /var/opt/gitlab/backups/
# 开始恢复 注意文件名不要 后面的 gitlab这些
gitlab-rake gitlab:backup:restore BACKUP=1703008988_2023_12_20_12.0.9
cd /etc/gitlab
vi gitlab.rb
# 将 external_url 'http://0.0.0.0:80
external_url 'http://0.0.0.0:80'
# 进入容器
docker exec -it gitlab /bin/bash
# 备份命令
gitlab-rake gitlab:backup:create
# 备份目录
docker 内部目录 /var/opt/gitlab/backups
宿主机目录 /data/gitlab/opt/backups
# 复制docker内部文件到宿主机目录 这一步是挂在在宿主机上可以不操作
docker container cp 容器:/var/opt/gitlab/backups/备份文件 /var/opt/gitlab/backups/
备份的时候不会备份
gitlab.rb, gitlab-secrets.json
需要我们手动保存
#安装docker
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce*
systemctl start docker
#下载gitlab images
docker pull gitlab/gitlab-ce:12.0.9-ce.0
#安装docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
#启动
#/usr/local/docker/gitlab 在此路径下放置docker-compose.yml
cd /usr/local/docker/gitlab
docker-compose up -d
#恢复开始
docker exec $(docker ps | grep gitlab/gitlab-ce:12.0.9-ce.0|awk '{print $1}') /bin/bash -c "
gitlab-ctl stop unicorn;\
gitlab-ctl stop sidekiq;\
gitlab-rake gitlab:backup:restore force=yes BACKUP=$(ls /var/opt/gitlab/backups/ |grep _gitlab |awk -F "_gitlab" '{print $1}');\
gitlab-ctl start;"