1. 程式人生 > 其它 >gitlab備份and恢復資料

gitlab備份and恢復資料

備份資料

1.確定備份的路徑

[root@localhost ~]# cat /etc/gitlab/gitlab.rb |grep backup_path
# gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"

2.備份資料

[root@localhost ~]# /usr/bin/gitlab-rake gitlab:backup:create
[root@localhost ~]# ls /var/opt/gitlab/backups/1632002877_2021_09_19_12.3.5_gitlab_backup.tar 
/var/opt/gitlab/backups/1632002877_2021_09_19_12.3.5_gitlab_backup.tar

也可以做定時任務通過指令碼備份

[root@localhost ~]# crontab -l
0 6 * * 0 /server/scripts/backup_gitlab.sh  2>&1 > /dev/null   #每週日的早上六點備份gitlab資料
[root@localhost ~]# cat /server/scripts/backup_gitlab.sh 
#!/bin/bash
wx(){
     curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=b2d0bdd0-0177-441d-9406-cfce1f73fed9' \
   -H 'Content-Type: application/json' \
   -d '
   {
    "msgtype": "markdown",
    "markdown": {
        "content":  "'"\$1"'"
    }

   }'
}


/usr/bin/gitlab-rake gitlab:backup:create
if [ $? == 0 ];then
      scp -rp $(find /var/opt/gitlab/backups/  -type f ) [email protected]:/data/docker/yum/gitlab/backup && rm -rf /var/opt/gitlab/backups/* 
      if [ $? ==0 ];then
           rm -rf /var/opt/gitlab/backups/*
           ssh [email protected] 'find /data/docker/yum/gitlab/backup/ -type f   -mtime +30   |xargs -i rm -rf {} '
      else
           wx "## ${ZH_NAME} <font color=warning>gitlab備份資料傳53送失敗!</font> "
      fi
else
     wx "## ${ZH_NAME} <font color=warning>gitlab備份資料失敗!</font> "
fi

恢復資料

1.下載安裝包 漢化包

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm
wget https://gitlab.com/xhang/gitlab/-/archive/v12.3.5-zh/gitlab-v12.3.5-zh.tar

2.安裝gitlab

yum install -y curl postfix policycoreutils-python openssh-server wget
yum localinstall gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm -y

3.修改對外暴露服務的埠號 時區

[root@localhost gitlab]# vim /etc/gitlab/gitlab.rb
#修改nginx埠號
nginx[‘listen_port’] = 8088
gitlab_rails['time_zone'] = 'Asia/Shanghai'

[root@localhost gitlab]# gitlab-ctl reconfigure
[root@localhost gitlab]# gitlab-ctl restart

4.漢化

#停止gitlab
[root@localhost data]# gitlab-ctl stop

#解壓漢化包
[root@localhost data]# tar xf gitlab-v12.3.5-zh.tar.gz 

#覆蓋語言包
[root@localhost data]# \cp -r gitlab-v12.3.5-zh/* /opt/gitlab/embedded/service/gitlab-rails/
cp: 無法以目錄"gitlab-v12.3.5-zh/log" 來覆蓋非目錄"/opt/gitlab/embedded/service/gitlab-rails/log"
cp: 無法以目錄"gitlab-v12.3.5-zh/tmp" 來覆蓋非目錄"/opt/gitlab/embedded/service/gitlab-rails/tmp"

#開啟gitlab
[root@localhost data]# gitlab-ctl start

5.恢復資料

chmod 777 /var/opt/gitlab/backups/1632002877_2021_09_19_12.3.5_gitlab_backup.tar
cd /var/opt/gitlab/backups
gitlab-ctl stop unicorn && gitlab-ctl stop sidekiq
gitlab-rake gitlab:backup:restore BACKUP=1632002877_2021_09_19_12.3.5