CentOS7 gitlab 办公环境简单主备同步搭建

简单说明:

本篇博文简单记录办公环境下的Gitlab搭建和简单主备同步部署步骤
因为有过办公环境虚拟化因跳电造成整个环境不可用的阴影
所以对办公环境下的Gitlab也搭建第二套虚拟化环境下的备机
办公环境下的Gitlab使用用户只有技术部几十人,代码提交频率和代码容量均不高
因此本篇博文记录Gitlab使用Rsync做备份同步和备机备份恢复

部署步骤:

1° 依据《CentOS7 gitlab安装搭建简单维护》搭建部署两台Gitlab环境
考虑到实际应用需求,分别对/var/opt目录挂载一块100G数据盘

2° 部署Rsync数据同步:
备份端操作:

yum -y install rsync

cat >>/etc/rsyncd.conf<<EOF
[git-master-backup]
path = /var/opt/gitlab/backups
hosts allow = 192.168.1.130
hosts deny = *
list = true
uid = git
gid = git
read only = false
EOF

systemctl start rsyncd
systemctl enable rsyncd

# 备份端不在执行每日备份JOB,创建备份恢复脚本:
cd /root/checkOS
cat >gitlabDailyRestore.sh<<EOF
#!/bin/bash
source ~/.bash_profile
cd /var/opt/gitlab/backups
FILE=\$(ls -lt *gitlab_backup.tar|head -1|awk '{print \$NF}'|awk -F'_gitlab_' '{print \$1}')
echo -e "\n\n\n\$(date +%F_%T) Restore Backup \${FILE}">>/root/checkOS/gitlabDailyRestore.log
gitlab-ctl stop unicorn>>/root/checkOS/gitlabDailyRestore.log
gitlab-ctl stop sidekiq>>/root/checkOS/gitlabDailyRestore.log
echo -e 'yes\nyes'|gitlab-rake gitlab:backup:restore BACKUP=\${FILE}>>/root/checkOS/gitlabDailyRestore.log 2>&1
gitlab-ctl restart>>/root/checkOS/gitlabDailyRestore.log
EOF

crontab -l>/tmp/crontab.tmp
echo '# Gitlab Daily Restore'>>/tmp/crontab.tmp
echo '0 4 * * * /bin/bash /root/checkOS/gitlabDailyRestore.sh'>>/tmp/crontab.tmp
cat /tmp/crontab.tmp |crontab
rm -rf /tmp/crontab.tmp

源端操作:

yum -y install rsync

# 测试
rsync -avz --delete /var/opt/gitlab/backups/ 192.168.1.140::git-master-backup

# 自动任务
crontab -l>/tmp/crontab.tmp
echo '# GitLab Backup Rsync'>>/tmp/crontab.tmp
echo '0 3 * * * rsync -avz --delete /var/opt/gitlab/backups/ 192.168.1.140::git-master-backup'>>/tmp/crontab.tmp
cat /tmp/crontab.tmp |crontab
rm -rf /tmp/crontab.tmp

[TOC]

你可能感兴趣的:(DevOps和生产中间件)