Ubuntu下GitLab迁移步骤指南
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION(Omnibus安装)或gitlab-rake gitlab:env:info查看版本。使用GitLab内置的gitlab-rake工具创建完整备份,包含仓库、用户、CI/CD配置、数据库等所有数据:
sudo gitlab-rake gitlab:backup:create
默认备份文件存储在/var/opt/gitlab/backups目录,文件名格式为时间戳_版本_gitlab_backup.tar(如1715472000_15.0.0_gitlab_backup.tar)。可通过ls -l /var/opt/gitlab/backups确认备份文件是否存在。
在目标Ubuntu服务器上通过Omnibus包(推荐)安装GitLab,步骤如下:
curl https://packages.gitlab.com/gpg.key | sudo apt-key add -
echo "deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/gitlab.list
sudo apt-get update
sudo apt-get install gitlab-ce
/etc/gitlab/gitlab.rb,设置外部访问URL(如external_url 'http://新服务器IP'),保存后重新加载配置:sudo gitlab-ctl reconfigure
sudo gitlab-ctl start
http://新服务器IP,首次登录需修改默认密码。将旧服务器的备份文件复制到新服务器的/var/opt/gitlab/backups目录(需确保目录权限为gitlab-www:gitlab-www):
# 旧服务器执行(替换user/new_server为新服务器用户名/IP)
scp -r /var/opt/gitlab/backups/* user@new_server:/var/opt/gitlab/backups/
# 新服务器确认备份文件权限(可选)
sudo chown -R gitlab-www:gitlab-www /var/opt/gitlab/backups
若备份文件较大,可使用rsync替代scp提高传输效率。
unicorn(应用服务器)和sidekiq(后台任务处理器):sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
sudo gitlab-rake gitlab:backup:restore BACKUP=时间戳
其中时间戳为备份文件的前缀(如1715472000对应1715472000_15.0.0_gitlab_backup.tar)。恢复过程会提示“是否覆盖现有数据”,输入yes确认。gitlab.rb、SSL证书),需将其复制到新服务器对应目录:sudo cp /path/to/old/gitlab.rb /etc/gitlab/gitlab.rb
sudo cp -r /path/to/old/ssl /etc/gitlab/ssl
sudo gitlab-ctl reconfigure # 重新加载配置
恢复完成后,启动GitLab所有服务并检查状态:
sudo gitlab-ctl start
sudo gitlab-ctl status # 确认所有服务均为“run”状态
若服务未正常启动,可通过sudo gitlab-ctl tail查看日志排查问题。
external_url(如http://新服务器IP),确认能正常登录。scp -i 私钥)。/etc/gitlab/gitlab.rb,添加:gitlab_rails['backup_keep_time'] = 604800 # 保留7天备份
gitlab_rails['backup_cron'] = "0 3 * * *" # 每天凌晨3点执行
保存后重新加载配置:sudo gitlab-ctl reconfigure。