Centos7-GitLab 备份与还原
备份
宿主机部署的GitLab
gitlab-rake gitlab:backup:create
Docker部署的Gitlab
docker exec gitlab gitlab-rake gitlab:backup:create
这里的
gitlab
就是您的容器名称
备份完成后,/var/opt/gitlab/backups
目录会生成文件名是 [TIMESTAMP]_gitlab_backup.tar 的备份文件.
如果docker 做了目录映射,则自行判断
还原
上传 [TIMESTAMP]_gitlab_backup.tar 文件到 /var/opt/gitlab/backups/
目录
停止 gitlab 服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-ctl status
docker部署同理~进入docker容器停止即可
执行还原命令
gitlab-rake gitlab:backup:restore BACKUP=1659555181_2022_08_03
重启
gitlab-ctl restart
检查 gitlab 状态
gitlab-ctl status
gitlab-rake gitlab:check SANITIZE=true
Docker环境下,每日定时备份
备份脚本如下:
[root@gitlab ~]# cat /root/gitlab_backup.sh
#! /bin/bash
case "$1" in
start)
docker exec gitlab gitlab-rake gitlab:backup:create
sleep 30
find "/data/gitlab/data/backups" -name "*.tar" -ctime +3 -type f -exec rm -rf {} \;
;;
esac
[root@gitlab ~]# crontab -l
0 2 * * * /root/gitlab_backup.sh start
如需要验证,可安装同版本的 gitlab
docker 部署命令:
docker run --detach --publish 443:443 \
--publish 19922:22 --publish 80:80 \
--name gitlab --restart always \
--volume /data/gitlab/config:/etc/gitlab \
--volume /data/gitlab/logs:/var/log/gitlab \
--volume /data/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:9.0.0-ce.0