自动备份gitlab到阿里云oss

本文共有1447个字,关键词:

每天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}

「一键投喂 软糖/蛋糕/布丁/牛奶/冰阔乐!」

pch18

(๑>ڡ<)☆谢谢老板~

使用微信扫描二维码完成支付

版权声明:如无特别说明,本文为作者原创,转载请在首行注明来源:https://pch18.cn/archives/500.html
添加新评论
暂无评论