CentOS環境下GitLab數據遷移詳細步驟
yum install -y policycoreutils openssh-server openssh-clients postfix
systemctl enable sshd && systemctl start sshd # 啟用SSH服務(用于傳輸文件)
systemctl enable postfix && systemctl start postfix # 啟用郵件服務(用于GitLab通知)
GitLab數據主要分為三類,需分別備份:
gitlab-rake
工具創建包含數據庫、倉庫、配置等的完整備份,備份文件默認存儲在/var/opt/gitlab/backups
目錄:# 停止GitLab相關服務(確保數據一致性)
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
# 創建備份(備份文件名為時間戳格式,如171017_120000_gitlab_backup.tar)
gitlab-rake gitlab:backup:create
# 啟動服務(備份完成后恢復)
gitlab-ctl start
/var/opt/gitlab/git-data/repositories
/var/opt/gitlab/postgresql
(PostgreSQL數據目錄)/var/opt/gitlab/users
/etc/gitlab/gitlab.rb
、/etc/gitlab/gitlab-secrets.json
(密鑰文件,務必備份)rsync
命令(保留權限):rsync -aHAX /var/opt/gitlab/git-data/repositories/ /tmp/git_repos_backup/
rsync -aHAX /etc/gitlab/gitlab.rb /tmp/git_config_backup/
# 添加GitLab官方YUM倉庫
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
# 安裝GitLab CE(社區版)
yum install -y gitlab-ce
/etc/gitlab/gitlab.rb
,設置外部訪問URL(需與舊服務器一致,避免用戶訪問中斷):external_url 'http://新服務器IP' # 若用HTTPS,需配置SSL證書路徑
/var/opt/gitlab/backups
下的.tar
文件)復制到新服務器的相同目錄:scp root@舊服務器IP:/var/opt/gitlab/backups/171017_120000_gitlab_backup.tar root@新服務器IP:/var/opt/gitlab/backups/
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-rake gitlab:backup:restore BACKUP=171017_120000 # 171017_120000為備份文件名(不含.tar后綴)
gitlab-ctl start
rsync -aHAX -e ssh /tmp/git_repos_backup/ root@新服務器IP:/var/opt/gitlab/git-data/repositories/
rsync -aHAX -e ssh /tmp/git_config_backup/gitlab.rb root@新服務器IP:/etc/gitlab/
gitlab-ctl stop postgresql
rm -rf /var/opt/gitlab/postgresql/*
rsync -aHAX -e ssh /tmp/git_db_backup/ root@新服務器IP:/var/opt/gitlab/postgresql/
gitlab-ctl start postgresql
/etc/gitlab/gitlab.rb
中的以下參數:external_url 'http://新服務器IP:新端口' # 如80→8080,需同步修改SSH端口(若用SSH克?。?/span>
gitlab_rails['gitlab_shell_ssh_port'] = 新端口 # 若SSH端口變更
gitlab-ctl reconfigure # 重新生成配置文件
gitlab-ctl restart # 重啟所有服務
http://新服務器IP
,使用舊服務器的用戶名/密碼登錄,檢查項目、用戶、權限是否正常。git clone http://新服務器IP/項目路徑.git
,測試提交(git push
)和拉?。?code>git pull)功能。gitlab-ctl tail # 實時查看所有服務日志
unicorn
、sidekiq
),避免數據寫入導致不一致。rsync
時添加-aHAX
參數,保留文件權限和屬主(如git
用戶對倉庫的讀寫權限)。chcon -R -t var_opt_t /var/opt/gitlab
),避免權限拒絕。