備份方式選用gitlab自帶的gitlab-rake功能。備份目的選用異地的OSS。每個月完成一次備份恢複測試。恢複測試需采用備份裝置相同版本gitlab。
https://help.aliyun.com/document_detail/50452.html?spm=a2c4g.11186623.6.697.b91e40afcNcuYt
mkdir ossutil64 cd ossutil64/ wget http://gosspublic.alicdn.com/ossutil/1.6.10/ossutil64 chmod 755 ossutil64 ./ossutil64 config endpoint:oss-cn-####.aliyuncs.com AccessKeyId:#### AccessKeySecret:#### ./ossutil64 ls oss://gitlab ./ossutil64 cp testfile oss://gitlab
[root@gitlab ~]# ls hzoss ossutil64 [root@gitlab hzoss]# cat hzoss.sh #!/bin/bash localpath=/var/opt/gitlab/backups gitlab-rake gitlab:backup:create && /root/hzoss/send_hzoss.exp if [ ! -f "$localpath/tar" ];then rm -rf $localpath/tar fi [root@gitlab hzoss]# cat send_hzoss.exp /root/ossutil64/ossutil64 cp /var/opt/gitlab/backups/tar oss://gitlab --maxupspeed 3000 [root@gitlab hzoss]# crontab -l 1 23 /root/hzoss/hzoss.sh [root@gitlab ~]# /root/ossutil64/ossutil64 ls oss://gitlab LastModifiedTime Size(B) StorageClass ETAG ObjectName 2020-01-21 17:09:45 +0800 CST 4926812160 Standard F73DC4475745908FBA70AD4C0116B85A-400 oss://gitlab/1579597055_2020_01_21_11.3.0_gitlab_backup.tar 2020-01-21 20:25:35 +0800 CST 4926873600 Standard 240BFA38A57338FADA962F64BD71C84C-400 oss://gitlab/1579608831_2020_01_21_11.3.0_gitlab_backup.tar
yum install -y curl openssh-server openssh-clients cronie lokkit systemctl stop firewalld curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash yum install gitlab-ce-11.3.0-ce.0.el7.x86_64
如果下載下傳太慢,增加清華源。
cat gitlab_gitlab-ce.repo [gitlab-ce] name=gitlab-ce baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7 repo_gpcheck=0 enabled=1 gpgcheck=0
然後重新yum安裝
gitlab-ctl reconfigure mkdir -p /gitlab/data mkdir -p /gitlab/backup cd /gitlab/data/
更改gitlab配置
vi /etc/gitlab/gitlab.rb gitlab_rails['manage_backup_path'] = true gitlab_rails['backup_path'] = "/gitlab/data" gitlab_rails['backup_archive_permissions'] = 0644 gitlab_rails['backup_keep_time'] = 7776000
更新gitlab配置
驗證http://ip 能否正常打開

停止gitlab
gitlab-ctl stop unicorn gitlab-ctl stop sidekiq gitlab-ctl status
下載下傳後,恢複備份檔案
[root@HZ-gitlab-test-001 ossutil64]# mv 1581887626_2020_02_17_11.3.0_gitlab_backup.tar /gitlab/data/ chown git.git 1579508247_2020_01_20_11.3.0_gitlab_backup.tar chmod 777 1579508247_2020_01_20_11.3.0_gitlab_backup.tar gitlab-rake gitlab:backup:restore BACKUP=1579508247_2020_01_20_11.3.0
啟動gitlab
gitlab-ctl start gitlab-rake gitlab:check SANITIZE=true
如果登陸出現問題,修複登陸方式
su - gitlab-psql psql -h /var/opt/gitlab/postgresql -d gitlabhq_production UPDATE application_settings SET password_authentication_enabled_for_web=true; \q exit gitlab-ctl restart