总体策略

备份策略

备份方式选用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
#!/bin/bash
/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配置

gitlab-ctl reconfigure

验证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-ctl status
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