在 CentOS 上恢复 GitLab 通常分为 系统级恢复(重装系统或 GitLab 损坏) 和 数据恢复(恢复到某一备份点) 两大类。下面按最常见、最安全的流程给你一套完整方案。
先判断你现在的状态:
gitlab-ctl status
rpm -qa | grep gitlab
cat /etc/gitlab/gitlab.rb | head
常见情况:
GitLab 备份通常在:
/var/opt/gitlab/backups/
文件名示例:
1690000000_2023_07_01_gitlab_backup.tar
如果备份在别的地方,复制到该目录。
⚠️ 版本必须一致(大版本+小版本)
查看原版本(如果还能看):
cat /opt/gitlab/version-manifest.txt
安装对应版本(示例:14.10.5):
yum install -y curl policycoreutils openssh-server
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash
yum install -y gitlab-ce-14.10.5-ce.0.el7.x86_64
若是 CentOS 8 / Rocky / Alma,请使用
dnf
gitlab-ctl reconfigure
gitlab-backup restore BACKUP=1690000000_2023_07_01
说明:
1690000000_2023_07_01 是备份文件名去掉 _gitlab_backup.taryes如果没有配置文件,会出现:
恢复 /etc/gitlab/gitlab.rb:
cp gitlab.rb.backup /etc/gitlab/gitlab.rb
gitlab-ctl reconfigure
gitlab-rake gitlab:check
gitlab-ctl restart
访问 GitLab 页面测试。
如果你还有:
/var/opt/gitlab/
yum install gitlab-ce-xxxx
gitlab-ctl reconfigure
gitlab-ctl stop
mv /var/opt/gitlab /var/opt/gitlab.bak
cp -a /old/path/var/opt/gitlab /var/opt/gitlab
chown -R git:git /var/opt/gitlab
gitlab-ctl start
⚠️ 成功率不稳定,不建议生产环境
gitlab-ctl restart
gitlab-ctl tail
journalctl -xe
gitlab-ctl reconfigure
gitlab-rake db:migrate
gitlab-rake gitlab:check
# 手动备份
gitlab-backup create
# 自动备份
crontab -e
0 2 * * * /opt/gitlab/bin/gitlab-backup create CRON=1
你可以直接告诉我以下信息(我可以一步步带你操作):
/var/opt/gitlab/backups/我可以给你 定制命令,不会让你误删数据 ✅