在 Linux 上“还原 GitLab”通常分为几种场景,我先按最常见、最实用的情况给你讲,你再对照自己的情况操作。
如果你之前用 GitLab 自带备份命令生成过备份:
/opt/gitlab/bin/gitlab-rake gitlab:backup:create
备份文件一般在:
/var/opt/gitlab/backups/
例如:
1659000000_2023_07_28_15.11.0_gitlab_backup.tar
放到目标机器相同目录。
gitlab-ctl stop puma
gitlab-ctl stop sidekiq
gitlab-rake gitlab:backup:restore BACKUP=1659000000_2023_07_28_15.11.0
不需要写
_gitlab_backup.tar
gitlab-ctl restart
gitlab-rake gitlab:check SANITIZE=true
备份不包含 /etc/gitlab/gitlab.rb 和 /etc/gitlab/ssl
还原方法:
cp gitlab.rb /etc/gitlab/gitlab.rb
gitlab-ctl reconfigure
docker exec -it gitlab bash
gitlab-rake gitlab:backup:restore BACKUP=时间戳
gitlab-ctl restart
如果是:
✅ 可尝试:
/var/opt/gitlab/git-data/repositories 是否还有残留步骤:
/etc/gitlabgitlab-ctl reconfiguregitlab:backup:restore❌ 版本不一致 → 无法还原
❌ 没有停服务 → 数据损坏
❌ 忘记恢复 gitlab.rb → 配置丢失
为了给你更精确的方案,请告诉我:
我可以直接给你一步一步命令。