以下是在Debian上進行GitLab數據遷移的常用技巧及關鍵步驟:
備份數據
使用GitLab自帶工具備份所有數據(含倉庫、配置、用戶信息等):
sudo gitlab-rake gitlab:backup:create
備份文件默認存放在/var/opt/gitlab/backups/
目錄,可通過gitlab.rb
修改路徑。
版本一致性檢查
確保新舊服務器的GitLab版本一致或兼容,避免遷移后出現不兼容問題。
傳輸備份文件
通過scp
命令將備份文件(含gitlab.rb
和gitlab-secrets.json
配置文件)從舊服務器復制到新服務器對應目錄:
scp /var/opt/gitlab/backups/backup.tar root@new_server:/var/opt/gitlab/backups/
scp /etc/gitlab/gitlab.rb root@new_server:/etc/gitlab/
scp /etc/gitlab/gitlab-secrets.json root@new_server:/etc/gitlab/
恢復數據
在新服務器上停止GitLab服務后,使用備份文件恢復數據:
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
sudo gitlab-rake gitlab:backup:restore BACKUP=備份文件名
恢復后需確保文件權限正確(chown git:git
)。
配置與重啟
gitlab.rb
配置文件(如external_url
),確保與新環境匹配。sudo gitlab-ctl reconfigure
使配置生效,然后重啟服務:sudo gitlab-ctl restart
驗證遷移結果
高級技巧(可選)
rsync
同步倉庫數據(需停止服務),或通過GitLab API遷移特定項目。gitlab-migrator
)批量遷移用戶權限和合并請求。注意事項:
scp
或rsync
over SSH)。參考來源: