在 Linux 上的 GitLab 中“恢复仓库”通常分为几种场景,下面按最常见情况给你说明,你可以对号入座。
GitLab 默认会生成备份文件在:
/var/opt/gitlab/backups/
查看是否有备份:
ls -lh /var/opt/gitlab/backups/
备份文件类似:
1690000000_2023_07_20_gitlab_backup.tar
gitlab-ctl stop unicorn
gitlab-ctl stop puma
gitlab-ctl stop sidekiq
gitlab-rake gitlab:backup:restore BACKUP=1690000000_2023_07_20
⚠️ 注意:
BACKUP 只写时间戳部分gitlab-ctl restart
gitlab-rake gitlab:check SANITIZE=true
git push origin <branch-name>
在本地查找历史:
git reflog
恢复:
git checkout -b recover-branch <commit-id>
git push origin recover-branch
GitLab 仓库物理路径一般在:
/var/opt/gitlab/git-data/repositories/
git push --mirror git@gitlab:group/project.git
如果你只是:
如果是容器化部署:
docker exec -it gitlab gitlab-rake gitlab:backup:restore BACKUP=xxx
✅ 唯一可靠方式:
git push --force --all
git push --force --tags
我可以直接给你一套可执行的恢复脚本。