本文最后更新于 870 天前,其中的信息可能已经有所发展或是发生改变
备份脚本
#!/bin/bash
localdate=$(date +%F-%T)
containe=$(docker exec -t gitlab gitlab-rake gitlab:backup:create)
if [ $? -eq 0 ]; then
echo "$localdate--gitlab备份执行成功" >> /home/gitlab/backup.log
else
echo "$localdate--gitlab备份执行失败" >> /home/gitlab/backup.log
fi
configcopy2=$(tar zcvf /home/gitlab/conf-backup/$localdate-rb-tar.gz /mydata/gitlab/etc/gitlab.rb)
if [ $? -eq 0 ];then
echo "$localdata--gitlab.rb备份执行成功" >> /home/gitlab/backup.log
else
echo "$localdata--gitlab.rb备份执行失败" >> /home/gitlab/backup.log
fi
configcopy1=$(tar zcvf /home/gitlab/conf-backup/$localdate-secre.tar.gz /mydata/gitlab/etc/gitlab-secrets.json)
if [ $? -eq 0 ];then
echo "$localdata--gitlab-secrets备份执行成功" >> /home/gitlab/backup.log
else
echo "$localdata--gitlab-secrets备份执行失败" >> /home/gitlab/backup.log
fi
find /home/gitlab/conf-backup -type f -mtime +7 -name "*.*" -exec rm -f {} \;
find /home/gitlab/data/backups -type f -mtime +7 -name "*.*" -exec rm -f {} \;
备份通知脚本
#!/bin/bash
while true
do
jud1=$(md5sum /home/gitlab/backup.log | awk '{print $1}')
sleep 5
jud2=$(md5sum /home/gitlab/backup.log | awk '{print $1}')
#sleep 2
if [ "$jud1" = "$jud2" ];then
cat /dev/null > /home/gitlab/result
else
tail -n 3 /home/gitlab/backup.log > /home/gitlab/result
fi
#diff $judge1 $judge2
done
- nohup后台执行,定时5秒检查备份文件的值
nohup /home/gitlab/bakcode.sh /dev/null &
- 备份代码库到本地服务器
- 已经和本地备份服务器做了免密登录
#!/bun/bash
last_date=`date +'%Y-%m-%d'`
file=$(find /home/gitlab/data/backups -type f -mmin -60 -name *.tar)
conf1=$(find /home/gitlab/conf-backup -type f -mmin -90 -name *secre*)
conf2=$(find /home/gitlab/conf-backup -type f -mmin -90 -name *rb*)
rsync -vzrtopg --progress -c -e 'ssh -p 22' $file root@172.16.40.38:/home/gitlab-backup/backup 1> /home/gitlab/rsync.log 2>&1
rsync -vzrtopg --progress -c -e 'ssh -p 22' $conf1 root@172.16.40.38:/home/gitlab-backup/conf-backup 1> /home/gitlab/rsync.log 2>&1
rsync -vzrtopg --progress -c -e 'ssh -p 22' $conf2 root@172.16.40.38:/home/gitlab-backup/conf-backup 1> /home/gitlab/rsync.log 2>&1
#if [ $? -eq 0 ];then
#
# echo "$last_date-gitlab-rsync: pass success" >> /home/gitlab/send
#
#else
#
# echo "$last_date-gitlab-rsync:pass fali" >> /home/gitlab/send
#
#fi
定时任务crontab
01 02 * * * /home/gitlab/backup.sh
30 02 * * * /home/gitlab/rsync.sh
zabbix取值并发送备份状态通知
[Gitlab每天备份状态通知,请联系shgbit运维确认状态](https://172.16.40.30)
Gitlab备份事件:{TRIGGER.NAME}
Gitlab备份时间:{EVENT.DATE} {EVENT.TIME}
Gitlab备份状态:{ITEM.LASTVALUE}
Gitlab备份主机IP:{HOST.IP}
Gitlab备份主机名:{HOST.NAME}
Gitlab备份发生时长:{EVENT.AGE}