每天5点备份上传到阿里云
文件放在/home/autoBackup_gitlab.sh
设置运行属性chmod +x /home/autoBackup_gitlab.sh
crontab -e
设置定时任务0 5 * * * /home/autoBackup_gitlab.sh
具体代码
#工作目录 ossutil及配置存放目录
workDir='/home/gitlab_backup'
#gitlab在容器中的名称
gitlabContainerName='pch18_gitlab'
#oss的endpoint
endpoint='oss-cn-hangzhou-internal.aliyuncs.com'
#oss的accessKeyID
accessKeyID='**********'
#oss的accessKeySecret
accessKeySecret='********************'
#oss的存放路径
saveDir="oss://pch18-backup-hz/gitlab/$(date +"%Y-%m")/"
if [ ! -d ${workDir} ]; then
mkdir ${workDir}
fi
cd ${workDir}
if [ ! -f ./ossutil64 ]; then
wget http://docs-aliyun.cn-hangzhou.oss.aliyun-inc.com/assets/attach/50452/cn_zh/1524643963683/ossutil64
chmod +x ./ossutil64
fi
if [ ! -f ./.ossutilconfig ]; then
echo '[Credentials]' > ./.ossutilconfig
echo 'language=CH' >> ./.ossutilconfig
echo 'endpoint='${endpoint} >> ./.ossutilconfig
echo 'accessKeyID='${accessKeyID} >> ./.ossutilconfig
echo 'accessKeySecret='${accessKeySecret} >> ./.ossutilconfig
fi
docker exec ${gitlabContainerName} gitlab-rake gitlab:backup:create
file=`docker exec ${gitlabContainerName} ls -t /var/opt/gitlab/backups | head -n 1`
docker exec ${gitlabContainerName} cat /var/opt/gitlab/backups/${file} >> /tmp/${file}
ossutil='./ossutil64 --config-file=./.ossutilconfig'
${ossutil} cp /tmp/${file} ${saveDir}
rm -f /tmp/${file}