GitLab – Backup & Restore

Loading

測試環境為 CentOS 8 x86_64 (虛擬機)

Gitlab 的備份與還原參考官方網站說明:

  • Backup – https://docs.gitlab.com/ee/administration/backup_restore/backup_gitlab.html
  • Restore – https://docs.gitlab.com/ee/administration/backup_restore/restore_gitlab.html

Gitlab 有提供指令就可以把所有資料(包含資料庫) 做備份與還原.

  • Backup
    以下兩個檔案因為包含一些密碼等資料所以需要手動備份起來.

    /etc/gitlab/gitlab-secrets.json
    /etc/gitlab/gitlab.rb
    

    以下指令可以把所有資料(包含資料庫)備份起來.

    [root@localhost ~]# gitlab-backup create
    

    備份檔案置於 /var/opt/gitlab/backups/

    [root@localhost ~]# ll /var/opt/gitlab/backups/
    total 253632
    -rw------- 1 git git    450560 Nov  5 23:00 1699254029_2023_11_06_16.5.1_gitlab_backup.tar
    

    這樣就備份完成.

  • Restore
    如果是全新的系統,需先安裝好 Gitlab – https://benjr.tw/105652 , 須注意安裝的版本需與 Backup 資料的 Gitlab 一致.

    需先將前面備份好了的 3個檔案複製到以下路徑.

    /etc/gitlab/gitlab-secrets.json
    /etc/gitlab/gitlab.rb
    /var/opt/gitlab/backups/1699254029_2023_11_06_16.5.1_gitlab_backup.tar
    

    停止服務.

    [root@localhost ~]# gitlab-ctl stop puma
    [root@localhost ~]# gitlab-ctl stop sidekiq
    

    檢視

    [root@localhost ~]# gitlab-ctl status
    

    還原資料,指定的名稱不包含 _gitlab_backup.tar

    [root@localhost ~]# gitlab-backup restore BACKUP=1699254029_2023_11_06_16.5.1
    

    重啟 Gitlab 並檢查.

    [root@localhost ~]# gitlab-ctl restart
    [root@localhost ~]# gitlab-rake gitlab:check SANITIZE=true
    

    還原完成.

遇過的錯誤

  • Backup 與 Restore 環境的 Gitlab 版本不一致.

    2024-01-17 03:25:18 UTC -- Unpacking backup ... done
    GitLab version mismatch:
      Your current GitLab version (16.7.3) differs from the GitLab version in the backup!
      Please switch to the following version and try again:
      version: 16.5.1
    
    Hint: git checkout v16.5.1
    2024-01-17 03:25:18 UTC -- Deleting tar staging files ...
    2024-01-17 03:25:18 UTC -- Cleaning up /var/opt/gitlab/backups/backup_information.yml
    2024-01-17 03:25:18 UTC -- Cleaning up /var/opt/gitlab/backups/db
    2024-01-17 03:25:18 UTC -- Cleaning up /var/opt/gitlab/backups/repositories
    2024-01-17 03:25:19 UTC -- Cleaning up /var/opt/gitlab/backups/uploads.tar.gz
    2024-01-17 03:25:19 UTC -- Cleaning up /var/opt/gitlab/backups/builds.tar.gz
    2024-01-17 03:25:19 UTC -- Cleaning up /var/opt/gitlab/backups/artifacts.tar.gz
    2024-01-17 03:25:19 UTC -- Cleaning up /var/opt/gitlab/backups/pages.tar.gz
    2024-01-17 03:25:19 UTC -- Cleaning up /var/opt/gitlab/backups/lfs.tar.gz
    2024-01-17 03:25:19 UTC -- Cleaning up /var/opt/gitlab/backups/terraform_state.tar.gz
    2024-01-17 03:25:19 UTC -- Cleaning up /var/opt/gitlab/backups/packages.tar.gz
    2024-01-17 03:25:19 UTC -- Cleaning up /var/opt/gitlab/backups/ci_secure_files.tar.gz
    2024-01-17 03:25:19 UTC -- Deleting tar staging files ... done
    2024-01-17 03:25:19 UTC -- Deleting backups/tmp ...
    2024-01-17 03:25:19 UTC -- Deleting backups/tmp ... done
    2024-01-17 03:25:19 UTC -- Deleting backup and restore PID file ... done
    root@ben-virtual-machine:/etc/gitlab#
    

    在新環境安裝 Gitlab 時需指定 EE 或是 CE 以及是哪一個版本.

    sudo EXTERNAL_URL="http://192.168.31.163" apt-get install gitlab-ce=16.5.1-ce.0
    
沒有解決問題,試試搜尋本站其他內容

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料